LISP code to populate dwgprops from csv

LISP code to populate dwgprops from csv

caitlyn_lyle6DTB8
Explorer Explorer
1,664 Views
29 Replies
Message 1 of 30

LISP code to populate dwgprops from csv

caitlyn_lyle6DTB8
Explorer
Explorer

Could someone help me clean up this code to get it working properly upon startup? Details and logic required are below:

  • AutoCAD full version 2025
    • Latest error message received:
      • AutoCAD menu utilities loaded.; error: bad argument type: VLA-object collection: #<VLA-OBJECT IAcadSummaryInfo 000001f98b8cf178>; error: bad argument type: VLA-object collection: #<VLA-OBJECT IAcadSummaryInfo 000001f98b8cf178>
  • Logic of the code:
    • Import dwgprops from “INTAKE.csv” that is in the same folder as the AutoCAD drawing file
      • Needs to be case-insensitive
      • Field name = Column A of INTAKE.csv, Value = Column B of INTAKE.csv
    • Any field name in the csv should populate the corresponding values in dwgprops (including blank values)
    • Any dwgprop inside the dwg file that is not listed in the csv file should remain as-is
0 Likes
Accepted solutions (1)
1,665 Views
29 Replies
Replies (29)
Message 2 of 30

paullimapa
Mentor
Mentor

could you also share INTAKE.csv


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

Unfortunately, no as it has IP attached. But there are about 250 rows, text only. 

0 Likes
Message 4 of 30

paullimapa
Mentor
Mentor

Wow that’s a lot of rows of data that needs to be populated into the dwg!!!

Hows about a very simple csv with just a sample couple of rows?

You can remove the sensitive data

With the csv would make it much easier with troubleshooting 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 30

BlackBox_
Advisor
Advisor
(if vla-put-SummaryInfo
  (prompt "\nNormality restored ")
  (alert
    (strcat
      "\"vla-put-SummaryInfo\" LispFunction not defined in the "
      (substr (findfile "acad.exe") 35 4)
      " release. "
    )
  )
)

"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

0 Likes
Message 6 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

Hi! I'm sorry I'm new to lisp - should this be added to the existing lisp code, and if so... in what order? 

0 Likes
Message 7 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

Here you go - I adjusted with the full amount of rows needed but feel free to edit for testing purposes. 

0 Likes
Message 8 of 30

BlackBox_
Advisor
Advisor

Mea culpa, no - I was demonstrating that the code you posted includes an undefined function (vla-put-SummaryInfo) - meaning that the posted code will not work as-is.

 

For reference: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/start-lisp-script-on-qnew/m-p/117929...

 

 

"How we think determines what we do, and what we do determines what we get."

Sincpac C3D ~ Autodesk Exchange Apps

Message 9 of 30

paullimapa
Mentor
Mentor

The errors are caused by these two custom functions:

paullimapa_0-1746639786983.png

I don't know where you got them from but they don't work:

