Author Topic: Command to build a list for dynamic blocks  (Read 2424 times)

0 Members and 1 Guest are viewing this topic.

EDDemtec

  • Guest
Command to build a list for dynamic blocks
« on: August 14, 2012, 10:32:31 AM »
Hi guys !

With my command, I want to build a list(Effectivename /Quantity) of block in a selection set, for now I'm ok for that !

I explain my problem:

I have a dynamic block named 'ElecBaseboard' for electric baseboard. Inside this block, there are many blocks for each watts (500W, 750W, 1000W etc....) On the list, the name appears as ElecBaseboard. Is there a unique value for a block that is the same in any drawings, a value that I can search in database and extract the name that I want to appear on the list...

Note: I forgot to specify that I use visibility parameter to display the block inside ElecBaseboard...

Is it posssible ?

Is there another way to do what I want ?

Thanks in advance !
« Last Edit: August 14, 2012, 03:55:18 PM by EDDemtec »

EDDemtec

  • Guest
Re: Command to build a list for dynamic blocks
« Reply #1 on: August 15, 2012, 09:57:22 AM »
I attached to this message the drawing...

The quick solution to my problem is that the user explodes the block but I dont want this...

Here is the current code, sorry some words are in french...
Code: [Select]
Public Class CountListBlocks

    'Définir la commande
    <CommandMethod("clb")> _
    Public Sub clb()

        'Obtenir l'éditeur de document en cours
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim db As Database = doc.Database

        'Déclarer les listes array
        Dim clbEffNameAr As New ArrayList()
        Dim clbBlockQtyAr As New ArrayList

        'Demarrer une transaction
        Using acTrans As Transaction = db.TransactionManager.StartTransaction()

            Dim blkref As BlockReference
            Dim acadblkref As AcadBlockReference

            'Création d'un type pour définir les critères de filtrage (Block = Insert)
            Dim acTypValAr(0) As TypedValue
            acTypValAr.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 0)

            'Attribuer les critères de filtre à un objet SelectionFilter
            Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)

            'Demande une sélection dans le dessin
            Dim acSSPrompt As PromptSelectionResult = doc.Editor.GetSelection(acSelFtr)

            'Si sélection est OK, poursuivre
            If acSSPrompt.Status = PromptStatus.OK Then
                Dim wss As SelectionSet = acSSPrompt.Value
                'Boucle le selection set
                For Each acSSObj As SelectedObject In wss
                    'Obtenir objet en cours
                    blkref = acSSObj.ObjectId.GetObject(OpenMode.ForRead)
                    'Convertir objet Blockreference en AcadBlockreference
                    acadblkref = CType(blkref.AcadObject, AcadBlockReference)
                    'Compiler la liste des blocks (quantité/nom)
                    'Vérifier que la liste n'est pas vide
                    If clbEffNameAr.Count > 0 Then
                        'Recherche l'effectivename courant
                        Dim i As Long
                        For i = 0 To clbEffNameAr.Count - 1
                            'Si existant modifier la quantité
                            If clbEffNameAr.Item(i) = acadblkref.EffectiveName Then
                                clbBlockQtyAr(i) = clbBlockQtyAr(i) + 1
                            'Si non existant ajouter effectivename et quantité
                            Else
                                clbEffNameAr.Add(acadblkref.EffectiveName)
                                clbBlockQtyAr.Add(1)
                            End If
                        Next
                    'Si vide, ajouter première valeur et quantité 1
                    Else
                        clbEffNameAr.Add(acadblkref.EffectiveName)
                        clbBlockQtyAr.Add(1)
                    End If
                Next
            Else
                Application.ShowAlertDialog("There is no block in the selection...")
            End If
            acTrans.Commit()
        End Using
        'Afficher les résultats
        Dim ii As Long
        For ii = 0 To clbEffNameAr.Count - 1
            MsgBox(clbEffNameAr(ii) & "Qte: " & clbBlockQtyAr(ii))
        Next
    End Sub

End Class

Thanks in advance !

Gasty

  • Newt
  • Posts: 90
Re: Command to build a list for dynamic blocks
« Reply #2 on: August 15, 2012, 06:29:33 PM »
Hi,

I'm not sure but it seems that you need the "active block name" i.e the name of the current visibility state, if so something like this may be what you want:

