版本为中望CAD2024,使用GetDynamicBlockProperties似乎无法实际读取到可变块的动态属性,中望API手册中存在对应的GetDynamicBlockProperties方法,然而测试似乎只能对旧有的AutoCAD动态块起作用。
Sub main()
Dim modelSpace As ZcadModelSpace
Dim ent As Object
Dim paramName As String ‘ 线性参数名
Dim newValue As Double
‘创建模型空间
Set modelSpace = ThisDrawing.modelSpace
‘遍历模型空间中的所有实体
For Each ent In modelSpace
‘判断是否是块参照对象
If TypeOf ent Is ZcadBlockReference Then
If ent.Name = “测试块” Then
Debug.Print “块名: ” & ent.Name
‘获取动态块属性
Dim props As Variant
props = ent.GetDynamicBlockProperties
Dim prop As Variant
‘循环遍历动态块属性
Debug.Print “属性数量: ” & UBound(props) – LBound(props) + 1
For Each prop In props
‘获取属性名称和值
On Error Resume Next
Select Case prop.PropertyName
Case “测试距离”
prop.Value = 3500
Exit Sub
End Select
Next prop
End If
End If
Next ent
End Sub
运行后输出为:
块名: 测试块
属性数量: 0