(defun LM:GetExistingProps (/ props key value)
  (setq props '())
  (vlax-for prop (vla-get-SummaryInfo (vla-get-activedocument (vlax-get-acad-object)))
    (setq key (strcase (vlax-get prop 'Name)))
    (setq value (vlax-get prop 'Value))
    (setq props (append props (list (cons key value)))))
  props
)

(defun LM:SetProp (key value)
  (vla-put-SummaryInfo (vla-get-activedocument (vlax-get-acad-object)) key value)
)

The following custom function works:

; SetCustomDwgProp function to add custom prop & value to dwgprops
; Arguments:
; key = custom property name
; value = custom property value
; Usage:
; (SetCustomDwgProp "Project Number" "9001")
; modified from:
; https://www.cadtutor.net/forum/topic/68735-check-if-a-custom-key-exist/#google_vignette
(defun SetCustomDwgProp	(key value / App Doc DwgProps getCustomDwgProp)
; getCustomDwgProp function to retrieve custom property value returns nil if doesn't exist
; Argument:
; key = custom property
 (defun getCustomDwgProp	(key / app doc dwgprops try val)
  (setq	App	 (vlax-Get-Acad-Object)
	      Doc	 (vla-Get-ActiveDocument App)
	      DwgProps (vla-Get-SummaryInfo Doc)
  )
  (cond
    ((vl-catch-all-error-p
       (setq try 
        (vl-catch-all-apply 'vla-GetCustomByKey (list DwgProps key 'val))
       )
     )
     (setq val nil)
    )
  )
  val
 )  
  (setq	App	 (vlax-Get-Acad-Object)
	      Doc	 (vla-Get-ActiveDocument App)
	      DwgProps (vla-Get-SummaryInfo Doc)
  )
  (if (getCustomDwgProp key)
    (vla-SetCustomByKey DwgProps key value)
    (vla-AddCustomInfo DwgProps key value)
  )
)

I also don't see a need to retrieve the existing drawing props with a custom function so I commented this out in the revised code also.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

This is close! It only updated 76 out of 268 rows - do you know how I can fix that issue?

0 Likes
Message 11 of 30

paullimapa
Mentor
Mentor

Must be something in your actual csv file because works fine here:

paullimapa_0-1746640535322.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

Interesting - nothing is different between those rows, just different descriptions. This is the error I get on CAD after the 76th row is populated: error: Automation Error. Invalid key

 

Could it be specific characters that are being used in the values? Like commas, quotations, etc? Or could it be the amount of text in those fields? If so, is there a way to alter the code to push those things through?

0 Likes
Message 13 of 30

paullimapa
Mentor
Mentor

again best way to troubleshoot is for you to share your actual CSV


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

Edited my response above, so wanted to make sure you saw it since we responded at the same time - Could it be specific characters that are being used in the values? Like commas, quotations, etc? Or could it be the amount of text in those fields? If so, is there a way to alter the code to push those things through?

0 Likes
Message 15 of 30

paullimapa
Mentor
Mentor

again not sure depending on what you have on the line where it stopped.

it could be as easy for you to troubleshoot by modifying items on your CSV.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

Unfortunately the content will vary - it's project specific and we have a broad scope. I removed the longer text item in row 76 and the remaining mostly populated. Seems the issue is with large amounts of text or using symbols like - 

 

Is there a way to update the code to include all text (or truncate after 250 characters) and to include special characters?

0 Likes
Message 17 of 30

paullimapa
Mentor
Mentor

I'm not sure if there's a 255 character limit or what characters may be causing the issue. 

Why don't you just include that line in a sample CSV for testing here?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 18 of 30

ec-cad
Collaborator
Collaborator

I think this will work.

Cheers

 

ECCAD

0 Likes
Message 19 of 30

caitlyn_lyle6DTB8
Explorer
Explorer

I would if I could, but I am not allowed to share that information explicitly. But here is some gibberish using the same amount of characters, spacing, and symbols:

- Fdd zxle: ZX QKPBNZJXK ZO YK QGZFEXO, XZRRLZNL, ZND LZJEXK

- Fdd zxle: XR QLKZOHX, XHSTZXCL ZKD ZCZZLZNX ZCJXEZQX SF SGLXSHHD ZNLSXHC ZLJXS ZKD/SQX STJZQ XTXLZTXJS XN ZZLZNXZS XS YJ QJ VZNXKX

GJZLSCJ Z zxle svcxjzjgc tkzt “24/7 txoxcgjxk yzzljzp xtcczz yhlcc xk rlzj Ywaj Gnlzqx qjzchqjx.”

-J zhnzkjzl fs qzx stxzzx qjsslm le iyclyhjk xk yxzf qdbz xkd vkhx qzjs, xz zccktxj xs yhe xgezt yhe hyzlx zs xk qlzzz jplsx jkd xzclxdt zhe rzze, djstzkx zkd dklzxz xs yhe xzkxzzx hqqsz yhe rzzezt rzxx yz sxqsn.
-Yhe ndzk zlxvcl jnxznx, zjj zezxl stczxzkx, ndzk zlxvcl rzjzl, zkshzccjyz, yzkxsxjklxz, zkd xzslzxzk zkd zxkylzk WTA xysyxz lnyt le sjzxn xs yhe xzkx zzzn. Xxel Gnlzqx xlzlc yhe Tzwkzjjar 3 cjexjyl zzkzljx xs yhe xzkx zzzn.

0 Likes
Message 20 of 30

paullimapa
Mentor
Mentor

fails if there's a duplicate key


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes