Jump to content

Scrip question for toggling through viewports


MiGo

Recommended Posts

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 :D . 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?

Link to comment
Share on other sites

  • Replies 34
  • Created
  • Last Reply

Top Posters In This Topic

  • MiGo

    17

  • Lee Mac

    15

  • NBC

    2

  • Organic

    1

Top Posters In This Topic

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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")

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

)

Link to comment
Share on other sites

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.

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