Author Topic: Get properties from not inserted dynamic blocks  (Read 2845 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
Get properties from not inserted dynamic blocks
« on: September 04, 2013, 03:41:18 PM »
Hi
To continue from thread 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

Bert

  • Guest
Re: Get properties from not inserted dynamic blocks
« Reply #1 on: September 05, 2013, 06:01:56 AM »
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)  :|
 
Code: [Select]
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


pedroantonio

  • Guest
Re: Get properties from not inserted dynamic blocks
« Reply #2 on: September 05, 2013, 01:12:32 PM »
Bert  8-) , thank you very very much  !! It works  :lol: :-D

Can you please further explain why is this approach not generally recommended?

CottageCGirl

  • Guest
Re: Get properties from not inserted dynamic blocks
« Reply #3 on: September 05, 2013, 02:13:28 PM »
apparently I am going insane.. or blinder.. REALLY thougth this thread was titled "Get prostitutes interested in dynamic blocks". ROFL

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Get properties from not inserted dynamic blocks
« Reply #4 on: September 05, 2013, 03:14:13 PM »
REALLY thougth this thread was titled "Get prostitutes interested in dynamic blocks". ROFL

Close: "Get prostitutes interested in dynamic blokes"
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Get properties from not inserted dynamic blocks
« Reply #5 on: September 05, 2013, 04:27:27 PM »
Doesn't sound much different than the spam hitting the AutoDesk Discussion groups.   :lol:
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

kaefer

  • Guest
Re: Get properties from not inserted dynamic blocks
« Reply #6 on: September 05, 2013, 06:21:15 PM »
I've been looking into your question & searching the net

Did you find this, 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.

Bert

  • Guest
Re: Get properties from not inserted dynamic blocks
« Reply #7 on: September 09, 2013, 02:16:51 AM »
Yes but No.

The sourcecode is very similar but i'm certain this was not the thread nor post I found the original solution.