Visual LISP, AutoLISP and General Customization

Reply
Active Member
camardi
Posts: 6
Registered: ‎10-10-2012
Message 1 of 5 (166 Views)

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

166 Views, 4 Replies
03-21-2013 03:54 PM

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 :smileyhappy:

Mentor
mid-awe
Posts: 1,199
Registered: ‎12-08-2004
Message 2 of 5 (163 Views)

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

03-21-2013 04:07 PM 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.

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 3 of 5 (139 Views)

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

03-21-2013 08:17 PM 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

Active Member
camardi
Posts: 6
Registered: ‎10-10-2012
Message 4 of 5 (132 Views)

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

03-21-2013 08:53 PM 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

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 5 of 5 (128 Views)

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

03-21-2013 09:13 PM 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] 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community