Jump to content

swap blocks and update layer from csv


therealjd

Recommended Posts

I'm hoping someone could help me with a lisp that will do the following.. 

1. swap all instances of a block with another block (keeping location, rotation, scale)

2. change that new block to a new layer.

i'd like to automate this through the use of a csv file. If the old block doesn't exist, skip it. 

oldblock1,newblock1,newlayer1

oldblock2,newblock2,newlayer2

 

Any help would be appreciated

 

I did find this code on the forum, but i'm unsure how to alter it. 

; ; thanks to Lee-mac for this defun
(defun _csv->lst ( str / pos x lst lst2)
(if (setq pos (vl-string-position 44 str))
   (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
   (list str)
   )
)

(defun c:ins->csv ( / fo x)
(setq fo (open (getfiled "Choose CSV file" "G:/AutoCAD/Lisp/" "CSV" ) "R")
(while (setq ans (read-line fo))
(setq lst (cons (_csv->lst ans) lst))
)
(setq y (length lst)) 
(setq x (- y 1))
(repeat y
(setq lst2 (nth x lst))
;(setvar 'clayer (nth 6 lst2))
(command "insert" (nth 0 lst2) (strcat (nth 1 lst2)","(nth 2 lst2)","(nth 3 lst2)) 1 (nth 5 lst2) (nth 7 lst2) (nth 8 lst2))
(setq x (- x 1))
)

) ; end defun

 

 

Edited by therealjd
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...