Code: [Select]
Public Function GetActiveBlockName(blkref as BlockReference) as string
         Dim dynprops As DynamicBlockReferencePropertyCollection = blkref.DynamicBlockReferencePropertyCollection
         For each dynprop as DynamicBlockReferenceProperty in dynprops
           if dynprop.name="Puissance plinthe" then
              return dynprop.value
           end if
         Next
End Function


Gaston Nunez

EDDemtec

  • Guest
Re: Command to build a list for dynamic blocks
« Reply #3 on: August 16, 2012, 08:31:05 AM »
Hi,

I'm not sure but it seems that you need the "active block name" i.e the name of the current visibility state, if so something like this may be what you want:

Code: [Select]
Public Function GetActiveBlockName(blkref as BlockReference) as string
         Dim dynprops As DynamicBlockReferencePropertyCollection = blkref.DynamicBlockReferencePropertyCollection
         For each dynprop as DynamicBlockReferenceProperty in dynprops
           if dynprop.name="Puissance plinthe" then
              return dynprop.value
           end if
         Next
End Function


Gaston Nunez

Your code do I what I want, but... I have many other blocks, with other visibility name.

I will check what I can do...

Gasty

  • Newt
  • Posts: 90
Re: Command to build a list for dynamic blocks
« Reply #4 on: August 16, 2012, 01:12:23 PM »
Hi,

As a Dynamic Block can have only one visibility state parameter in its definition, you can test for PropertyTypeCode=5 and then get the value of the dynamic property to obtain the name of the "active block name".

Code: [Select]
Public Function GetActiveBlockName(blkref as BlockReference) as string
         '''Assumed block is dynamic
         Dim dynprops As DynamicBlockReferencePropertyCollection = blkref.DynamicBlockReferencePropertyCollection
         For each dynprop as DynamicBlockReferenceProperty in dynprops
           if dynprop.PropertyTypeCode=5 then
              return dynprop.value
           end if
         Next
End Function

EDDemtec

  • Guest
Re: Command to build a list for dynamic blocks
« Reply #5 on: August 16, 2012, 01:26:55 PM »
Hi,

As a Dynamic Block can have only one visibility state parameter in its definition, you can test for PropertyTypeCode=5 and then get the value of the dynamic property to obtain the name of the "active block name".

Code: [Select]
Public Function GetActiveBlockName(blkref as BlockReference) as string
         '''Assumed block is dynamic
         Dim dynprops As DynamicBlockReferencePropertyCollection = blkref.DynamicBlockReferencePropertyCollection
         For each dynprop as DynamicBlockReferenceProperty in dynprops
           if dynprop.PropertyTypeCode=5 then
              return dynprop.value
           end if
         Next
End Function

Hi !

I have no idea what PropertyTypeCode, but it works ! I did not find any help on this property...

Thanks !

Gasty

  • Newt
  • Posts: 90
Re: Command to build a list for dynamic blocks
« Reply #6 on: August 16, 2012, 03:05:58 PM »
Hi,

Glad to help. I can't find help in the docs too, it supposed to be an enumeration, but it's not listed (Managed nor ARX). I'll post help on this here and in  the Autodesk .NET forum.

Gaston Nunez

Gasty

  • Newt
  • Posts: 90
Re: Command to build a list for dynamic blocks
« Reply #7 on: August 16, 2012, 04:38:05 PM »
Hi,

Alexander Rivilis give us a insight of this, PropertyTypeCode is the value type, meaning that 1 stand for a Real value, 5 a text (string), 12 a Point3d, and so on.

That complicate a little the things, because a dynamic block can have a lookup parameter with text values, an that imply that a 5 value in PropertyTypeCode is not necessarily a visibility state, so be careful with that.

here is the complete list from acdb.h:

Code: [Select]
enum DwgDataType       { kDwgNull            = 0,
                             kDwgReal            = 1,
                             kDwgInt32           = 2,
                             kDwgInt16           = 3,
                             kDwgInt8            = 4,
                             kDwgText            = 5,
                             kDwgBChunk          = 6,
                             kDwgHandle          = 7,
                             kDwgHardOwnershipId = 8,
                             kDwgSoftOwnershipId = 9,
                             kDwgHardPointerId   = 10,
                             kDwgSoftPointerId   = 11,
                             kDwg3Real           = 12,
                             kDwgInt64           = 13,
                             kDwgNotRecognized   = 19 };

Gaston Nunez

EDDemtec

  • Guest
Re: Command to build a list for dynamic blocks
« Reply #8 on: August 17, 2012, 08:06:46 AM »
Hi,

Thank you for this additional information !

On my side, I do not use lookup parameter...