Results 1 to 8 of 8

Thread: Combine two LISP routines into one...

  1. #1
    Member
    Join Date
    2015-11
    Posts
    16
    Login to Give a bone
    0

    Default Combine two LISP routines into one...

    Hi there, first post for me. I am fairly green when it comes to lisp routines. I mean, I know what they do, and how to execute them, but beyond that I am grasping.

    My question, I have two routines that I like to execute before I close a drawing; one is to lock all vports, and the other zoom extents all viewports. I have been trying to combine the two into one routine but it is giving me much grief. Any help would be appreciated.

    Also, to take that one step further, it would be great if these routines could both simply be executed upon closing of the drawing. It would seem that this must be possible...I just haven't the knowledge.

    Lisp to lock vports:
    Code:
    ;;Program by Dann Brower 2006
    (defun C:vpl (/ kw)
      (setq kw "LOCK")
      (vplocks kw)
      (princ)
    )
    (defun C:vpu (/ kw)
      (setq kw "UNLOCK")
      (vplocks kw)
      (princ)
    )
    (defun vpLocks (kw / kval doc adoc lao cnt inc cvprt blk pw)
      (vl-load-com)
      (if (= kw "LOCK")
    	(setq kval :vlax-true)
    	(if (= kw "UNLOCK")
    	  (setq kval :vlax-false)
    	)
      )
      (setq doc  (vlax-get-object "AutoCad.Application")
     adoc (vla-get-ActiveDocument doc)
     lao  (vla-get-Layouts adoc)
     cnt  (vla-get-Count lao)
     inc  0
      )
      (repeat cnt
    	(setq cvprt (vla-Item lao inc)
       inc (+ inc 1)
       blk (vla-get-Block cvprt)
    	)
    	(vlax-for itm blk
    	  (if
     (vlax-property-available-p itm 'DisplayLocked)
      (progn
    	(vla-put-DisplayLocked itm kval)
    	(vla-update itm)
      )
    	  )
    	)
      )
      (princ)
    )
    Lisp to zoom all vports:
    Code:
    (defun zoom_all_layouts (/ lay layouts *acad* *doc*)
      (vl-load-com)
      (setq *acad* (vlax-get-acad-object)
     *doc* (vla-get-activedocument *acad*)
     layouts (vla-get-layouts *doc*)
      )
      (vlax-for lay layouts ; step through layouts 
    	(vla-put-activelayout *doc* lay) ; activate layout 
    	(if (= (vla-get-activespace *doc*) 0) ; If in paperspace 
    	  (if (= (vla-get-mspace *doc*) :vlax-true) ; in mspace viewport 
     (vla-put-mspace *doc* :vlax-false) ; inactivate vp 
    	  ) ; endif 
    	) ;endif 
    	(vla-zoomextents *acad*)
      )
    )
    (defun c:zal ()
      (zoom_all_layouts)
    )
    Cheers,
    Billy

    [ Moderator Action = ON ] What are [ CODE ] tags... [ Moderator Action = OFF ]
    Last edited by Mike.Perry; 2006-10-13 at 04:58 AM. Reason: [CODE] tags added.

  2. #2
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Combine two LISP routines into one...

    just add this code use the command mycolse to lock and zoom

    Code:
     
    (defun c:myclose()
    (vplocks "LOCK")
    (zoom_all_layouts)
    )

  3. #3
    Member
    Join Date
    2015-11
    Posts
    16
    Login to Give a bone
    0

    Default Re: Combine two LISP routines into one...

    Quote Originally Posted by jwanstaett
    just add this code use the command mycolse to lock and zoom

    Code:
     
    (defun c:myclose()
    (vplocks "LOCK")
    (zoom_all_layouts)
    )
    So, do I combine the 2 routines into one, (ie. cut the text from one and paste it at the begininng of the other) and then add that text at the beginning?

  4. #4
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Combine two LISP routines into one...

    Hi Billy,

    As jwanstaett has written it, when you type myclose at the command line, the function c:myclose will call the vplocks function passing "LOCK" as the argument, then executing the zoom_all_layouts function when that is complete.

    Each of the functions will execute fine as long as they are loaded regardles of what file they are in. If they are in separate files, you may want to combine them in the same file just so its easy to keep track of, but it's not required. Just add the code for c:myclose to one of the files and load it (or them, if in separate files), then type myclose.

    HTH, post back if I've confused you.

  5. #5
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Combine two LISP routines into one...

    Quote Originally Posted by thestanger
    So, do I combine the 2 routines into one, (ie. cut the text from one and paste it at the begininng of the other) and then add that text at the beginning?
    No, actually you create a third program that use the other functions, if they already are loaded as global
    Code:
    (defun MyProgram ( In_Lock / )
      (zoom_all_layouts) ; that first run the function zoom_all_layouts
      (vpLocks In_Lock ) ; and the run the function vpLocks with the Lock/Unlock In_Lock   input argument
      (princ)
    )
    usage
    Command: (MyProgram "LOCK" )
    or
    Command: (MyProgram "UNLOCK" )

    if the functions vpLocks and zoom_all_layouts is not loaded as global
    you have to copy and paste/replace the separate function code in to MyProgram inside the parenthesis.

    : ) Happy Computing !

    kennet
    Last edited by kennet.sjoberg; 2006-10-13 at 06:13 AM.

  6. #6
    Member
    Join Date
    2015-11
    Posts
    16
    Login to Give a bone
    0

    Default Re: Combine two LISP routines into one...

    Hey guys, thanks a ton for the help! I have set up the first 2 routines to load globally, then I created a 3rd routine to run the routines upon the click of a button. Now all I need to do is a simple button click and voila, vports locked and everything zoom extents.

    The only other option I'd love to add would be to zoom to .95x so as to leave a bit of a border. I have a routine that does this, but it's only for the particular layout your in, not every layout in the drawing. I attempted to incorporate this into the original zoom all extents routine, but I wasn't successful.

    Here is the zoom to .95x routine:

    Code:
    (Defun C:ZEE () 
       (command "Zoom" "E" "Zoom" "0.95x") 
       (princ) 
    )
    [ Moderator Action = ON ] What are [ CODE ] tags... [ Moderator Action = OFF ]

    Thanks again for the help.
    Last edited by Opie; 2006-10-13 at 02:18 PM. Reason: [CODE] tags added, see Moderator Action

  7. #7
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: Combine two LISP routines into one...

    Code:
    ;;  Zoom Extents For All Layout Tabs
    ;;  Closes any active viewports first
    (defun zoom_all_layouts    (/ lay layouts *acad* *doc* )
      (vl-load-com)
      (setq  *acad*   (vlax-get-acad-object)
             *doc*    (vla-get-activedocument *acad*)
             layouts  (vla-get-layouts *doc*)
      )
      (vlax-for lay   layouts ; step through layouts 
        (vla-put-activelayout *doc* lay) ; activate layout 
        (if (= (vla-get-activespace *doc*) 0) ; If in paperspace 
          (if (= (vla-get-mspace *doc*) :vlax-true); in mspace viewport 
             (vla-put-mspace *doc* :vlax-false) ; inactivate vp 
          ) ; endif 
        ) ;endif 
        (vla-zoomextents *acad*)
        (vl-cmdf "._zoom" ".95x") ; <----<<<<
      )
    )

  8. #8
    Member
    Join Date
    2015-11
    Posts
    16
    Login to Give a bone
    0

    Default Re: Combine two LISP routines into one...

    Quote Originally Posted by CAB2k
    Code:
    ;;  Zoom Extents For All Layout Tabs
    ;;  Closes any active viewports first
    (defun zoom_all_layouts    (/ lay layouts *acad* *doc* )
      (vl-load-com)
      (setq  *acad*   (vlax-get-acad-object)
             *doc*    (vla-get-activedocument *acad*)
             layouts  (vla-get-layouts *doc*)
      )
      (vlax-for lay   layouts ; step through layouts 
        (vla-put-activelayout *doc* lay) ; activate layout 
        (if (= (vla-get-activespace *doc*) 0) ; If in paperspace 
          (if (= (vla-get-mspace *doc*) :vlax-true); in mspace viewport 
             (vla-put-mspace *doc* :vlax-false) ; inactivate vp 
          ) ; endif 
        ) ;endif 
        (vla-zoomextents *acad*)
        (vl-cmdf "._zoom" ".95x") ; <----<<<<
      )
    )
    Works like a charm...thanks!

    You guys are too good.

Similar Threads

  1. how do you call other lisp routines with lisp?
    By moises.y969653 in forum AutoLISP
    Replies: 1
    Last Post: 2011-02-06, 01:01 PM
  2. Lisp Routines
    By Shadrak in forum AutoCAD Customization
    Replies: 4
    Last Post: 2009-10-08, 01:32 AM
  3. Lisp Routines
    By jsnow in forum AutoCAD General
    Replies: 2
    Last Post: 2009-04-16, 05:07 AM
  4. combine 2 lisp into one
    By CISCO in forum AutoLISP
    Replies: 4
    Last Post: 2008-02-20, 12:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •