0

Instead of creating text boxes everytime for the displaying the name of the blocks, I thought of creating a reusable template for the same. Following is what I created

partial block BlockTemplate
  annotation(Icon(coordinateSystem(extent = {{-100,-100},{100,100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {2,2}), graphics = {Text(origin = {-0.366361,-0.51471}, lineColor = {0,0,255}, extent = {{-150,150},{150,110}}, textString = "%name"),Text(origin = {0,-260}, lineColor = {0,0,255}, extent = {{-150,150},{150,110}}, textString = "%name")}));
end BlockTemplate;

Then I imported this in another block by using

extends BlockTemplate

Turns out that I get the %name displayed on top of the block but I cannot edit it.

What should be done so that I am able to edit it?

Thanks in advance, MSK

MSK
  • 448
  • 2
  • 5
  • 18

2 Answers2

1

OK then you can do it like this,

Block A

block A
  annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100}, {100,100}}), graphics={Text(extent={{-52,50},{62,-20}}, lineColor={0,0,255}, textString="%name")}));
end A;

Block B

block B
  extends A;
end B;

Block C

block C
  B abc annotation (Placement(transformation(extent={{-60,20},{-40,40}})));
end C;
Adeel Asghar
  • 577
  • 2
  • 7
0

I think you can't use Text annotation with extends like this. You need to create an instance of the block.

block A

  annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},
            {100,100}}), graphics={Text(
          extent={{-52,50},{62,-20}},
          lineColor={0,0,255},
          textString="%name")}));
end A;

Above is the block which defines a text annotation with %name.

block B

  A a annotation (Placement(transformation(extent={{-40,20},{-20,40}})));
end B;

Block B contains a component of Block A which will automatically display the name of the component in place of %name.

Adeel Asghar
  • 577
  • 2
  • 7
  • This does not serve the purpose, Adeel. Taking your answer as an example, what I want is block A to have a template which would help in naming B. So that when I Drag and Drop B onto another model C, I want A to display B's name in the diagram view of C. – MSK Jun 09 '14 at 12:45
  • Doing what you said will show the name of A in the Diagram View of B – MSK Jun 09 '14 at 12:45