Multileaders Generated from Dynamo

Hello,

Has anyone tried/had any success using Dynamo for automating multileader callouts? I have a 2D siteplan in Civil3D with different pipe sizes on different layers and I am trying to automatically label these pipes with multileaders using Dynamo. I am able to extract the necessary info in Dynamo and create multiline text at the centerline of the pipe lines but I would like to use multileaders if possible. I know this would need to be done in Python, but I’m having trouble finding the right script in the AutoCAD API. My current script and output is shown in the screenshots below.

Thank you!

1 Like

@Paolo_Emilio_Serra1 this would be an awesome addition to the Toolkit (if you aren’t working on it already).

4 Likes

noted

4 Likes

Hi! @mbrayN4L27 I’m with a similar need here. Did you found a solution for that?

This need has been sitting for awhile, so I made a first attempt. This code is not great. Hoping someone can improve upon it.

import clr

# Add Assemblies for AutoCAD
clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')

# Import references from AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

def create_mleader(text, leaderPnt, textPnt):
		
	output=[]
	i=0
	
	if not isinstance(text,list):
		text = [text]
	
	global adoc

	with adoc.LockDocument():
	    with adoc.Database as db:
	        with db.TransactionManager.StartTransaction() as t:
				bt = t.GetObject(db.BlockTableId, OpenMode.ForRead)
				btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
				for obj in text:
					leader = MLeader()
					leader.SetDatabaseDefaults()
					leader.ContentType = ContentType.MTextContent
					mText = MText()
					mText.SetDatabaseDefaults()
					mText.SetContentsRtf(obj)
					mText.Location = Point3d(textPnt[i].X, textPnt[i].Y, textPnt[i].Z)
					leader.MText = mText
					idx = leader.AddLeaderLine(Point3d(leaderPnt[i].X, leaderPnt[i].Y, leaderPnt[i].Z))
					btr.AppendEntity(leader)
					t.AddNewlyCreatedDBObject(leader, True)
					output.append(leader)
					i+=1
				t.Commit()				
		return output
				
OUT = create_mleader(IN[0], IN[1], IN[2])
5 Likes

Hi @mzjensen and @Paolo_Emilio_Serra1 can we add this to wishlist. I was trying to update Githhub but not able to do it, failed in repeated attempts to add new tab in the wishlist folder.

Apologies if its already been taken care and if i am not aware of the node.

I keep getting this error on my dynamo script. Does anyone know how to fix it?

I am assuming that has to do with mText.SetContentsRtf()

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 53, in
AttributeError: ‘type’ object has no attribute ‘MtextContent’

Is the “t” in MtextContent actually lowercase like it is in your post? It should be MTextContent.

I used your code without the loop and that is the error dynamo keeps throwing in the node.

There are several issues with the code that will probably throw other errors, so I recommend you copy and paste the original code verbatim.

Civil 3D Toolkit 1.1.20

image

image

5 Likes

Can you share your code for how to get a new line in Mtext? It would be the equivalent of typing enter for a new second line of text in Mtext

Also,

It would be helpful to have variables for background mask and attachment location in the MLeader and Mtext nodes