@jtm2020hyo
Here is an example of retrieving the value of a Property in a Property Set on a selected object. Apologies for not making the variables local; I adapted code I had used to explore object data access and dumped it into a quick command function. The code defines a custom command called WALLREMARKS. The command prompts the user to select a Wall object. You can select anything, but meaningful results will only be obtained if you select a Wall that has the WallObjects Property Set attached and that Property Set has a Remarks property defined in it. If so, the value of the Remarks property is displayed on the command line.
(defun C:WallRemarks ()
(setq ent (entsel "\Select Wall: ")
ename (car ent)
obj (vlax-ename->vla-object ename)
) ;_ End setq.
;; Code to explore object model.
(vl-load-com)
;; AutoCAD Application Object.
(setq aa (vlax-get-acad-object)) ; Holds the AutoCAD Application object.
;; AEC Schedule Applicaton Object.
(setq aecschd (vla-GetInterfaceObject
aa
(strcat "AecX.AecScheduleApplication" ".8.2")
)
; Holds AecScheduleApplication object.
) ;_ End setq.
(setq oPSets (vlax-invoke-method aecschd 'PropertySets obj)
iPSets (vlax-get-property oPSets 'Count)
iPSet 0
) ;_ End setq.
(while (< iPSet iPSets) ; While unprocessed property sets remain...
(setq oPSet (vlax-invoke-method oPSets 'Item iPSet)
; Get current property set object.
sPSetNm (vlax-get-property oPSet 'Name)
; Get property set name.
) ;_ End setq.
(if (= (strcase sPSetNm) (strcase "WallObjects"))
(setq iPSet (1+ iPSets)) ; Target property set found, exit while loop.
(setq iPSet (1+ iPSet)) ; Increment property set counter.
) ;_ End if.
) ;_ End while.
(cond ; Cond A.
((= iPSet iPSets)
;; If the property set is not found after processing all attached property sets, issue prompt.
(prompt "\nWallObjects not found on selected object. ")
) ;_ End condition A1.
(T
(setq oProps (vlax-get-property oPSet 'Properties)
iProps (vlax-get-property oProps 'Count)
; Total number of properties in the property set.
iProp 0
) ;_ End setq.
(while (< iProp iProps) ; While unprocessed properties remain...
(setq oProp (vlax-invoke-method oProps 'Item iProp)
; Get current property object.
sPropNm (vlax-get-property oProp 'Name)
; Get property name.
) ;_ End setq.
(if (= (strcase sPropNm) (strcase "Remarks"))
(setq iProp (1+ iProps)) ; Target property found, exit while loop.
(setq iProp (1+ iProp)) ; Increment property counter.
) ;_ End if.
) ;_ End while.
(cond ; Cond A2B.
((= iProp iProps)
;; If the property is not found after processing all properties in the property set, issue prompt.
(prompt
"\nWallObjects:Remarks property not found on selected object. "
)
) ;_ End condition A2B1.
(T
(setq varPropVal (vlax-get-property oProp 'Value)
sPropVal (vlax-variant-value varPropVal)
) ;_ End setq.
(prompt
(strcat
"\nRemarks property value = \""
sPropVal
"\" "
) ;_ End strcat.
) ;_ End prompt.
) ;_ End condition A2B2.
) ;_ End cond A2B.
) ;_ End condition A2.
) ;_ End cond A.
(prin1)
) ;_ End C:WallRemarks.
Just a little more than a single line. 😉 And all of that to get one property value! To be fair, you would not have to repeat the entire thing for each additional property value. You would only need to do the code up through finding the target Property Set once, then have a while loop searching for a given target Property for each target Property, saving the values to unique variables. Then a single prompt could display all of the collected values.
Copy the above to Notepad (or any other plain text editor) and save it as an AutoLISP file (LSP extension). Drag and drop the file into the AutoCAD canvas and the WALLREMARKS command will be defined. Type WALLREMARKS at the command prompt and press the ENTER key to run the command.
NOTE: This is written to run in AutoCAD Architecture 2020. In line 15, change ".8.2" to ".8.3" for 2021, ".8.4" for 2022, or ".8.5" for 2023.
David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
