[VBA] Changing Dynamic Block Property Values

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear All,
I'm developing a simple function in Excel that updates the property values of a Autocad dynamic block but I'm struggling with the assignment of numeric values.
I've been able to get the properties of the dyn block and store them in a variant variable, and I created a for-next cicle to loop through them to look for the PropertyName I want to set. Apparently the issue is the format of the value I pass.
Here is my function:
Function ChangeAttr_PP(sBlk As String, sAttrTag1 As String, ByVal sVal1 As Variant, Optional sAttrTag2 As String, Optional ByVal sVal2 As Variant, Optional sAttrTag3 As String, Optional ByVal sVal3 As Variant, Optional bAttr As Boolean, Optional sAttrLng As String, Optional sValLng As String)
Dim objEnt As AcadEntity Dim objBlock As AcadBlock Dim objAttrib As AcadAttribute Dim objAttribs As Collection Dim dynBlkProp As Variant Dim iCount As Integer iCount = 0 'Debug.Print acadDoc.FullName Set objBlock = acadDoc.Blocks.Item(sBlk) If objBlock.IsDynamicBlock Then 'get properties from dynamic BlockObj Dim dybprop As Variant, i As Integer Dim bobj As AcadEntity For Each bobj In acadDoc.ModelSpace 'Get AutoCAD Entity's Debug.Print bobj.ObjectName If bobj.ObjectName = "AcDbBlockReference" Then 'Check if BlockRef If bobj.IsDynamicBlock Then 'Check to see if it is a Dynamic Block dybprop = bobj.GetDynamicBlockProperties If bobj.EffectiveName = sBlk Then 'Finds Dynamic Block NAME For i = LBound(dybprop) To UBound(dybprop) 'Goes through Results Dim oProp As AcadDynamicBlockReferenceProperty Set oProp = dybprop(i) Select Case oProp.PropertyName Case sAttrTag1 oProp.Value = sVal1 iCount = iCount + 1 Case sAttrTag2 oProp.Value = sVal2 iCount = iCount + 1 Case sAttrTag3 oProp.Value = sVal3 iCount = iCount + 1 Case sAttrLng oProp.Value = sValLng iCount = iCount + 1 End Select Next i End If End If End If Next ' synchronize definition of block attributes acadDoc.SendCommand ("attsync n " & sBlk & vbCr) MsgBox "Done. Successfully updated " & iCount & " dyn blocks." iCount = 0 If bAttr = True Then GoTo 10 Else [...] End If End Function
And this is how I call the function
Call ChangeAttr_PP(sBlkPnt, "D_Lung", sBldLung & "#", , , , , True, "Visibility1", sLng)
Actually, D_Lung is the PropertyName and sBldLung is the string variable in which I store the value to set.
I read in this article that the numeric values shall be passed as NUM#, hence I added the hash (#) at the end of my value.
Unluckily It happes that it works if I enter directly the value (i.e. if I write 66#) but it doesn't if I pass it as a variable.
Any help would be much appreciated.
Thank you
bye
P