Author Topic: Zoom Extend All Layouts in All Open Drawings?  (Read 25952 times)

0 Members and 1 Guest are viewing this topic.

PKENEWELL

  • Bull Frog
  • Posts: 309
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #15 on: September 06, 2017, 10:08:44 AM »
I guess my question is, what programming language is used with the express tool work? Is it a .NET thing? I guess something in the way the mechanics work.

I am not sure what those commands are programmed in, but my point is that (vla-save) DOES work fine in Visual Lisp. However, The Zoom Extents via (Vla-ZoomExtents) and other methods do not seems to work.

BTW - I attempted to compile the program to a separate namespace VLX file and it still did not work.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #16 on: September 06, 2017, 10:18:36 AM »
I wonder what other vla commands work similar to the vla-save. Like you said the vla zoomextents does not work.
Civil3D 2020

ChrisCarlson

  • Guest
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #17 on: September 06, 2017, 10:19:14 AM »
Correct, as written previously, you are only zoom-extenting the current tab or layout. You need to process each layout separately.

Lee had written this up a few years ago

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/zoom-extents-for-all-tabs/m-p/3226104/highlight/true#M300276

Code - Auto/Visual Lisp: [Select]
  1. (defun c:zea ( / acapp acdoc aclay )
  2.     (setq acapp (vlax-get-acad-object)
  3.           acdoc (vla-get-activedocument acapp)
  4.           aclay (vla-get-activelayout acdoc)
  5.     )
  6.     (vlax-for layout (vla-get-layouts acdoc)
  7.         (vla-put-activelayout acdoc layout)
  8.         (if (eq acpaperspace (vla-get-activespace acdoc))
  9.             (vla-put-mspace acdoc :vlax-false)
  10.         )
  11.         (vla-zoomextents acapp)
  12.     )
  13.     (vla-put-activelayout acdoc aclay)
  14.     (princ)
  15. )

PKENEWELL

  • Bull Frog
  • Posts: 309
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #18 on: September 06, 2017, 10:25:55 AM »
Correct, as written previously, you are only zoom-extenting the current tab or layout. You need to process each layout separately.

Lee had written this up a few years ago

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/zoom-extents-for-all-tabs/m-p/3226104/highlight/true#M300276
...

@Master_Shake

Yes - I understand this. If you look at my original code and Marko's, we were attempting to do this in ALL open drawings, not just in the currently active one. The (vla-ZoomExtents) works correctly in all the layouts of the currently active drawing. but does not work when switching to another open drawing.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

ChrisCarlson

  • Guest
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #19 on: September 06, 2017, 11:10:43 AM »
Oh, sorry it appears I mis-read.  The zoom function is part of the application object within the document namespace which means the lisp routine is limited to the active document it is ran in.

I had to edit it a few times to try and word it correctly.
« Last Edit: September 06, 2017, 11:19:24 AM by Master_Shake »

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #20 on: September 06, 2017, 11:56:08 AM »
Would a .NET type of application be able to do this?
Civil3D 2020

ChrisCarlson

  • Guest
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #21 on: September 06, 2017, 03:09:41 PM »
.NET should be able to accomplish this, personally I would go with a script routine. Lee's SW is quite powerful.

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #22 on: September 06, 2017, 03:30:14 PM »
I love using Lee's Scriptwriter. The other thing I am kinda leveraging is the acaddoc.lsp. Basically I put the routine I need in there. Save it, then drag all the drawings I need to do this to into AutoCAD.

But I do see how a user could be in several drawings and need to run a routine on all opened dwgs. Weather its a save each dwg or zoom extents, or plot for that matter.
Civil3D 2020

PKENEWELL

  • Bull Frog
  • Posts: 309
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #23 on: September 06, 2017, 05:29:22 PM »
Oh, sorry it appears I mis-read.  The zoom function is part of the application object within the document namespace which means the lisp routine is limited to the active document it is ran in.

