Even Vertical Spacing of Mtext

Hey Dynamo community. I’m new to the Dynamo and python scene but have been working hard to improve. I’m hoping someone can help guide me here. I wrote a script in python that takes keynote numbers from a given civil 3D sheet view and returns an excel file with the corresponding notes.

I have pulled this excel file into dynamo, created lists, and generated the blocks and mtext as intended. However, I am having trouble formatting it. When I decrease the width of the mtext, the text is no longer evenly spaced and the keynote blocks no longer line up with the text.

It seems I need to conduct some sort of transformation command that references the bounding box width of each mtext item and sets spacing this way. THEN, grab the midpoint coordinate of each mtext object and place each keynote horizontally offset. Typically in CAD this operation would be done with the “Text Align” command and setting a spacing, but I am unable to find an equivalent operation in Dynamo.

It looks like the text does line up with the keynote blocks, it’s just that the vertical attachment on the MText node is set at the default, which is “Top”. In your picture, it looks like the top left corner of each MText is aligned with the insertion point of the block (i.e. same Y coordinate). So if you want them aligned with the middle of the text, just change the vertical attachment to “Middle” with a string input.

1 Like

Thanks for your time,

I have made this change. However, this does not achieve what my finished goal is. The problem is the vertical spacing between items is the same, regardless of each mtext’s total vertical height. I would like the mtext to be spaced evenly between the text, not between the center point of each text. As shown:

Rather than:

Ah OK, I see what you’re trying to do now. So it’s the spacing between the bottom of one MText and the top of the next one that matters, and the spacing between the blocks is irrelevant.

Yes, I think this is the way to do it. There isn’t really a quick solution that I know of. It could probably be done with some fancy combination of nodes, but I think it might be more straightforward to write some type of looping logic to generate the desired Y-coordinates. Maybe something like this:

  1. Get the bounding box of each MText with Object.Extents
  2. Get the top and bottom Y-coordinates of each bounding box with BoundingBox.MinPoint and BoundingBox.MaxPoint
  3. Generate new Y-coordinates given desired spacing
  4. Create coordinate systems at the new points
  5. Use Object.Transform to move the MText objects to the new coordinate systems
  6. Add the keynote blocks at the desired X-coordinate offset

Hope that helps. Sorry I can’t share an example script, I don’t have much time to figure this out.

1 Like

Completely understandable. We’re all busy and I really appreciate your time! I’ll take a look into this and reply back. I also had the idea of generating a list using a len() function on each note string and setting the step value of the coordinates equal to this integer list multiplied by a factor. However, this may be an awkward fix.

Thanks for your help!

Zachri and others,

I’ve been looking over the bounding box and coordinate nodes and familiarized myself a bit. I have found an issue with this methodology due to the the mtext node’s creation methodology. It seems when mtext is generated by passing a width to it, the bounding box does not automatically update to the total height of the text. The text is automatically squeezed by the width constraint, but the total height of the bounding box does not adjust with it. Therefore, when I return the result of the maximum Y Values minus the minimum Y values, a list is returned with a repeating minimum height value.

Do you see anyway around this?

I was playing around with that yesterday and it was working fine on my end - try using the BoundingBox.ToCuboid node so that you can actually see the box in Dynamo. When I adjusted the width input for the MText, the bounding box would grow and shrink as the text wrapped to multiple lines.

1 Like

Also, try not using a height input on the MText node. I don’t think it is needed if the max width is what you are most concerned width. My guess for why you’re getting repeating values of 0.5 is because you set the height of each MText to 0.5?

1 Like

Perfect! How could it be so simple! Thanks a ton. I see now that the “height” value the mtext actually receives is from the default textstyle (At least that’s how it seems to me). If you provide input to the “height” value for the mtext node, then it overwrites the bounding box height. By changing this, the list is now varied.

Thanks again for your help Zachri. The script is now working as intended. Just as you originally thought, the bounding box data of each mtext has to be referenced and used for the spacing, then the bubble blocks will reference these final coordinates. I’ve included the final dynamo file and images in case anyone would like to reference this in the future.

Here is a final video of the script in action: https://www.youtube.com/watch?v=-BVVjiRMOdU
It utilizes GUI automation in python to control the autocad data extraction from the keynotes and then a dynamo script is run to take python’s excel output and turn it into mtext/space it properly.

keynoteDynamoScriptV2.dyn (146.9 KB)

1 Like