Creating fields in MText

Hello,

I am trying to select all polylines in a drawing, get their areas as a field, then insert the field into Mtext back into the drawing. (So that when the polyline area is changed the label updates automatically)

What am I doing wrong?

Hi @sophia2013,

That isn’t quite how that node works. An example usage would be to pass in a text or MText object that has fields in the body of the text, then the node would return the fields. In your case, what you’re trying to do is create new fields, not query existing ones. To create a new field in the MText, you’d need to know the exact field expression, which includes the object ID of each polyline. So it isn’t very straightforward.

But I’ll ask, do you need fields? Alternatively, you could get the lengths of the polylines and put those values into new MText objects. Then just rerun the graph when you want to update the values.

@sophia2013 I think what you are looking for can be done with Lee Mac’s lisp Length & Area Field

Thanks for the response. Do you happen to have any examples in Dynamo for creating a new field in Mtext based off an object?

To answer your question: Yes having the fields would be important. The end result I am trying to make would have a field for structure numbers as well. That way if structure numbers change, this drawing would not need to be opened to re-label the areas & structures.

image

You can get the fieldcode string of your desired MTEXT, then replace the object ID part to be the objectID property of the polyline. then use it as the MText content.
I am not suer if D4C3D has the node to get ObjectID and Mtext content textstring from existing Mtext, if not, you can try using LinkDWG/LinkDWG2:

  1. get the TextString property from your desired Mtext to be the proto fieldcode,
  2. get the ObjectID property of target polyline and use it to replace the ObjectID part
  3. set the new string as Mtext content.

I was able to get the ObjectID of the polyline in Dynamo through ObjectExtensions.GetParameters.

However, I can’t get the ObjectID of a structure when this object is selected. Would anyone know how?