Can't get the ObjectID of AcadDynamicBlockReferenceProperty (VBA)

Can't get the ObjectID of AcadDynamicBlockReferenceProperty (VBA)

Anonymous
Not applicable
2,713 Views
7 Replies
Message 1 of 8

Can't get the ObjectID of AcadDynamicBlockReferenceProperty (VBA)

Anonymous
Not applicable

Hello, I hope someone can help me. Smiley Very Happy

 

I have made a VBA routine that needs to get an ObjectID of an AcadDynamicBlockReferenceProperty.

If i replace:

ThisDrawing.Utility.Prompt dybprop(i).ObjectID & vbCrLf

for:

ThisDrawing.Utility.Prompt dybprop(i).PropertyName & vbCrLf

it returns all the names of the customproperties of the dynamic block.

I want to get the objectID so i can create a field (ObjectARX) and place it into an attribute.

 

Here my full VBA code:

Sub CreateFieldFromAtt_SWDEG()
Dim ss As AcadSelectionSet
Dim dybprop As Variant
Dim i As Integer
Dim bobj As AcadEntity
Dim inspt As Variant
'Dim i
Dim EObjId As String
Dim ErrorCount As Integer
Dim ErrorDataCount As Integer

ErrorCount = 0
ErrorDataCount = 0

On Error Resume Next
Set ss = ThisDrawing.SelectionSets.Add("SS2")
ss.SelectOnScreen
For Each bobj In ss
If bobj.ObjectName = "AcDbBlockReference" Then
'Clear
EObjId = ""

Set oBlkRef = bobj
    If oBlkRef.IsDynamicBlock Then
        dybprop = oBlkRef.GetDynamicBlockProperties
                For i = LBound(dybprop) To UBound(dybprop)
                ThisDrawing.Utility.Prompt dybprop(i).ObjectID & vbCrLf
                            If dybprop(i).PropertyName = "Angle1" Then
                                ThisDrawing.Utility.Prompt "heeft Angle1" & vbCrLf
                                EObjId = dybprop(i).ObjectID
                            End If
                Next i


           'Error Check
           If EObjId = "" Then
                ThisDrawing.Utility.Prompt "Geen SENSOR_TYPE ObjectID" & vbCrLf
                ErrorCount = ErrorCount + 1
                GoTo Error
           End If

            AttList = oBlkRef.GetAttributes
            For i = LBound(AttList) To UBound(AttList)
               If AttList(i).TagString = "SENSOR_TYPE" Then
                    EString = "%<\AcObjProp Object(%<\_ObjId " & EObjId & ">%).TextString>%"
                    AttList(i).TextString = EString & " " & SString & "-" & NString
                    ErrorDataCount = 0
                    Exit For
                    Else
                    ErrorDataCount = 1
               End If
           Next
           If ErrorDataCount = 1 Then
                ThisDrawing.Utility.Prompt "Geen DATAPUNT_NAAM attribute" & vbCrLf
                ErrorCount = ErrorCount + 1
                GoTo Error
           End If
            
Error:
       End If
End If
Next
ThisDrawing.Regen acAllViewports
If ErrorCount = 1 Then
MsgBox "Er is 1 block waar een fout is opgetreden. Bekijk de commandline."
ElseIf ErrorCount > 1 Then
MsgBox "Er zijn " & ErrorCount & " blocken waar een fout is opgetreden. Bekijk de commandline."
End If
ss.Clear
ThisDrawing.SelectionSets("SS2").Delete
End Sub

0 Likes
Accepted solutions (1)
2,714 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I know ObjectID is not part of the GetDynamicBlockProperties object but since i can create the field manualy to ref my Angle1 customproperty i know there is a way to do this with VBA.

Within BlockReference object when i use the method "GetAttributes" i can readout the ObjectID of the Attributes.
Within BlockReference object you have also the method GetDynamicBlockProperties, but cannot readout the ObjectID...

0 Likes
Message 3 of 8

norman.yuan
Mentor
Mentor

As you have already know that AcadDynamicBlockReferenceProperty DOES NOT have ObjectId (because it is not drawing database residing object), so that is no way to get something that simply does not exist.

 

You can try to manually create a field that somehow linked to particular dynamic property of a block reference. If it can be created manually, then it is possible to do it in VBA code. If not, the chances are that it cannot be created by code either.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 8

Anonymous
Not applicable

Thank you for ur answer.

 

Well there is an ObjectID for Angle1 (customproperty) because i can get it manualy. The question is if i can obtain it by VBA...

0 Likes
Message 5 of 8

Anonymous
Not applicable

