- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a really decent lisp for importing blocks from a csv file, however i want to modify it to be able to populate a single attribute value upon import. I have a csv file formatted as follows: (BLOCKNAME,x,y,z,ATTRIBUTEVALUE). I was able to modify the lisp to parse the list correctly, however i have been struggling with a solution to populate the attribute value.
The constraints that i must maintain are :
- An existing CAD file where the block reference already exists in the drawing.
- A Hardcoded CSV file location
- The blocks can be different (example files contains only one block reference)
- The attribute value can change for each block
The lisp is as follows:
(defun c:BLKCSV1 (/ SplitStr doc spc csv csv data bn)
(defun SplitStr (s d / p)
(if (setq p (vl-string-search d s))
(cons (substr s 1 p)
(SplitStr (substr s (+ p 1 (strlen d))) d)
)
(list s)
)
)
(if (and (setq doc (vla-get-activedocument (vlax-get-acad-object))
spc (vla-get-block (vla-get-activelayout doc))
)
(setq csv (open "C:/Users/%username%/Documents/Drawing1.csv" "r"))
(read-line csv)
);and
(while (and (setq data (read-line csv))
(setq data (splitstr data ",")
bn (car data)
;;modified variable to get xyx
pnt (cdr (reverse (cdr (reverse data))))
;;added variable for attribute
att (last data)
)
)
(if (tblsearch "block" bn)
(vla-InsertBlock
spc
(vlax-3d-point (mapcar 'atof pnt))
bn
1
1
1
0
);insertblock
;;NOT WORKING
;(setq attributes (vlax-safearray->list (vlax-variant-value (vla-getAttributes bn))))
;; get the first attribute of the list to set its "value" (TextString property)
;(vla-put-TextString (car attributes) att)
);if
);while
);if
(if csv
(close csv)
)
(princ)
)
This lisp originated in a CAD forum, i think it was CAD tutor or something like that. I modified it to read the attribute value from the CSV but as i said, i cant figure out how to get the value to populate based on the csv.
The section marked ";;NOT WORKING" is a solution i found in the Autodesk forums, however it isn't working for me. Can anyone point me in the right direction here? Any help would be greatly appreciated.
Solved! Go to Solution.