25 | 03 | 2017

Edit Dynamic Block Settings

The Insert Dynamic Block Example showed how to insert a Dynamic Block. It could be possible that Dynamic blocks are already in the drawing. With the following function its possible to change the parameters of a block without.

Function editblock(ByVal Parametername, ByVal Newvalue, ByVal Blockname As String)

Dim ent As AcadEntity
Dim oBkRef As IAcadBlockReference
Dim oDynProp As AcadDynamicBlockReferenceProperty
Dim v As Variant
Dim I As Long

For Each ent In ThisDrawing.ModelSpace
If ent.ObjectName = "AcDbBlockReference" Then
Set oBkRef = ent
If oBkRef.IsDynamicBlock = True Then 'Check if it is a dynamic block

v = oBkRef.GetDynamicBlockProperties 'Get all Dynamic attributes
If oBkRef.EffectiveName = Blockname Then

For I = LBound(v) To UBound(v)

Set oDynProp = v(I)
If Not IsArray(oDynProp.Value) Then 'Not an array
If oDynProp.PropertyName = Parametername Then

Str (oDynProp.Value)

oDynProp.Value = Newvalue 'Set the new value
End If
End If
Next

End If
End If
End If
Next ent

End Function

Call this function using:

Editblock "YourParametername", newvalue, "YourBlockname" 

 If we take the block from the Insert Dynamic Block Example then we would use:

Editblock "Xvalue", 200, "block"
Editblock "Yvalue", 200, "block"

So all blocks with the name 'Block' are now 200 mm Wide and 200mm Long

 


Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2208356
Latest Articles