Jump to content

Lisp that will select layer and draw VP and go back to previous layer


matthewrussell

Recommended Posts

Hey people,

 

I have been having trouble making a lisp routine that will draw a viewport on a set layer and then once thats done will automatically go back to the previous layer that i had selected. I couldnt get it to work so I came here.

 

This is what i had

 

;Draw Viewport In Viewport Layer 
(defun c:mvp
(setq layerset (getvar "clayer"))
(setvar "clayer" "0-VPort")
(command "mview")
(setvar "clayer" layerset)
(princ)
) ;defun

 

Cheers

Link to comment
Share on other sites

This is a LISP that I made for another guy on here, it may help you with yours:

 

(defun c:vp (/ oldlay)
   (setq oldlay (getvar "clayer"))
   (setvar "cmdecho" 0)
   (if (/= (getvar "ctab") "Model")
       (progn
           (if (not (tblsearch "LAYER" "vport"))
           (command "-layer" "M" "vport" "C" "49" "vport" "P" "N" "vport" "")
           (setvar "clayer" "vport")
           ) ; end if
           (command "-vports"
               pause
               pause
           ) ; end command
           (setvar "clayer" oldlay)
       ) ; end progn
       (alert "Viewport Cannot be Drawn in Model Space.")
   ) ; end if
   (setvar "cmdecho" 1)
   (princ)
) ; end defun

Link to comment
Share on other sites

  • 1 month later...

Hey,

 

That is great ... thanx!

 

Allthough I wanted to combine your lisp with inserting an Xref with layer Xref after the Vport had been made.

 

When I do it it pauses after making vport, the program enters mspace and then:

Command:

Invalid option keyword.

BUT try to run this once, and when the layers are made, XREF and VPORT, the next time you run the lisp it works ... what is wrong?

 

And thats is ..

 

Here is the code..:

 