I had to edit it a few times to try and word it correctly.

Yep. I had though I could get away with using (vla-SendCommand doc "_zoom _e ") since it directly references the document object. However, it does not work and can make the application unstable. It seems to try to run the command in the calling document no matter what document object is referenced and confuses AutoCAD. I would classify this as a bug as it should send the command to the referenced document object. Perhaps it just creates a namespace conflict however.

FYI - I also tried (vla-ZoomExtents (Vla-Get-Application doc)) and got the same results as (vla-ZoomExtents acd). Though maybe getting the application from the referenced document would make a difference - Nope.
« Last Edit: September 06, 2017, 05:37:47 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #24 on: September 06, 2017, 05:44:08 PM »
Quick and dirty, minimalist, no hand holding code ...

Place this code in a vb module, then save to a dvb file, e.g.  "z:\dvblib\zooms.dvb"

Code: [Select]
Sub ZoomExtentsInAllLayouts( )

    Dim layout  As AcadLayout, _
        restore As AcadLayout
       
    With ThisDrawing
       
        Set restore = .ActiveLayout
           
        For Each layout In .Layouts
            .ActiveLayout = layout
            If 1 = .GetVariable("TILEMODE") Or _
               1 = .GetVariable("CVPORT") Then
                Application.ZoomExtents
            Else
                .MSpace = False
                Application.ZoomExtents
                .MSpace = True
            End If
        Next layout
       
        If restore.Name <> .ActiveLayout.Name Then .ActiveLayout = restore
       
    End With

End Sub

Sub ZoomExtentsInAllDocs( )

    Dim doc     As AcadDocument, _
        restore As AcadDocument
       
    Set restore = ThisDrawing
   
    For Each doc In Documents
        doc.Activate
        Call ZoomExtentsInAllLayouts( )
    Next
   
    restore.Activate

End Sub

Invoke from LISP:

(vla-loaddvb (vlax-get-acad-object) "z:\\dvblib\\zooms.dvb")

(command ".vbastmt" "ZoomExtentsInAllDocs")

*poof*
« Last Edit: September 07, 2017, 10:40:45 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #25 on: September 06, 2017, 11:02:30 PM »
Some quick & dirty helper / wrapper code (edit: updated LoadedDVBs function) ...

