Get BlockReference Rotation Value

Hello Everyone,

How can i get BlockReference Rotation Value? Do we have any nodes to read BlockReferences?

Thanks in Advance,

1 Like

There is various blockreference nodes available, but none for rotation! As a workaround I would create a dynamic block with a rotation action parameter. There are nodes to read dynamic block parameters in the AutoCAD dynamo library.

Hi @craigp @marshmallow

Is this what you guys are after?

2 Likes

OMG :astonished: i thought this is not possible but you made it possible :smile:. You’re super hero :man_superhero:.

Hello great work!, and what about getting the visibility parameter of a block and the possibility of changing this visibility? This would allow to change blockreference by lists in a massive way.
Thank you.
I posted this a few months ago:

@craigp - you can also use the OOTB nodes for coordinate systems and vectors (example below).

BlockRotation.dyn (17.8 KB)

3 Likes

@javiermend - I replied to your other thread so that we keep things organized. Check it out.

Hi @mzjensen

I was aware of this method and tried this first before jumping into Python, but this method (Vector.AngleAboutAxis) doesn’t match values of BlockReferences inside Civil3d:

So i thought let’s make it cleaner by reading the values itself.

Cheers!

@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

Thanks @mzjensen for the OOTB solution. @Kulkul is right i saw the same differences in the values by using Vector.AngleAboutAxis. Thanks a million @Kulkul for sharing the code :bowing_man:.

I don’t mean to beat this to death, but I’m not seeing the same discrepancies that you both are seeing, which is interesting. The OOTB nodes work for me every time.

@Kulkul - the angles in your example are supplementary to each other. I think using Vector.Reverse instead of List.Reverse might fix this?

Hi @mzjensen

Nah still the same:

Here is the dwg file and dyn file if you want to check it out from your side:
Test.dwg (869.1 KB)
BlockReference Rotation Angle.dyn (32.7 KB)

Ah OK, I figured it out. Several of the blocks in the DWG had a “Scale X” of -1, which reverses the vectors. So I guess you would have to add some more nodes to check for this scenario and get the absolute value, or something like that. Or just use Python and call it good :slight_smile:

2 Likes

Get the coordinate system of the block, then get the vector rotation from x axis.
By that you get the insert rotation of the block.

Yes, there are several other posts about that in this thread already.

The problem is that this method can output the wrong value depending on the scale factors of the block. Reading the value directly from Civil 3D instead of calculating it is arguably more bulletproof.

3 Likes

I think that difference in scale is causing me to have issues with something similar - Can I have some help sorting it? I am unable to run Python in Dynamo due to company policies so stuck with an OOTB solution.
https://forum.dynamobim.com/t/dynamic-blocks-to-infraworks/92177/7