(defun c:AIX:XREFINRITDEF (/ oldlay)
   (setq oldlay (getvar "clayer"))
   (setvar "cmdecho" 0)
   (if (/= (getvar "ctab") "Model")
       (progn
           (if (not (tblsearch "LAYER" "vport"))
           (command "._layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "")
           (setvar "clayer" "vport")
           ) ; end if
  (prompt "Skapar ett nytt Mview-Fönster...")
           (command "-vports"
               pause
               pause
           ) ; end command
           (setvar "clayer" oldlay)
       ) ; end progn
       (alert "Mview-fönsret Kan Ej skapas i Modellen!!")
   ) ; end if
   (setvar "cmdecho" 1)
 ;;;INSERT XREF
(command "._mspace")
(command "_.ucs" "w")
 (setq oldlay (getvar "clayer"))
   (setvar "cmdecho" 0)

 (if (tblsearch "layer" "XREF")
   (command "_layer" "s" "XREF" "")
   (command "_layer"    "m"   "XREF"
     "c"    "7"   ""        "d"
     "ExternReferens"   "XREF"
     "lo"    "XREF"        ""
    )
 )
(command "._XAttach")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
 (setvar "clayer" oldlay)
(setvar "cmdecho" 1)
 (command "_.ucs" "p")
 (command "._pspace")

   (princ)
) ; end defun

Link to comment
Share on other sites

You encounter a problem when trying to delete a layer (i assume that is what you are trying to do.) this cannot be done via the "-layer" command.

 

I have tidied the code up a bit also - this should work (although untested!):

 

(defun c:AIX:XREFINRITDEF (/ varlist oldvars)
 (setq varlist (list "CMDECHO" "CLAYER" "CTAB")
   oldvars (mapcar 'getvar varlist))
 (setvar "cmdecho" 0)
 (if (/= (getvar "ctab") "Model")
   (progn
     (if (not (tblsearch "LAYER" "vport"))
   (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "")
   (setvar "clayer" "vport"))
     (prompt "Skapar ett nytt Mview-Fönster...")
     (command "-vports" pause pause))
   (alert "Mview-fönsret Kan Ej skapas i Modellen!!"))
 
;;;INSERT XREF
 
 (setvar "ctab" "MODEL")
 (command "_.ucs" "w")
 (if (not (tblsearch "LAYER" "XREF"))
   (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "")
   (setvar "clayer" "XREF"))
 (command "._XAttach")
 (while (> (getvar "CMDACTIVE") 0) (command pause))
 (command "_.ucs" "P")
 (mapcar 'setvar varlist oldvars)
 (princ))

Link to comment
Share on other sites

Great!!! It works fine. Thank you very much Sir.

 

Is it possible to develop this lisp a little bit to make a statement to choose to create vport or not?

Sometimes it happens that you already have vports set so you do not need to create ones. So I want to make a user to choose from to create vport or not to.

 

Like that:

 

  (setq answer
     (dos_msgbox "New VPORT..."Do you want to create New VPORT?..." 4 3))
    (if answer ( = 6) (command "-vports" pause pause)))
   )

 

I tried to place it in a good spot but couldnt manage and the lisp just inserts an xref and skipping this dos_msg box...

 

 

Thanx for help!

Link to comment
Share on other sites

I've never used a "dos_msgbox", but this should accomplish the same thing:

 

(defun c:AIX:XREFINRITDEF (/ varlist oldvars ans)
 (setq    varlist    (list "CMDECHO" "CLAYER" "CTAB")
   oldvars    (mapcar 'getvar varlist))
 (setvar "cmdecho" 0)
 (initget "Yes No")
 (setq ans (getkword "\nCreate a Viewport? [Yes/No] <Yes> : "))
 (if (/= ans "No")
   (progn
     (if (/= (getvar "ctab") "Model")
   (progn
     (if (not (tblsearch "LAYER" "vport"))
       (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "")
       (setvar "clayer" "vport"))
     (prompt "Skapar ett nytt Mview-Fönster...")
     (command "-vports" pause pause))
   (alert "Mview-fönsret Kan Ej skapas i Modellen!!"))))

;;;INSERT XREF

 (setvar "ctab" "MODEL")
 (command "_.ucs" "w")
 (if (not (tblsearch "LAYER" "XREF"))
   (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "")
   (setvar "clayer" "XREF"))
 (command "._XAttach")
 (while (> (getvar "CMDACTIVE") 0) (command pause))
 (command "_.ucs" "P")
 (mapcar 'setvar varlist oldvars)
 (princ))

Link to comment
Share on other sites

Thanx Sir!

It exactly does the thing I wanted...

There is only one prob ... If I use the lisp in model.dwg it do not cancel the whole script which it did before.

If I am in a model-drawing it should cancel the whole thing ..

 

:)

 

Sorry I harass you but it got lost on the way :)

 

Many thanx!!

Link to comment
Share on other sites

Would you like it to cancel the XREF when you are in model space?

 

Only reason I ask is that the LISP is programmed to switch to model space in order to insert the XREF anyway - so it wouldn't matter whether or not the user is in model space to start with.

Link to comment
Share on other sites

If that indeed is what you are after:

 

(defun c:AIX:XREFINRITDEF (/ varlist oldvars ans)
 (setq    varlist    (list "CMDECHO" "CLAYER" "CTAB")
   oldvars    (mapcar 'getvar varlist))
 (setvar "cmdecho" 0)
 (if (/= (getvar "ctab") "Model")
   (progn
     (initget "Yes No")
     (setq ans (getkword "\nCreate a Viewport? [Yes/No] <Yes> : "))
     (if (/= ans "No")
   (progn
     (if (not (tblsearch "LAYER" "vport"))
       (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "")
       (setvar "clayer" "vport"))
     (prompt "Skapar ett nytt Mview-Fönster...")
     (command "-vports" pause pause)))
     (setvar "ctab" "MODEL")
     (command "_.ucs" "w")
     (if (not (tblsearch "LAYER" "XREF"))
   (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "")
   (setvar "clayer" "XREF"))
     (command "._XAttach")
     (while (> (getvar "CMDACTIVE") 0) (command pause))
     (command "_.ucs" "P"))
   (alert "Mview-fönsret Kan Ej skapas i Modellen!!"))
 (mapcar 'setvar varlist oldvars)
 (princ))

Link to comment
Share on other sites

Would you like it to cancel the XREF when you are in model space?

 

Only reason I ask is that the LISP is programmed to switch to model space in order to insert the XREF anyway - so it wouldn't matter whether or not the user is in model space to start with.

 

Exactly! That works fine when I am in a Layout.dwg-drawing!!

 

But when I am in model-drawing.dwg it does:

 

1. I call the command

2. It tells me (alert "Mview-fönsret Kan Ej skapas i Modellen!!")) which means "VPORT-window cannot be created in model-drawing.dwg".

 

 

The lisp works fine in Layout-drawing but it should terminate after the alert "Viewport Cannot be Drawn in Model Space" as you did the first time when I am in model-drawing.dwg.

 

That is why I find it very useful. I have two lisps. One that insert xrefs in modelspace and one in layout-drawing.dwg.

Link to comment
Share on other sites

In the LISP posted above - the XREF will only be inserted if you are initially in Layout Space.

 

Although, please note that the XREF is being inserted into model space, and the value of "ctab" is being re-instated at the end of the LISP. (to switch back to layout-space.)

Link to comment
Share on other sites

In the LISP posted above - the XREF will only be inserted if you are initially in Layout Space.

 

Although, please note that the XREF is being inserted into model space, and the value of "ctab" is being re-instated at the end of the LISP. (to switch back to layout-space.)

 

Hehe... take a look at this code ...

 

(defun C:AIX:XREFINRITDEF (/ varlist oldvars ans)
 (setq    varlist    (list "CMDECHO" "CLAYER" "CTAB")
   oldvars    (mapcar 'getvar varlist))
 (setvar "cmdecho" 0)
 (initget "Yes No")
 (setq ans (getkword "\nSkapa ett Nytt VPORT?? [JA/Nej] <JA> : "))
 (if (/= ans "Nej")
   (progn
     (if (/= (getvar "ctab") "Model")
   (progn
     (if (not (tblsearch "LAYER" "vport"))
       (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "")
       (setvar "clayer" "vport"))
     (prompt "Skapar ett nytt Mview-Fönster...")
     (command "-vports" pause pause))
   (alert "Mview-fönsret Kan Ej skapas i Modellen!!"))))
;;;INSERT XREF
 (command "_mspace")
 (command "_.ucs" "w")
 (if (not (tblsearch "LAYER" "XREF"))
   (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "")
   (setvar "clayer" "XREF"))
 (command "._XAttach")
 (while (> (getvar "CMDACTIVE") 0) (command pause))
 (command "_.ucs" "P")
(command "_pspace")
 (mapcar 'setvar varlist oldvars)
 (princ)
 );;; END DEFUN

 

When in modelTAB the lisp executes anyways even after alert.

I changed while in layouTAB to :

(command "_mspace")

then after commands beeing done and xrefs chosen

(command "_pspace")

...

 

So, problem is that the script contiunes when Im in modelTAB which it shouldnt. It should only work in LayoutTAB.

 

Thanx Sir! :) I hope Im not to much trouble

Link to comment
Share on other sites

THANX!!

 

All work now

 

Here is with the dos_msgbox and DosLib...

I think its better :)

 

Thank you for helping me out... Truly apprciate it!!

 

defun c:AIX:XREFINRITDEF (/ varlist oldvars ans)
 (setq    varlist    (list "CMDECHO" "CLAYER" "CTAB")
   oldvars    (mapcar 'getvar varlist))
 (setvar "cmdecho" 0)
 (if (/= (getvar "ctab") "Model")
   (progn
   (setq
     svar (dos_msgbox
     "Create VPORT?"
     "New Window"
     4
     3
   )
   )
   (IF (= svar 6)
   (progn
     (if (not (tblsearch "LAYER" "vport"))
       (command "-layer" "M" "vport" "C" "7" "vport" "P" "N" "vport" "")
       (setvar "clayer" "vport"))
     (prompt "Skapar ett nytt Mview-Fönster...")
     (command "-vports" pause pause)))
     (setvar "ctab" "MODEL")
     (command "_.ucs" "w")
     (if (not (tblsearch "LAYER" "XREF"))
   (command "-layer" "M" "XREF" "C" "7" "XREF" "LO" "XREF" "")
   (setvar "clayer" "XREF"))
     (command "._XAttach")
     (while (> (getvar "CMDACTIVE") 0) (command pause))
     (command "_.ucs" "P"))
   (alert "VPORT cant be created in modelspace.!!"))
 (mapcar 'setvar varlist oldvars)
 (princ))

 

Thanx SIR!!

Link to comment
Share on other sites

No Probs - happy to help :)

 

Although I do have one question however:

 

How do you make the dos_msgbox work? Obviously it is not a recognised LISP function, so how does it operate?

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