TheSwamp
Code Red => .NET => Topic started by: EDDemtec 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 !
-
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...
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 !
-
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:
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
-
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:
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...
-
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".
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,
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".
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 !
-
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
-
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:
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
-
Hi,
Thank you for this additional information !
On my side, I do not use lookup parameter...