Getting Attribute Tags from MLeader Block Definition

Need some help on this one. I’m trying to compile a list of keyed notes organized by the block they are associated to – shapes, namely (square, circle, hexagon, etc.). I’ve looked at a few .NET examples and pieced together some python, but it appears I’m missing a piece (or several).

I’ve attached my .dyn as well as the code I’m toying with. Any advice would be much appreciated.

GetLeaderAttributes.dyn (21.3 KB)

import clr
# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')
clr.AddReference('Civil3DNodes')

# Add standard Python references
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import math

# Add references to manage arrays, collections and interact with the user
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox

# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

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

# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# Import references for Dynamo for Civil 3D
from Autodesk.Civil.DynamoNodes import Alignment as DynAlignment

adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor
civdoc = CivilApplication.ActiveDocument

attdefId = IN[0]
MLeaders = IN[1]

def get_MLeader_Attributes(attdefId,MLeaders):

	global adoc
	global civdoc
	
	output = []
	
	if not isinstance(MLeaders, list):
		MLeaders = [MLeaders]

	with adoc.LockDocument():
		with adoc.Database as db:
			with db.TransactionManager.StartTransaction() as t:
				
				for o in MLeaders:
					mleader = t.GetObject(o.InternalObjectId, OpenMode.ForRead)
					blockId = mleader.BlockContentId
					record = t.GetObject(blockId, OpenMode.ForRead, BlockTableRecord)
					#output.append(t.GetObject(blockId,OpenMode.ForRead))
					for Id in record:
						#adef = t.GetObject(Id, OpenMode.ForWrite,AttributeDefinition)
						dbObj = t.GetObject(Id, OpenMode.ForRead)
						if dbObj is AttributeDefinition:
							attDef = t.GetObject(Id, OpenMode.ForRead, AttributeDefinition)
							attRef = mleader.GetBlockAttribute(attDef.Id)
							output.append(t.GetObject(dbObj,OpenMode.ForRead))
				t.Commit()
	return output

OUT = get_MLeader_Attributes(IN[0],IN[1])

Hi
Attach an example drawing
It’s better to help you

Absolutely, here’s an example of what I’m talking about. I have these MLeaders which all use different blocks but have an attribute, “KEYEDNOTE_NO”, that I want to be able to get the value of. My end goal is to have a list of keyed notes using the blocks and the numbers, similar to this post: Even Vertical Spacing of MText

KeyedNoteTest.dwg (845.3 KB)

Cole, I do think the “Even Vertical Spacing of MText, autokeynote” script I made should be updated and I’ve been wanting to for awhile. It utilizes the data extraction tool, an external python script AND a dynamo script to work. Talk about janky duck tape that I put together with my tidbits of knowledge!

My thoughts here would be to use the camber package to get the attributes according to each block type. I’d definitely like to know how to extract the attribute strings from the blocks embedded into mleaders. This would speed up my work flow for keynoting sheets and also updating/swapping keynote numbering according to my keynote excel sheets.

@mzjensen , How do you select an mleader in civil 3d and get it into the “Camber.AutoCAD.MLeader” format? The only method I can find for getting an MLeader from an object in dynamo is by using the toolkit nodes for “Select Objects” and “MLeader.ByObject”. I don’t see an equivalent selection method in Camber to provide the correct format.

1 Like

Certainly. I’ve looked the route of Camber (amazing tools) as well, but because the package doesn’t “talk” with Civil3D toolkit I couldn’t find a way to put it to good use in this situation. It seems like there needs to be a node that allows the two to talk, but I believe @mzjensen has made a few comments about why that can’t be the case with regards to best practices. Perhaps the Civil3D toolkit team has this on their radar, but I’m not certain.

It’s in the works!

3 Likes

You’re the man Zachri! Once those updates are pushed I can update my sheet keynoting script to something more deployable and even create a keynote number update script for the community. Exciting stuff!

1 Like