Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding a command after a lisp in a macro

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
ryled
547 Views, 5 Replies

Adding a command after a lisp in a macro

^C^C^C_AI_SELALL;-OVERKILL;IGNORE;NONE;TOLERANCE;0.000001;P;NO;T;NO;E;NO;A;YES;DONE;^C^C^C_AUDIT;YES;^C^C^C(if (null c:laz)(load"f:/CUSTOM PATH/LAZ - Lock and Zoom for Save"))(c:laz);ON;^C^C^C_QSAVE;

 I am attempting to run the above macro.  However I am having a hard time running a second command after a lisp routine is entered.  When this command is ran it ignores the QSave.  I am unsure as to why.  Is it impossible to run an additional command in a macro after running a lisp routine?  If not how would I go about completing this. 

 

I would like to make this the new save button to decrease some drawing errors.  If anyone has suggestions Im all ears.  Thank you!

5 REPLIES 5
Message 2 of 6
dmfrazier
in reply to: ryled

Try running each piece of this on the command line.

I think you will find that there is an error at "(c:laz)". (I think this LISP would be run as "(laz)", but I can't be sure without the code.)

 

Another thing to try is doing the entire thing in LISP.

Message 3 of 6
ryled
in reply to: dmfrazier

(DEFUN C:LAZ ()
 (PROMPT "\n*LOCK VEIWPORTS(all)* ")
 (INITGET 1 "On oFf")
 (SETQ VPSM (GETKWORD "\nViewport lock mode[On/oFf]: "))
 (IF (OR (= VPSM "O") (= VPSM "o") (= VPSM "ON") (= VPSM "on") (= VPSM "On")) (SETQ LS "ON"))
 (IF (OR (= VPSM "F") (= VPSM "f") (= VPSM "OFF") (= VPSM "off") (= VPSM "oFf")) (SETQ LS "OFF"))
 (SETQ TMV (GETVAR "TILEMODE"))
 (SETVAR "TILEMODE" 1)
 (SETQ VPS (SSGET "X" '((0 . "VIEWPORT")) ))
 (SETVAR "TILEMODE" TMV)
 (SETQ VPSL (SSLENGTH VPS))
 (SETQ CT (- VPSL 1))
 (SETQ LP 1)
 (WHILE LP
  (SETQ VPEN (SSNAME VPS CT))
  (SETQ VPENL (ENTGET VPEN))
  (SETQ VPENLN (CDR (ASSOC 410 VPENL)))
  (COMMAND "LAYOUT" "SET" VPENLN)
  (COMMAND "MVIEW" "LOCK" LS "ALL" "")
  (SETQ CT (- CT 1))
  (IF (< CT 0) (SETQ LP NIL))
 );END LP
(setvar 'CTAB "Model");;
 (COMMAND "REGENALL")
; goes through all layout tabs and zooms all
; By Alan H june 2011
(vl-load-com)
 (command "_.pspace")
 (setq curtab (getvar "Ctab"))
 (setq this_dwg (vlax-get-acad-object))
 (foreach d (layoutlist)
      (setvar "CTAB" d)
      (command "_.pspace")
      (vla-ZoomExtents this_dwg)
 )
 (setvar "ctab" curtab)
 (PRINC)
);END LAZ

 I meant to include the lisp as an attachment.  There is the code for 'LAZ' (Lock & Zoom)

 

I have ran this macro seperately with success and figured copying it, and pasting it into a larger macro, while including the command 'On' after to turn viewport locking on would work.

^C^C^C(if (null c:laz)(load"f:/Stalworth Policy/Projects/0000 - Standard Folder Setup/Drawings&Calcs/STALWORTH Shop Drawings/CAD/Standard Shapes/Custom Menu Drive/Lisp Routines/LAZ - Lock and Zoom for Save"))(c:laz)

 

 

I would attempt to do the entire thing in a lisp however I have no real LISP experience.  I've been trying to pick things up here and there and am enrolled in a couple programming classes to learn but atm I do not know.

 

The LAZ lisp is a combo of two other lisps 'LVP' and 'ZEA'.  Perhaps I put them together wrong, although it seems to work.

Message 4 of 6
hmsilva
in reply to: ryled

As dmfrazier already have stated, if your are testing for the existence of a laz command with (null c:laz) you should call the command with laz...

change
(if (null c:laz)(load"f:/CUSTOM PATH/LAZ - Lock and Zoom for Save"))(c:laz);ON
to
(if (null c:laz)(load"f:/CUSTOM PATH/LAZ - Lock and Zoom for Save"));laz;ON;

 

And for the laz command, maybe something like this will be sufficient to lock the viewports and to zoom entents all layouts, and qsave...

 

(defun c:laz ( / acad_)
  (vl-load-com)
  (setq acad_ (vlax-get-acad-object))
  (vlax-for layt (vla-get-layouts (vla-get-activedocument acad_))
    (if	(eq :vlax-false (vla-get-modeltype layt))
      (vlax-for	obj (vla-get-block layt)
	(if (= (vla-get-objectname obj) "AcDbViewport")
	  (vlax-put obj 'displaylocked :vlax-true)
	)
      )
    )
  )
  (foreach d (layoutlist)
    (setvar 'CTAB d)
    (if	(>= (getvar 'CVPORT) 2)
      (command "_.pspace")
    )
    (vla-ZoomExtents acad_)
  )
  (setvar 'CTAB "Model")
  (vl-cmdf "_.qsave")
  (princ)
)

 

Using this code you don't need the

(if (null c:laz)(load"f:/CUSTOM PATH/LAZ - Lock and Zoom for Save"));laz;ON;
Just

(if (null c:laz)(load"f:/CUSTOM PATH/LAZ - Lock and Zoom for Save"));laz;

 

Hope that helps

Henrique

EESignature

Message 5 of 6
ryled
in reply to: hmsilva

Henrique and dmfrazier thank you for the help.

 

I wasn't  quite clear what was meant by calling the command with just laz.  I was under the impression from my last semester teacher that when checking for a command the final part (c:laz) would tell autocad to name this command with the keyboard shortcut laz.  And if it was not loaded then calling the command with just laz would not execute.  This could be wrong though as he just gave us a copy of a line of code and said this is how to run a lisp in a macro.

 

That seemed to be the problem when I attempted the macro with the original lisp, (the one with ^C^C^CQSave at the end) as when it got to the 'laz' part of the macro it came up "nil" and the command stopped without executing the macro or the lisp routine.  The same "nil" came up when I put in the lisp routine that Henrique gave me by putting "laz" and not (c:laz) after loading the lisp.  It did work and function as I wanted it too with (c:laz) at the end so thank you! 

 

Perhaps it is the fact I'm working on AutoCAD 2012, I'm not sure.  However here is the final maco with the lisp attached in case anyone would like to use it.

[SAVE]^C^C^C_AI_SELALL;-OVERKILL;IGNORE;NONE;TOLERANCE;0.000001;P;NO;T;NO;E;NO;A;YES;DONE;^C^C^C_AUDIT;YES;^C^C^C(if (null c:laz)(load"f:/Stalworth Policy/Projects/0000 - Standard Folder Setup/Drawings&Calcs/STALWORTH Shop Drawings/CAD/Standard Shapes/Custom Menu Drive/Lisp Routines/LAZ - Lock and Zoom for Save"))(c:laz);

 I basically was going for a simplistic risk free overkill command that would delete only duplicates, audit the drawing, then go through and make sure all the layouts are zoomed to extents and viewports locked before saving.

 

Thanks again you guys.

 

Message 6 of 6
hmsilva
in reply to: ryled

You're welcome, ryled
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost