Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LIsp and i'm stuck.....HELP!

4 REPLIES 4
Reply
Message 1 of 5
camardi
387 Views, 4 Replies

LIsp and i'm stuck.....HELP!

guys, i know how to write a simple lisp to rename and repath multiple xrefs....i just dont know how to progress to the next level.....I need to add a loop into the code below to search for a name and if it doesnt existing within that particular drawing, to skip to the next xref....

 

anybody?

 

---------------------------------------------------------------------------------------------------------------------------------------------

 

(defun c:repath ()

(command "-rename" "b" "XC00-AA005360-AAX-00-TITLE" "XC00-PN001234-aax-00-TITLE")
(command "-xref" "p" "XC00-PN001234-aax-00-TITLE" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC00-PN001234-aax-00-TITLE")

(command "-rename" "b" "XC01-AA005360-AAX-00-SURVEY" "XC01-PN001234-aax-00-SURVEY")
(command "-xref" "p" "xC01-PN001234-aax-00-SURVEY" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC01-PN001234-aax-00-SURVEY")

(command "-rename" "b" "XC02-AA005360-AAX-00-CADASTRE" "XC02-PN001234-aax-00-CADASTRE")
(command "-xref" "p" "xC02-PN001234-aax-00-CADASTRE" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC02-PN001234-aax-00-CADASTRE")

(command "-rename" "b" "XC03-AA005360-AAX-00-EXCONT" "XC03-PN001234-aax-00-EXCONT")
(command "-xref" "p" "XC03-PN001234-aax-00-EXCONT" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC03-PN001234-aax-00-EXCONT")

(command "-rename" "b" "XC04-AA005360-AAX-00-DESIGN" "XC04-PN001234-aax-00-DESIGN")
(command "-xref" "p" "XC04-PN001234-aax-00-DESIGN" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC04-PN001234-aax-00-DESIGN")

(command "-rename" "b" "XC05-AA005360-AAX-00-DESCONTS" "XC05-PN001234-aax-00-DESCONTS")
(command "-xref" "p" "XC05-PN001234-aax-00-DESCONTS" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC05-PN001234-aax-00-DESCONTS")

(command "-rename" "b" "XC06-AA005360-AAX-00-RDLONG" "XC06-PN001234-aax-00-RDLONG")
(command "-xref" "p" "XC06-PN001234-aax-00-RDLONG" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\xcsu-PN001234-aax-00-RDLONG")

)

 

---------------------------------------------------------------------------------------------------------------------------------------------

 

 

ps i've deliberatly separated the lines of code hoping somebody adds the loop for me 🙂

4 REPLIES 4
Message 2 of 5
mid-awe
in reply to: camardi

Just a suggestion, use vl-cmdf. vl-cmdf function evaluates all the supplied arguments before executing the AutoCAD command, and will not execute the AutoCAD command if it detects an error during argument evaluation. 

 

That should help with the skipping part of your issue.

Message 3 of 5
pbejse
in reply to: camardi

In simple modification:

 

(defun c:repath ( / renblk repathxr)
 (foreach blks (list '(("XC00-AA005360-AAX-00-TITLE" "XC00-PN001234-aax-00-TITLE")
                       ("XC00-PN001234-aax-00-TITLE"
                        "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC00-PN001234-aax-00-TITLE"
                       )
                      )
                     '(("XC01-AA005360-AAX-00-SURVEY" "XC01-PN001234-aax-00-SURVEY")
                       ("xC01-PN001234-aax-00-SURVEY"
                        "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC01-PN001234-aax-00-SURVEY"
                       )
                      )
                     '(("XC02-AA005360-AAX-00-CADASTRE" "XC02-PN001234-aax-00-CADASTRE")
                       ("xC02-PN001234-aax-00-CADASTRE"
                        "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC02-PN001234-aax-00-CADASTRE"
                       )
                      )
                     '(("XC02-AA005360-AAX-00-CADASTRE" "XC02-PN001234-aax-00-CADASTRE")
                       ("xC02-PN001234-aax-00-CADASTRE"
                        "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC02-PN001234-aax-00-CADASTRE"
                       )
                      )
               )
(setq renblk (car blks)
      repathxr (Cadr blks))
   (if (tblsearch "BLOCK" (car renblk))
         	(command "-rename" "b" (car renblk) (cadr renblk)))
   (if (and (tblsearch "BLOCK" (car repathxr))
              (findfile (strcat (cadr repathxr) ".dwg")))
         	(command "-xref" "p" (car repathxr) (cadr repathxr))
         )
        )
   )

 

Also you may need to check if the blocks New name already exist, then

 

(if (and (tblsearch "BLOCK" (car renblk))
            (not (tblsearch "BLOCK" (cadr renblk))))
         	(command "-rename" "b" (car renblk) (cadr renblk))
     		(princ "\nBlock name already exists"))

 

 HTH

Message 4 of 5
camardi
in reply to: pbejse

oh, ok...pbejse, am i meant to add that to the top of the lisp? 

 

Im just not sure how this links to what i've got already? Im sure im just missing something. it looks like the command is on the bottom and the variables are above it?

 

sorry if i sound a little dense, havent really done that much in relation to autolisp

Message 5 of 5
pbejse
in reply to: camardi

You asked for a "loop" right?

 

In this case we use the  foreach function to iterate thru the list of Block names and Xrefs

The list is broken down into two parts fore each loop

 

(

("XC00-AA005360-AAX-00-TITLE" "XC00-PN001234-aax-00-TITLE")
("XC00-PN001234-aax-00-TITLE"
"E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC00-PN001234-aax-00-TITLE"
)
)

 

(IF (and  (tblsearch "BLOCK" "XC00-AA005360-AAX-00-TITLE") <---true 

(not (tblsearch "BLOCK" "XC00-PN001234-aax-00-TITLE")) <--- also true

 

then--- > (command "-rename" "b" "XC00-AA005360-AAX-00-TITLE" "XC00-PN001234-aax-00-TITLE")

 

If  the statement is NOT true then will NOT invoke the call for _rename then procede to check the next item on the name list: 

 

(if (and (tblsearch "BLOCK" "XC00-PN001234-aax-00-TITLE") <--- true
(findfile (strcat "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC00-PN001234-aax-00-TITLE" ".dwg")))<-- file exists

 

Then

(command "-xref" "p" "XC00-PN001234-aax-00-TITLE" "E:\\_ACAD Customization\\_example job set\\C-Civil\\X-Xref\\XC00-PN001234-aax-00-TITLE")

 

ALL NAMES are assigned to these variables at each loop

 

(setq renblk (car blks) <-- old and new block name
repathxr (Cadr blks)) <- xref name and new path

 

So if any of the statement evaluates to nil , the program will proceed to run the next element of the list

 

Got it?

 

see attached file [you may need to add more block names and Xref paths to your liking] 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost