Get BlockReference Rotation Value

@craig here is the python code.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# 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 from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
	
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
	with adoc.Database as db:
		with db.TransactionManager.StartTransaction() as t:
			bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
			btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
			blh = []
			blr = []
			errorReport = None
			for oid in btr:
				bl = t.GetObject(oid, OpenMode.ForRead)
				try:
					# Filter BlockReference starts with.				
					if isinstance(bl, BlockReference) and bl.Name.startswith(IN[0]):
					# Get values of handle & Rotation.
						blh.append(bl.Handle)
						blr.append(bl.Rotation)
				# Catch and report Exception...	
				except:
					import traceback
					errorReport = traceback.format_exc()
					
					
			t.Commit()
           				

# Assign your output to the OUT variable.

if errorReport == None:
	OUT = blh,[x*57.2958 for x in blr]# Convert from radians to degrees
else:
	OUT = errorReport

Please mark the post as solved. You’re welcome!

4 Likes