Jump to content

Code help please for tidy up pre drawing close


JADT

Recommended Posts

I would like some help with maybe a lisp that would help with the following please.

I would like to run a lisp on a drawing that would:-

 

switch to paperspace

lock all viewports

zoom all layouts to extents

make first layout current - the layout however will have been renamed so no longer original default name...

save

 

i will probably make a tool button for this on a palette so i can just click.

Link to comment
Share on other sites

There are many examples of LISP for this. Could you not find one with a search?

 

You probably won't find one that does exactly what you want. But at least you will have a base to work from and with a little modification you should be good to go.

Link to comment
Share on other sites

Try this

; 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)
;(vla-put-mspace this_dwg :vlax-false)
(COMMAND "pSPACE")
     (command "zoom" "C" "400,277" 600)
)
(setvar "ctab" curtab)
(princ)

 

and this one needs patching for goto 1st as part of above. Note Model is 0 1st layout is 1

(defun C:goto ( / alllayouts lay num)
(setq num (getint "\nEnter tab number"))
(setq alllayouts (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))))
(SETQ LAYNUM 0)
(vlax-for x alllayouts
(Setq laynum (+ 1 laynum))
) ;total number of layouts
(if (> num laynum)
(setq num (- laynum 1))
)
(vlax-for lay alllayouts
(if (= num (vla-get-taborder lay))
 (setvar "ctab" (vla-get-name lay))
) ; if
) ; for
) ; defun
(C:goto)

Link to comment
Share on other sites

Perhaps this help .

 

(defun c:test (/ lay ent)
 (vl-load-com)
 (vlax-for lay
       (vla-get-layouts
         (vla-get-activedocument (vlax-get-acad-object))
       )
   (if    (eq :vlax-false (vla-get-modeltype lay))
     (vlax-for    ent (vla-get-block lay)
   (if (= (vla-get-objectname ent) "AcDbViewport")
     (vla-put-displaylocked ent :vlax-true)
   )
     )
   )
 )
 (lze)
)

(defun lze (/ AC OT )
 (setq    ot (getvar 'CTAB)
   ac (vlax-get-acad-object)
 )
 (foreach l (layoutlist)
   (setvar 'CTAB l)
   (vla-ZoomExtents ac)
 )
 (setvar 'CTAB ot)
(lsw) 
)
 (defun lsw(/ aDoc)
 (setvar "TILEMODE" 1);thanks for ASMI on [url="http://www.cadtutor.net/forum/showthread.php?25524-Activating-any-layout-with-lisp&p=163492&viewfull=1#post163492"]cadtutor.net[/url]
 (vlax-for l(vla-get-Layouts
          (setq aDoc(vla-get-ActiveDocument
        (vlax-get-acad-object))))
   (getkword
     (strcat"\nPress Spacebar for layout '"
          (vla-get-Name l) "' "))
   (vla-put-ActiveLayout aDoc l)
   ); end vlax-for
 (princ "\n<<< No more layouts, goodbuy... >>> ")
(command "qsave")
 (princ)
 ); end of c:lsw

Edited by mostafa badran
improve code
Link to comment
Share on other sites

Big Al & mostafa, thank you. that seems to do what I require. Not sure about the spacebar input instruction to invoke layout 1 if the lisp could just default to layout 1 without any required input that would be great.

 

I will try and work through your lisps and learn what each part is doing and try to modify myself that's how i'm teaching myself at the moment...

Link to comment
Share on other sites

Here is my version:

(defun c:tidy ( / app doc idx lay lst sel )
   (setq app (vlax-get-acad-object)
         doc (vla-get-activedocument app)
   )
   (vlax-for obj (vla-get-layouts doc)
       (if (= :vlax-false (vla-get-modeltype obj))
           (progn
               (setq lay (vla-get-name obj)
                     lst (cons (cons (vla-get-taborder obj) lay) lst)
               )
               (setvar 'ctab lay)
               (vla-put-mspace doc :vlax-false)
               (setq sel (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 lay))))
               (repeat (setq idx (1- (sslength sel)))
                   (vla-put-displaylocked (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) :vlax-true)
               )
               (vla-zoomextents app)
           )
       )
   )
   (setvar 'ctab (cdr (assoc 1 lst)))
   (princ)
)
(vl-load-com) (princ)

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