TheSwamp
Code Red => .NET => Topic started by: pedroantonio on September 04, 2013, 03:41:18 PM
-
Hi
To continue from thread http://www.theswamp.org/index.php?topic=42796 (http://www.theswamp.org/index.php?topic=42796) as I have similar question but for dynamic blocks:
How can I get all possible properties from NOT INSERTED dynamic blocks (visibility, lookups, flips, etc...)?
Above code returns only attributes which is fine for static blocks and attributes part of dynamic blocks, but no Visibility or similar properties...
By Google search I have found many examples how to return other properties I need by using a BlockReference and that is not possible while blocks are not yet inserted in the drawing. Or is possible?
I appreciate every help... thanks in advance
-
Hi pedroantonio !
I've been looking into your question & searching the net and this is what i've come up with :
It's possible to read dynamic properties from a BlockTableRecord if you really need to, but you'll need to reference the unsupported acmgdinternal module for it
(wich is generally not recommended) :|
Sub DynamicPropsFromBlockTableRecord()
'' Get the current document and database
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database = acDoc.Database
'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Open the Block table for read
Dim acBlkTbl As BlockTable= acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
For Each acObjId As ObjectId In acBlkTbl
Dim obj As DBObject = acObjId.GetObject(OpenMode.ForRead)
If TypeOf obj Is BlockTableRecord Then
Dim acBlkTblRec As BlockTableRecord = acObjId.GetObject(OpenMode.ForRead)
If acBlkTblRec.IsDynamicBlock Then
Dim extDictDynBT As DBDictionary = DirectCast(acTrans.GetObject(acBlkTblRec.ExtensionDictionary, OpenMode.ForRead, False), DBDictionary)
Dim acadEnhancedBlk As DBObject = DirectCast(acTrans.GetObject(extDictDynBT.GetAt("ACAD_ENHANCEDBLOCK"), OpenMode.ForRead, False), DBObject)
Dim graph As EvalGraph = Nothing
Dim idGraph As ObjectId = acadEnhancedBlk.ObjectId
If Not idGraph.IsNull Then
graph = DirectCast(acTrans.GetObject(idGraph, OpenMode.ForRead), EvalGraph)
If graph IsNot Nothing Then
Dim iNodes As Integer() = graph.GetAllNodes()
For Each iNode As Integer In iNodes
Dim node As DBObject = graph.GetNode(CUInt(iNode), OpenMode.ForRead, acTrans)
If node IsNot Nothing Then
Dim eExpr As EvalExpr = TryCast(node, EvalExpr)
'If type is BlockLookupAction
If eExpr.[GetType]() Is GetType(BlockLookupAction) Then
Dim blua As BlockLookupAction = TryCast(eExpr, BlockLookupAction)
If blua IsNot Nothing Then
Dim pDataTable As Array
Dim descArray As LookupColumnDescriptorCollection
blua.GetLookupTable(pDataTable, descArray)
End If
End If
'If type is BlockLookupAction
If eExpr.[GetType]() Is GetType(BlockLookupParameter) Then
Dim blup As BlockLookupParameter = TryCast(eExpr, BlockLookupParameter)
If blup IsNot Nothing Then
Dim props As BlockParameterPropertyDescriptorCollection = blup.PropertyDescription
For Each prop As BlockParameterPropertyDescriptor In props
'INSERT YOUR CODE HERE
Next
End If
End If
End If
Next
End If
End If
End If
End If
Next
'' Dispose of the transaction
End Using
End Sub
-
Bert 8-) , thank you very very much !! It works :lol: :-D
Can you please further explain why is this approach not generally recommended?
-
apparently I am going insane.. or blinder.. REALLY thougth this thread was titled "Get prostitutes interested in dynamic blocks". ROFL
-
REALLY thougth this thread was titled "Get prostitutes interested in dynamic blocks". ROFL
Close: "Get prostitutes interested in dynamic blokes"
-
Doesn't sound much different than the spam hitting the AutoDesk Discussion groups. :lol:
-
I've been looking into your question & searching the net
Did you find this (http://forums.autodesk.com/t5/NET/Definition-of-Dynamic-Blocks-with-NET-API/td-p/2377920/page/2), by any chance?
Hallex' code does work, but suffers far too many levels of indentation. A few could be shaved off without altering the logic: After DirectCast there's no need to test for Nothing. The second cast to EvalGraph and subsequent comparisons of System.Type object are superfluous; instant TryCast to e.g. BlockLookupAction would take care of it.
Unedited he said, not unedifying.
-
Yes but No.
The sourcecode is very similar but i'm certain this was not the thread nor post I found the original solution.