Different text in each BlockReference instance

The following code sample demonstrates how to change the text in each BlockReference instance. The trick is to use the Attribute entity.

A block attribute is a tag or label that attaches information to a block. The information is mapped as a column in a database table. It can be anything, for example room numbers, equipment tags, drawings numbers in a set, etc.

The appearance of the tag can be customized at instance level as well, for example you can change the size of the text only for a single instance of your block. To reset all settings as in block definition you need to call ViewportLayout.Entities.SinchronizeAttributes() instead.

// Block creation
Block bl1 = new Block();

LinearPath rect = new LinearPath(180, 80);
rect.ColorMethod = colorMethodType.byEntity;
rect.Color = Color.Blue;

// adds some entities

bl1.Entities.Add(new Text(10, 10, 0, "Dimensions:", 5));
bl1.Entities.Add(new Text(10, 20, 0, "Owner:", 5));
bl1.Entities.Add(new Text(10, 30, 0, "Price:", 5));
bl1.Entities.Add(new Text(10, 40, 0, "Color:", 5));

// adds attributes, their text will replaced for each instance
bl1.Entities.Add(new devDept.Eyeshot.Entities.Attribute(50, 10, 0, "Dimensions", "Dimensions (cm)?", 5));
bl1.Entities.Add(new devDept.Eyeshot.Entities.Attribute(50, 20, 0, "Owner", "Owner name?", 5));
bl1.Entities.Add(new devDept.Eyeshot.Entities.Attribute(50, 30, 0, "Price", "Price?", 5));
bl1.Entities.Add(new devDept.Eyeshot.Entities.Attribute(50, 40, 0, "Color", "Color?", 5));

// adds the block to the Blocks master collection
viewportLayout1.Blocks.Add("desk", bl1);

// Block reference creation
BlockReference br1 = new BlockReference(-20, 50, 0, "desk", 1, 1, 1, 0);

// Fills required tags (you can skip some of them)
br1.Attributes.Add("Dimensions", "160 x 80");
br1.Attributes.Add("Owner", "Alberto");
br1.Attributes.Add("Price", "169,00 Euros");

// adds the block reference to the 3D scene

// changes a values after adding it
br1.Attributes["Owner"].Value = "Giulia";

// changes visibility status
br1.Attributes["Owner"].Invisible = true;

// Block reference creation
BlockReference br2 = new BlockReference(-102, 130, 0, "desk", 1, 1, 1, Utility.DegToRad(-90));

// Fills required tags (you can skip some)
br2.Attributes.Add("Dimensions", "160 x 80");
br2.Attributes.Add("Owner", "Luca");
br2.Attributes.Add("Price", "169,00 Euros");
br2.Attributes.Add("Color", "Birch veneer");

// adds the block reference to the 3D scene

// changes height of the first BlockReference instance price tag
br1.Attributes["Price"].Height = 8;

// this change requires a regen call

// If you want to reset all settings as in Block definition uncomment this line
// viewportLayout1.Entities.SynchronizeAttributes("desk");

Here is an image of the result:


Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request


  • BlockReference.Attributes is readonly so, is this line still applicable?

    br1.Attributes = new Dictionary<string, string>();   

  • You're right, that line of code is not allowed, since the Dictionary is already created internally.

    I fixed the code. 

    Thanks for reporting it.

  • Does the Attribute entity supports linebreak? If yes, what char has to be used?

Please sign in to leave a comment.