Here is a different approach to manipulating dynamic blocks.
I include several functions
The one you can use is
Code:
(DynamicPropertyPut objSelection strProperty Value)
Include block instance, propertyname and new value.
P=
Code:
;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2020 All Rights Reserved
;___________________________________________________________________________________________________________|
;___________________________________________________________________________________________________________|
;
; General Function Header List
;___________________________________________________________________________________________________________|
;* (DynamicProperty objSelection strProperty)
;* Function to put a dynamic property value given Block Reference object, propertyname and new value
;* (DynamicPropertyPut objSelection strProperty Value)
;* Function to put a dynamic property value given Block Reference object, propertyname and new value
;* (DynamicSublist objDynamic strWCProperty)
;* Function to get a sublist of Propertyname, Value as Variant, Value, VariantType, vla-object
;* (DynamicSublists objSelection strWCProperty )
;* Function to get a dynamic block property value given block instance object, wildcard dynamic propertyname
;* (ErrorTrap symFunction)
;* Function to trap error. Syntax (errortrap '(setq A (/ 1 0)))
;$ Header End
;___________________________________________________________________________________________________________|
;
; Function to put a dynamic property value given Block Reference object, propertyname and new value
;___________________________________________________________________________________________________________|
(defun DynamicProperty (objSelection strProperty / lstOfSublists)
(if (setq lstOfSublists (DynamicSublists objSelection (strcase strProperty )))
(cadar lstOfSublists)
)
)
;___________________________________________________________________________________________________________|
;
; Function to put a dynamic property value given Block Reference object, propertyname and new value
;___________________________________________________________________________________________________________|
(defun DynamicPropertyPut (objSelection strProperty Value / intVariantType lstSublist objDynamic)
(if (and (setq lstOfSublists (DynamicSublists objSelection (strcase strProperty )))
(setq lstSublist (car lstOfSublists))
(setq objDynamic (car (reverse lstSublist)))
(setq intVariantType (nth 3 lstSublist))
)
(errortrap (quote (vlax-put-property objDynamic
"Value"
(vlax-make-variant Value
intVariantType
)
)
)
)
)
)
;___________________________________________________________________________________________________________|
;
; Function to get a sublist of Propertyname, Value as Variant, Value, VariantType, vla-object
; Given a Dynamic Block Property object and wildcard propertyname
; Returns a sublist for success and nil for failure
;___________________________________________________________________________________________________________|
(defun DynamicSublist (objDynamic
strWCProperty
/
intVariantType
strPropertyName
varValue
)
(if (and
(= (type objDynamic) 'vla-object)
(vlax-property-available-p objDynamic "PropertyName")
(setq strPropertyName (strcase (vla-get-propertyname objDynamic)))
(wcmatch (strcase strPropertyName)(strcase strWCProperty))
)
(list strPropertyName
(setq varValue (vlax-get-property objDynamic "Value"))
(vlax-variant-value varValue)
(vlax-variant-type varValue)
objDynamic
)
)
)
;___________________________________________________________________________________________________________|
;
; Function to get a dynamic block property value given block instance object, wildcard dynamic propertyname
;___________________________________________________________________________________________________________|
(defun DynamicSublists (objSelection
strWCProperty
/
lstDynamicBlockProperties
lstReturn
objDynamic
strProperty
)
(if (and
(= (type objSelection) 'vla-object)
(vlax-property-available-p objSelection "IsDynamicBlock")
(= (vlax-get objSelection "IsDynamicBlock") -1)
(setq lstDynamicBlockProperties (vlax-invoke objSelection "GetDynamicBlockProperties"))
)
(foreach objDynamic (reverse lstDynamicBlockProperties)
(and (setq lstDynamicSublist (DynamicSublist objDynamic strWCProperty))
(setq lstReturn (cons lstDynamicSublist lstReturn))
)
)
)
lstReturn
)
;___________________________________________________________________________________________________________|
;
; Function to trap error. Syntax (errortrap '(setq A (/ 1 0)))
;___________________________________________________________________________________________________________|
(defun ErrorTrap (symFunction / objError result)
(if (not
(vl-catch-all-error-p
(setq objError (vl-catch-all-apply
'(lambda (X)(set X (eval symFunction)))
(list 'result)))))
(if result result 'T)
)
)
(princ "!")
(vl-load-com)