Correct way to write a lisp for civil 3D that gets the Object Data from a polyline

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…

New contributor

Irlanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật