No chit-chat so direct to the point.
I am trying to write a lisp for autocad civil 3D, the first step for it (where I am already stuck) is to get info from object data of a polyline (or what I suppossed is object data) to use it later.
At the beginning I am trying to just show the value of the property on the command line just to be shure it is getting it riht but I am only getting error or nil results.
The info appears in the properties window when you select the polyline (here a screenshot)
screnshot properties window on autocad civil 3D
the idea is to ge the “Thema” value, the “OD” in front of the agrupation name “OD:KLIC_Administratief” makes me think that it is Object Data.
My programing knowledge is low or null, so I am working with chatgpt in order to make it work, with no luck…
I will write the code I have now, under experts eyes it may make no sense, unfortunatelly I don’t understand half the info or functions so I am putting all my trust on chatgpt…
(defun c:GetThemaValue (/ ent objDoc objEnt objData objDataTable objRecords objRecord i fieldName fieldValue)
;; Prompt the user to select a polyline
(setq ent (car (entsel "nSelect a polyline: ")))
;; Check if the selected entity is a polyline
(if (and ent (= (cdr (assoc 0 (entget ent))) "LWPOLYLINE"))
(progn
;; Get the active document
(setq objDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Get the selected entity as a COM object
(setq objEnt (vlax-ename->vla-object ent))
;; Get the collection of object data tables in the document
(setq objData (vla-get-DataBase objDoc))
(setq objDataTables (vla-GetObjectDataTables objData))
;; Check if the object data table "KLIC_Administratief" exists
(if (setq objDataTable (vl-catch-all-apply 'vla-Item (list objDataTables "KLIC_Administratief")))
(progn
;; Get the object data records of the selected entity
(setq objRecords (vlax-invoke objDataTable 'GetObjectDataRecords objEnt))
;; Iterate over the records
(if (> (vlax-safearray-get-u-bound (vlax-variant-value objRecords) 1) 0)
(progn
;; Get the first record (assuming there is at least one)
(setq objRecord (vlax-safearray-get-element (vlax-variant-value objRecords) 0))
;; Get the field names of the record
(setq objFieldNames (vlax-variant-value (vlax-invoke objRecord 'GetFieldNames)))
;; Iterate over the field names to find "Thema"
(setq i 0)
(while (< i (vlax-safearray-get-u-bound objFieldNames 1))
(setq fieldName (vlax-safearray-get-element objFieldNames i))
(if (= fieldName "Thema")
(setq fieldValue (vlax-invoke objRecord 'GetField fieldName))
)
(setq i (1+ i))
)
;; Display the value of the "Thema" field
(if fieldValue
(prompt (strcat "nThe value of the 'Thema' property is: " (vl-princ-to-string fieldValue)))
(prompt "nThe 'Thema' field was not found.")
)
)
(prompt "nThere are no object data records associated with this polyline.")
)
)
(prompt "nThe 'KLIC_Administratief' object data table was not found.")
)
)
(prompt "nThe selected entity is not a polyline.")
)
(princ)
)
And of course, due to my ignorance, I can’t see where is it failing.
well, I tried imploring chatgpt to make it work…
From my ignorance on this field, I have no idea what to try or do to solve this…
Irlanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.