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])