karrotbear Posted September 19, 2016 Share Posted September 19, 2016 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 19, 2016 Share Posted September 19, 2016 (edited) 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 September 19, 2016 by BIGAL Quote Link to comment Share on other sites More sharing options...
karrotbear Posted September 19, 2016 Author Share Posted September 19, 2016 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. Quote Link to comment Share on other sites More sharing options...
abra-CAD-abra Posted September 19, 2016 Share Posted September 19, 2016 Try Changing: (setvar "ctab" (atof x)) To: (setvar "ctab" (itoa x)) Quote Link to comment Share on other sites More sharing options...
karrotbear Posted September 19, 2016 Author Share Posted September 19, 2016 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 Quote Link to comment Share on other sites More sharing options...
karrotbear Posted September 19, 2016 Author Share Posted September 19, 2016 (edited) 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 September 19, 2016 by karrotbear Quote Link to comment Share on other sites More sharing options...
abra-CAD-abra Posted September 19, 2016 Share Posted September 19, 2016 Cool! Change: (defun xreflay ( / x fname) to (defun c:xreflay ( / x fname) and delete (xreflay) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 19, 2016 Share Posted September 19, 2016 Thanks Abr-CAD-abra Sorry about that ITOA I type stuff off the top of my head, could not test at time of writing. Quote Link to comment Share on other sites More sharing options...
abra-CAD-abra Posted September 19, 2016 Share Posted September 19, 2016 Thanks Abr-CAD-abra Sorry about that ITOA I type stuff off the top of my head, could not test at time of writing. All good BIGAL Quote Link to comment Share on other sites More sharing options...
karrotbear Posted September 19, 2016 Author Share Posted September 19, 2016 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! Quote Link to comment Share on other sites More sharing options...
abra-CAD-abra Posted September 20, 2016 Share Posted September 20, 2016 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 20, 2016 Share Posted September 20, 2016 You can buy books for Kindle/Pc very cheap I bought 4, a set about Vlisp for about $8 each. Quote Link to comment Share on other sites More sharing options...
karrotbear Posted September 20, 2016 Author Share Posted September 20, 2016 Sweet as, I'll have a look at both sources Thanks again guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.