I make the question easier:
How to obtain the ObjectID number of the (Angle1) AcadDynamicBlockReferenceProperty by VBA?

0 Likes
Message 6 of 8

norman.yuan
Mentor
Mentor
Accepted solution

Again, dynamic property DOES NOT HAVE ObjectId, there is NO WAY to get something that simply does not exist. Period. To make your question easier, you might want to describe/explain what exactly you want to do. However, I assume you are in this situation: you have a rotation parameter defined in the dynamic block, showing as property "Angle1", which is applied to a portion of the block with Rotation action, so they can be drag-rotated. Then the block also has an attribute. Once the block is inserted into drawing as Block Reference, you want the attribute value linked to the rotation parameter (as field), so that when "Angle1" changes, the attribute value would also be updated accordingly.

 

You obviously already tried command "Field" to find out what the field's value looks like when the dynamic property is used in the field. It should like like:

 

%<\AcObjProp Object(%<\_ObjId xxxxxxxxxx>%).Parameter(1).UpdatedAngle \f "%au5">%

 

This is where you were wrong: the objectid in the field value (xxxxxxxxxx) is the Block Reference's ObjectId, not dynamic property's ObjectId (which does not exist!).

 

"Parameter(1)" is used to refer parameters defined in the block as dynamic property. The index would be different, depending on how many parameters are used. 

 

"UpdatedAngle" is only applicable to "Rotation" parameter, obviously.

 

"%au5" if the angle expression's format (decimal, deg/mm/ss,...)

 

Here I provide a concrete example: a block that has a circle and a line with one end at the circle's center; a rotation parameter "HandleAngle" is added with range of 0 to 180 degree and with rotation center at the circle's center; a rotation action apples to the line, using the rotation parameter; then, an attribute added below the circle, with its value to be assigned to a field linking to the rotation parameter when the block being inserted into drawing.

 

Here is the code:

 

Option Explicit

Public Sub InsertMyDynBlock()

    Dim fieldText As String
    fieldText = "%<\AcObjProp Object(%<\_ObjId xxxxxxxxxx>%).Parameter(1).UpdatedAngle \f ""%au5"">%"
    
    Dim blkName As String
    blkName = "Test"
    
    Dim attTag As String
    attTag = "HandleAngle"
    
    Dim pt As Variant
    Dim blk As AcadBlockReference
    Dim i As Integer
    
    '' insert 2 block references
    For i = 1 To 2
        
        If Not GetInsertionPoint(i, pt) Then Exit For
        Set blk = InsertBlock(blkName, pt)
        LinkAttribute blk, attTag, fieldText
        
    Next
    
    ThisDrawing.Regen acActiveViewport
    
End Sub

Private Function GetInsertionPoint(blkIndex As Integer, pt As Variant) As Boolean
    
    On Error Resume Next

    pt = ThisDrawing.Utility.GetPoint(, _
        vbCr & "Select insertion point for block reference " & blkIndex)
    
    If Err.Number <> 0 Then
        GetInsertionPoint = False
    Else
        GetInsertionPoint = True
    End If
    
End Function

Private Function InsertBlock(blkName As String, insPoint As Variant) _
    As AcadBlockReference

    Dim blk As AcadBlockReference
    Set blk = ThisDrawing.ModelSpace.InsertBlock(insPoint, blkName, 1#, 1#, 1#, 0#)
    Set InsertBlock = blk

End Function

Private Sub LinkAttribute(blk As AcadBlockReference, attTag As String, fieldValue As String)

    Dim atts As Variant
    Dim att As AcadAttributeReference
    Dim i As Integer
    Dim id As String
    Dim attVal As String
    
    id = CStr(blk.ObjectID)
    attVal = Replace(fieldValue, "xxxxxxxxxx", id)
    
    atts = blk.GetAttributes()
    For i = 0 To UBound(atts)
        Set att = atts(i)
        If UCase(att.TagString) = UCase(attTag) Then
            att.TextString = attVal
            Exit For
        End If
    Next
    
End Sub

Here is the video clip that show the result of running the code:

 

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 8

norman.yuan
Mentor
Mentor

For some reason, the video got lost in previous reply. Re-try it here:

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 8

Anonymous
Not applicable

This is where you were wrong: the objectid in the field value (xxxxxxxxxx) is the Block Reference's ObjectId, not dynamic property's ObjectId (which does not exist!).


 

Thank you. This did it! I misunderstood the ObjectID. Like attributes have their own Object ID the custom properties don't. Custom properties refer to the blocks ObjectID and work with parameter numbers in my case.

0 Likes