Visibility states: How to get and set this for dynamic block references?

Hi, do you think it is possible now to get and set visibility states for Dynamic Blocks in Dynamo for Civil 3D?

2 Likes

Hi, I found this: How to access and modify a DynamicBlockReference property in ARX and .Net? - AutoCAD DevBlog
Is here anyone who solved this already in Python please?

Hi,
a rapid test with CADPythonShell

set dynBlock

import clr
import System
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
# 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 *
doc = Application.DocumentManager.MdiActiveDocument
ed = doc.Editor
db = doc.Database
# Write Code Below
# name and value property to set dynamic block
namePropVisu = 'Visibilité1'
valuePropVisu = 'Type D'

with doc.LockDocument():
	with doc.Database as db:
		with db.TransactionManager.StartTransaction() as t:
			bt = t.GetObject(db.BlockTableId,OpenMode.ForRead)
			btr  = t.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForRead)
			for objectid in btr:
				blkRef = t.GetObject(objectid, OpenMode.ForRead)
				if isinstance(blkRef, BlockReference):
					if blkRef.IsDynamicBlock:
						block = t.GetObject(blkRef.DynamicBlockTableRecord, OpenMode.ForRead)
						blkName = block.Name
						props = blkRef.DynamicBlockReferencePropertyCollection
						for prop in props:
							values = prop.GetAllowedValues()
							print(("values", values))
							print("PropertyName", prop.PropertyName)
							if prop.PropertyName == namePropVisu and not prop.ReadOnly:
								idx = System.Array.IndexOf(values, valuePropVisu)
								print("Value", prop.Value)
								print("idx", idx)
								prop.Value = values[idx]

			t.Commit()
6 Likes

Hi, at this moment I have the goal to get solid from visibility state which is currently set in model space and create solid geometry in Dynamo. I tried to edit your code but I have some errors and I do not know how to continue. Could you give me any hint please?

Hi @Drbohlav

I admit that I have no idea how to get the geometry of a dynamic block

@Drbohlav
Try node block.objects or you need changing python code

Can you attached example drawing for testing

Hi @hosneyalaa,
here is example. I’m looking for solution how to get geometry for current visibility. Is here anyne who can help with solution?



Block.dwg (518.6 KB)
D4C3D_block.dyn (18.9 KB)

2 Likes

This is a workaround after I gave up trying to solve this using Python. You need to set the layers for the objects to the individual visibility states. Then you can simply filter geometry.


2 Likes