- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a CSV that holds a the location (x coordinate, y coordinate) and the attributes to assign to a block (addresses, and parcel numbers). The LISP that I wrote creates these blocks and the location with the given attributes using entmakex however when I run the LISP the blocks only show when selected through select similar or by filtering them out when selecting the whole file's geometry. I've run regen and regenall however the blocks still won't show outside the property manager. Any help?
Note: this will import 1397 addresses so I would like to use entmakex to save time.
LISP:
(defun c:ParcelCreator (/ LM:str->lst read_csv_file draw_pline ; local functions
fname points^ itm)
;; Parse string in CSV ;;
(defun LM:str->lst ( str del / pos )
(if (setq pos (vl-string-search del str))
(cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
(list str)
)
) ; LM:str->lst
(defun read-csv-addy (filename)
(setq file (open filename "r"))
(if (not file)
(progn
(princ "\nError: Unable to open file.") ; Print error message
(exit) ; Stop execution
)
)
(setq data '())
(while (setq line (read-line file))
(setq fields (LM:str->lst line ",")) ; Use LM:str->lst instead of vl-string-split
(if (and fields (= (length fields) 5)) ; Ensure fields exist and have 4 elements
(setq data (cons fields data))
)
)
(close file)
(reverse data)
)
(defun insert-block (blkname polyind x y address apn)
(setq inspt (list (atof x) (atof y) 0)) ; Convert string coordinates to numbers
;; Create block reference
(setq blk-entity (entmakex (list
(cons 0 "INSERT") ; Block reference
(cons 2 blkname) ; Block name
(cons 10 inspt) ; Insertion point
(cons 41 1.0) ; X scale factor
(cons 42 1.0) ; Y scale factor
(cons 43 1.0) ; Z scale factor
(cons 50 0.0) ; Rotation angle
)))
; Now modify the attributes of the inserted block
(setq ent (entnext blk-entity)) ; Get the first attribute
(while ent
(setq entData (entget ent)) ; Get the entity data of the attribute
(setq tag (cdr (assoc 2 entData))) ; Get the tag of the attribute
(if (equal tag "ADDRESS") ; Match the tag of the attribute
(progn
; Modify the attribute value
(setq newEntData (subst (cons 1 address) (assoc 1 entData) entData))
(entmod newEntData) ; Modify the attribute entity
(princ (strcat "Modified attribute " tag address))
)
)
(if (equal tag "APN") ; Match the tag of the attribute
(progn
; Modify the attribute value
(setq newEntData (subst (cons 1 apn) (assoc 1 entData) entData))
(entmod newEntData) ; Modify the attribute entity
(princ (strcat "Modified attribute " tag " to " apn))
)
)
(setq ent (entnext ent)) ; Move to the next attribute
)
(princ "Block inserted and attributes modified.")
)
;; Main execution
(setq mykmzPath (getfiled "Select KMZ File" "" "" 0)) ; Get the KMZ file path
(if mykmzPath ;if KMZ exists go into script
(progn
(setq dir (vl-filename-directory mykmzPath))
(setq Addresspath (strcat dir "\\" "AddressCoords.csv"))
(setq start 1)
(if (setq Aname (findfile Addresspath))
(progn
(setq blkname "ADD_PLACE")
(setq csv-data (read-csv-addy Aname))
;;(print csv-data)
(foreach row csv-data
(if (= start 1)
(progn
(print "here")
(setq start (+ start 1))
)
(progn
(print row) ; Debug output to check row format
(apply 'insert-block (cons blkname row))
)
)
)
)
)
)
)
(print) ; Final print for cleanliness
)
Solved! Go to Solution.