Code: [Select]
(defun _LoadedDVBs ( / i pjx pth rst )

    (repeat
        (setq i
            (vlax-get
                (setq pjx
                    (vlax-get
                        (vlax-get (vlax-get-acad-object) 'vbe)
                        'VBProjects
                    )
                )
               'count
            )
        )
        (and
            (setq pth (vl-catch-all-apply 'vlax-get (list (vlax-invoke pjx 'item i) 'filename)))
            (eq 'str (type pth))
            (setq rst (cons pth rst))
        )   
        (setq i (1- i))
    )

    rst

)

And ...

Code: [Select]
(defun C:ZAll ( )

    (if
        (null
            (vl-some
                (function (lambda (s) (eq "ZOOMS" (strcase (vl-filename-base s)))))
                (_LoadedDVBs)
            )
        )
        (vl-catch-all-apply
            'vla-loaddvb
            ;;  mod to suit | replace with findfile algo | yada
            (list (vlax-get-acad-object) "z:\\dvblib\\zooms.dvb")
        )
    )

    (vl-cmdf ".vbastmt" "ZoomExtentsInAllDocs")

    (princ)

)

Cheers.
« Last Edit: September 07, 2017, 08:21:35 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #26 on: September 07, 2017, 01:06:30 AM »
I hope I copied it fine...

It gives me this error :
Code: [Select]
Command: ZALL
Initializing VBA System...
Syntax Error

Here is what I've used :

Code: [Select]
(defun _LoadedDVBs ( / i pjx rst )

    (repeat
        (setq i
            (vlax-get
                (setq pjx
                    (vlax-get
                        (vlax-get (vlax-get-acad-object) 'vbe)
                        'VBProjects
                    )
                )
               'count
            )
        )
        (setq
            rst (cons (vlax-get (vlax-invoke pjx 'item i) 'filename) rst)
            i   (1- i)
        )
    )

    (reverse rst)

)

(defun C:ZAll ( / fn )

    (if
        (null
            (vl-some
                (function (lambda (s) (eq "ZOOMS" (strcase (vl-filename-base s)))))
                (_LoadedDVBs)
            )
        )
        (progn
            (setq fn (open (strcat (getvar 'tempprefix) "zooms.dvb") "w"))
            (write-line "Sub ZoomExtentsInAllLayouts( )" fn)
            (write-line "" fn)
            (write-line "    Dim layout  As AcadLayout, _" fn)
            (write-line "        restore As AcadLayout" fn)
            (write-line "        " fn)
            (write-line "    With ThisDrawing" fn)
            (write-line "        " fn)
            (write-line "        Set restore = .ActiveLayout" fn)
            (write-line "            " fn)
            (write-line "        For Each layout In .Layouts" fn)
            (write-line "            .ActiveLayout = layout" fn)
            (write-line "            If 1 = CInt(.GetVariable(\"TILEMODE\")) Or _" fn)
            (write-line "               1 = CInt(.GetVariable(\"CVPORT\")) Then" fn)
            (write-line "                Application.ZoomExtents" fn)
            (write-line "            Else" fn)
            (write-line "                .MSpace = False" fn)
            (write-line "                Application.ZoomExtents" fn)
            (write-line "                .MSpace = True" fn)
            (write-line "            End If" fn)
            (write-line "        Next layout" fn)
            (write-line "        " fn)
            (write-line "        If restore.Name <> .ActiveLayout.Name Then .ActiveLayout = restore" fn)
            (write-line "        " fn)
            (write-line "    End With" fn)
            (write-line "" fn)
            (write-line "End Sub" fn)
            (write-line "" fn)
            (write-line "Sub ZoomExtentsInAllDocs( )" fn)
            (write-line "" fn)
            (write-line "    Dim doc     As AcadDocument, _" fn)
            (write-line "        restore As AcadDocument" fn)
            (write-line "        " fn)
            (write-line "    Set restore = ThisDrawing" fn)
            (write-line "    " fn)
            (write-line "    For Each doc In Documents" fn)
            (write-line "        doc.Activate" fn)
            (write-line "        Call ZoomExtentsInAllLayouts( )" fn)
            (write-line "    Next" fn)
            (write-line "    " fn)
            (write-line "    If restore.Name <> ThisDrawing.Name Then restore.Activate" fn)
            (write-line "" fn)
            (write-line "End Sub" fn)
            (close fn)
            (vl-catch-all-apply
                'vla-loaddvb
                ;;  mod to suit | replace with findfile algo | yada
                (list (vlax-get-acad-object) (strcat (getvar 'tempprefix) "zooms.dvb"))
            )
            (if (findfile (strcat (getvar 'tempprefix) "zooms.dvb"))
                (vl-file-delete (strcat (getvar 'tempprefix) "zooms.dvb"))
            )
        )
    )

    (vl-cmdf ".vbastmt" "ZoomExtentsInAllDocs")

    (princ)

)

What is wrong, I can't see... Help, please...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #27 on: September 07, 2017, 01:16:20 AM »
That's not how one creates a dvb file.

You need to open the VBA editor (vbaide) -- create a new code module -- add the code I supplied to the new module. Save the project as zooms.dvb ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #28 on: September 07, 2017, 01:24:27 AM »
That said -- I could read in the binary stream from the dvb file I created via my _ReadStream function -- store the data in lisp format -- write out to a dvb file via my _WriteStream function -- then invoke per previous posed code -- ha.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #29 on: September 07, 2017, 01:25:58 AM »
And with that good night folks. :-P
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst