Jump to content

Opening and Inserting Multiple X-refs into Multiple Layout Spaces


karrotbear

Recommended Posts

Okay, first time poster, longtime lurker, super basic lisp skills.

 

Currently working on inserting a whole bunch of xrefs, at a defined point (being the centre of my layout space).

 

The xref names are pretty conventional, i.e X-MC10 XS1.dwg and the next is X-MC10 XS2.dwg..... So each file is just previous+1

 

I have set up my layout names to be 1, 2, 3.....x

 

I have a lisp that essentially does what I want, except I dont want to have to add an additional line into the lisp everytime I need to change something etc.

 

 

This is my lisp (I dont know how to write it all special on the forum)

 

(defun c:run ()

(setvar "ctab" "1")

(COMMAND "-layer" "SET" "0" "")

(COMMAND "-XREF" "OVERLAY" "EXTENDED FILE PATH\\X-MC10 XS1.dwg" "428.561,326.886,0" "1" "1" "0")

(setvar "ctab" "2")

(COMMAND "-XREF" "OVERLAY" "EXTENDED FILE PATH\\X-MC10 XS2.dwg" "428.561,326.886,0" "1" "1" "0")

(setvar "ctab" "3")

(COMMAND "-XREF" "OVERLAY" "EXTENDED FILE PATH\\X-MC10 XS3.dwg" "428.561,326.886,0" "1" "1" "0")

(setvar "ctab" "4")

(COMMAND "-XREF" "OVERLAY" "EXTENDED FILE PATH\\X-MC10 XS4.dwg" "428.561,326.886,0" "1" "1" "0")

(setvar "ctab" "5")

(COMMAND "-XREF" "OVERLAY" "EXTENDED FILE PATH\\X-MC10 XS5.dwg" "428.561,326.886,0" "1" "1" "0")

 

So you get the picture. I just want to write some expression where I can define that there are X Layouts and for the lisp to then xref each corresponding drawing into each corresponding layout.

 

Im sorry if I didnt clarify this properly.

Link to comment
Share on other sites

Take a different approach just read a text file with the list of xref names. Not tested.

(defun xreflay ( / x fname)
(setq oldlay (getvar "clayer"))
[i](setvar "clayer" "0")[/i]

(setq x 1)

(setq fname (open "c:\\temp\\mydwglist.txt" "r"))

(while (setq dwgname (read-line fname))
(setvar "ctab" (itoa x))
[i](COMMAND "-XREF" "OVERLAY" [/i]dwgname "428.561,326.886,0" 1 1 0)
(setq x (+ x 1))
)

(close fname)
(setvar "clayer" layold)
(princ)
)
(xreflay)

 

EXTENDED FILE PATH\\X-MC10 XS1.dwg
EXTENDED FILE PATH\\X-MC10 XS2.dwg
EXTENDED FILE PATH\\X-MC10 XS3.dwg

Edited by BIGAL
Link to comment
Share on other sites

Hey mate,

 

I've copied the code in and tried running it, but it comes back with an "error: bad argument type: stringp 1" but I have no idea what that means.

Link to comment
Share on other sites

Okay, thats taken care of the stringp 1 error. However now its telling me that "\\X-MC10 XS1.dwg" is not a valid file name. *Invalid*; error: Function cancelled"

 

In the error report it tells me that it has exactly the same filepath as my original lisp, but doesnt work with the shorter smarter version :(

Link to comment
Share on other sites

I got it to work!

 

Thanks BIGAL and abra-CAD-abra! Issue was with how my file paths were copied into the text file. I just did a find replace "\\" to "/" and it seems to have done the trick, suddenly all the drawings are good! I've attached the complete code for anyone who needs to do something similar in the future.

 

Quick question though, how do you convert this to a defun c: type lisp? Cause I've tried just chucking c:blahblah in there but it still autoruns on appload and I'd rather have it as a command input type lisp. *edit - I'm a noodle. Deleting (xreflay) from the bottom fixed it*

 

(defun xreflay ( / x fname)
(setq oldlay (getvar "clayer"))
(setvar "clayer" "0")

(setq x 1)

(setq fname (open "G:...\\LISPS AND SCRIPTS\\0_2 XSDRAWINGLIST.txt" "r"))

(while (setq dwgname (read-line fname))
(setvar "ctab" (itoa x))
(COMMAND "-XREF" "OVERLAY" dwgname "428.561,326.886,0" 1 1 0)
(setq x (+ x 1))
)

(close fname)
(setvar "clayer" layold)
(princ)
)
(xreflay)

Edited by karrotbear
Link to comment
Share on other sites

Yeah both of you seriously just made my life easier haha :) By chance, do any of you know any good learning tools (in plain language) for writing lisps? I.e xyz does abc to defg with examples? I never got into programming at school etc so my knowledge of the language itself is very limited. I've been pulling apart other lisps to see how they work but at the end of the day I feel like a 13th century doctor drilling holes in peoples heads!

Link to comment
Share on other sites

Yeah both of you seriously just made my life easier haha :) By chance, do any of you know any good learning tools (in plain language) for writing lisps? I.e xyz does abc to defg with examples? I never got into programming at school etc so my knowledge of the language itself is very limited. I've been pulling apart other lisps to see how they work but at the end of the day I feel like a 13th century doctor drilling holes in peoples heads!

 

 

I suggest starting here:

http://www.afralisp.net/index.php

 

:thumbsup:

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...