MiGo Posted March 24, 2009 Share Posted March 24, 2009 I am new at the whole script writing and haven't done much of anything with Lisp files, and I have a customer that is living in the stone age and they want all of our drawings for many different present and past projects (hundreds of drawings) submitted in model space only and all external references need to be bound exploded then trimmed for the conversion. We have been using the ExportLayout command, but that has been taking a very long time on larger drawings and errors out a lot, so I took on the task of coming up with my own script . I searched the forums last week and found a great help in setting which viewport you were in by setting the variable "cvport". I saw in one thread that they ran an if statement to run through all the viewports until the max number of viewports in the current drawing was met, and now I can't find that thread. So what I need is to know how to get a number for the current number of viewports in the drawing to do a repeat for that number. Anyone? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 Perhaps? [size=2](repeat (getvar "MAXACTVP[/size][font=Arial][size=2]") ...Do something here.... )[/size][/font] Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 24, 2009 Author Share Posted March 24, 2009 That seems to be the maximum allowed viewports in the drawing and will repeat the process that many times. What i'm after is the current number of viewports in the drawing. I wish I could find that thread that had it. If I remember right it was a thread about toggling through viewports and changing a setting. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 Ok, how about: (repeat (1- (length (vports))) ...do something... ) Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 24, 2009 Author Share Posted March 24, 2009 Awsome seems to work on the first drawing. I'll reply if there are any issues. Thanks :D Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 Cool, glad it works for you Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 24, 2009 Author Share Posted March 24, 2009 Ok got an issue. When runing inside the repeat i'm trying to use a lisp called vp-outline, and what this does is draws a border around the current viewport in the form of a polyline. I know to run a command you just do the (command "command here") but this isn't a command and i get an error unknown command. Ideas? Quote Link to comment Share on other sites More sharing options...
Organic Posted March 24, 2009 Share Posted March 24, 2009 I'd tell the customer politely to go jump. Sure do it for future projects, but i would not go back and do it for completed ones. Send them a copy of the files and they can do them themselves if its that important to them. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 Ok got an issue. When runing inside the repeat i'm trying to use a lisp called vp-outline, and what this does is draws a border around the current viewport in the form of a polyline. I know to run a command you just do the (command "command here") but this isn't a command and i get an error unknown command. Ideas? If you are calling a sub-function, (defun myfunct () ... then just put it in brackets, like (myfunct), - with the necessary arguments and it will function correctly. If you need any more help on how to do this, just ask Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 24, 2009 Author Share Posted March 24, 2009 I guess I see what your saying. I am trying to use a command called vp-outline It is a lisp that was loaded on the pc by one of our admins. When using the command it automatically draws the outline of the current viewport your in, and if not in a viewport it asks for you to select one, but my script always has me in a viewport before vp-outline. The other command is Extrim and what that one does is trims all lines crossing your selected object either on the outside or inside as you designate by picking a point, but that one wasn't loaded I have been able to use it before this process. So inside the repeat my line for vp-outline would have to look something like this in order to work? (defun vp-outline (vp-outline)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 I think you may have misunderstood me MiGo, A sub-function is defined like this: (defun myfun (arg1 arg2 / var1 var2) (princ "\nThis is a sub-function.") (princ)) Where, arg1 arg2, are the necessary arguments for the function, and var1, var2, are the localised variables. You can call a sub-function from a main-function, as follows: (defun c:mainfun (/ var1 var2 var3) (myfun arg1 arg2) (princ)) Where var1 var2 & var3 are the localised variables. If the subfunction has takes no arguments, just call it like this: (defun c:mainfun (/ var1 var2 var3) (myfun) (princ)) The above examples are LISPs, in a script you can call a loaded function as follows: (c:myfun) Hope this helps Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 24, 2009 Author Share Posted March 24, 2009 Awsome the third one works great for the vp-outline because there are no variable to give it, but when I have it run the extrim a message comes up saying initializing and asks me to get the variables required. So my next question would be now that the extrim initializes how do i tell CAD via the script what the variables are? the first one should be the object to use for the trim and I want the last one, then on which side of the object to trim on for the inside or outside trimming effect, and I would just use a point out in the middle of nowhere like 10million,0. The repeat section (will be much larger) as i'm currently building it is as follows. (repeat (1- (length (vports))) (c:vp-outline) (command "model") (command "zoom "e") (c:extrim) "last" "10000000,50" (command "tilemode" "0") ) after the extrim it's not taking the info as the object and point so that is where i am hung up. If I manually select the variables then it continues and goes to paper after. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 Hmmm... I'm assuming you are using the EXTRIM as from Express tools? If so, express tools are hard to call through LISPs and scripts, as they override previously invoked functions. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 More info on this: http://www.cadtutor.net/forum/showthread.php?t=5944 Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 24, 2009 Author Share Posted March 24, 2009 I found it on another web blog and someone mentioned what extrim did and it fit perfectly for me trimming my lines that exceed the viewport limitations from old xrefs to the viewport limits. so i can run it in the script just fine as extrim l 10000000,0 but when inside the repeat it says "unknown command" if i put in (command "extrim") Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 I found it on another web blog and someone mentioned what extrim did and it fit perfectly for me trimming my lines that exceed the viewport limitations from old xrefs to the viewport limits. so i can run it in the script just fine as extrim l 10000000,0 but when inside the repeat it says "unknown command" if i put in (command "extrim") Yes, being an Express Tool, ACAD won't recognise it as an in-built command that you can call unforturnately. Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 24, 2009 Author Share Posted March 24, 2009 So why is it that I can use it in the script when not in the repeat loop, but when in it I can't? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 24, 2009 Share Posted March 24, 2009 When you call the Express Tools, after completion, the LISP from which you have called it will not continue to run, but will be terminated - so a repeat will cause problems. You can't call them like this: Command: (command "EXTRIM") EXTRIM Unknown command "EXTRIM". Press F1 for help. Command: nil but like this: (c:extrim) I suppose you could try running it transparently, using an apostrophe: 'extrim Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 26, 2009 Author Share Posted March 26, 2009 Lee I posted a question in a script tutorial forum but I also noticed that you were on and wanted to ask here if you can write an if statement in a script. I'm trying but I get a syntax error, and I'm sure it's due to my limited knowledge. The line is this (if (eq (length (vports)) "1") ...do something here ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 26, 2009 Share Posted March 26, 2009 Length will return an integer, hence: (if (eq (length (vports)) 1) ...do something here ) Also, if you wish to evaluate more than one statement after the IF, then you will need to use "progn" to wrap the statements. 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.