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

0 Members and 1 Guest are viewing this topic.

ribarm

  • Water Moccasin
  • Posts: 1690
  • Marko Ribar, architect
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #30 on: September 07, 2017, 01:28:43 am »
Thanks MP...
It's working now...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

MP

  • Seagull
  • Posts: 17000
  • brevity != aggression
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #31 on: September 07, 2017, 01:31:19 am »
You're most welcome -- thanks for letting me know -- cheers. Zzzzzzzz...
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 736
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #32 on: September 07, 2017, 04:41:56 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.
>> (vl-cmdf ".vbastmt" "ZoomExtentsInAllDocs")
Using vbastmt on 64 bit might I have this problem?
https://www.theswamp.org/index.php?topic=43869.msg491387#msg491387
Code: [Select]
"So if I use VBASTMT in >= 2010 I need to load VBA
(x64VBAServer.exe on 64 bit) and *everything* runs 6-8x slower,
including AutoCAD commands! It is much true particularly if you
must use many commands inside of the Lisp function.
Then I need to close AutoCAD to restore previous speed."
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

MSTG007

  • Water Moccasin
  • Posts: 2065
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #33 on: September 07, 2017, 07:16:09 am »
Marko,
Just curious here, why is your code different than MP's? To me, it looks like you are repeating the dvb code twice.

Still getting the darn Syntax error.

Hopefully I am missing something here. For me to get the "ZALL" routine to work.
1. VBaid
2. Create new module
3. Paste the mode in the module
4. Debug / Compile ACADProject
5. Save out module to Zooms.dvb
6. In AutoCAD, Run "zall"

Works.

When I close out of AutoCAD completely and open a new session. I run the "zall" routine and can not get it to work without doing the above steps.




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...
« Last Edit: September 07, 2017, 07:30:11 am by MSTG007 »
Autodesk Infrastructure Design Suite 2017

MP

  • Seagull
  • Posts: 17000
  • brevity != aggression
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #34 on: September 07, 2017, 07:34:16 am »
... Using vbastmt on 64 bit might I have this problem?
https://www.theswamp.org/index.php?topic=43869.msg491387#msg491387

I'm running 2015 64 bit. Speedy here -- acknowledging one test environment does not make conclusive. Thanks for the heads up. PS -- there's more than one way to skin this cat ... to load code into vbe ... or ... :evil:

Still getting the darn Syntax error.

Define your error handler like this: (defun *error* (x) (vl-bt))

Then execute the code line by line & show us the error message thrown please.

PS: You don't need step 4.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

MSTG007

  • Water Moccasin
  • Posts: 2065
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #35 on: September 07, 2017, 07:40:20 am »
Clean session.

Code: [Select]
Command: zall
Backtrace:
[0.52] (VL-BT)
[1.48] (*ERROR* "ACADProject: Path not found")
[2.43] (_call-err-hook #<SUBR @00000000567d32c8 *ERROR*> "ACADProject: Path not found")
[3.37] (sys-error "ACADProject: Path not found")
:ERROR-BREAK.32 nil
[4.29] (vlax-get #<VLA-OBJECT _VBProject 000000002aaaf148> FILENAME)
[5.23] (_LOADEDDVBS)
[6.19] (C:ZALL)
[7.15] (#<SUBR @00000000568af098 -rts_top->)
[8.12] (#<SUBR @000000003d568700 veval-str-body> "(C:ZALL)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

Autodesk Infrastructure Design Suite 2017

MP

  • Seagull
  • Posts: 17000
  • brevity != aggression
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #36 on: September 07, 2017, 08:11:42 am »
Ah. Found the issue. If the VBIDE has been fired up but a dvb has not been loaded there is an active project but the filename property returns an error. Ez fix.

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

)

Thanks MST.
« Last Edit: September 07, 2017, 08:19:57 am by MP »
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

MSTG007

  • Water Moccasin
  • Posts: 2065
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #37 on: September 07, 2017, 08:24:23 am »
Hey I helped! one more for you. Typically if this is used in a drawing, it will be saved with the drawing. So others who do not have VBA installed or enabled would get the popup enable VBA stuff. Is there a way that once we run the routine the macro can be deleted from the drawing? If not that's ok. Just did not know.
Autodesk Infrastructure Design Suite 2017

MP

  • Seagull
  • Posts: 17000
  • brevity != aggression
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #38 on: September 07, 2017, 08:37:06 am »
There's a way to do everything. :-) unfortunately out of time at present ... off to shower ... then my real job ... maybe tomorrow I can play again ... thanks. :-)
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

MSTG007

  • Water Moccasin
  • Posts: 2065
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #39 on: September 07, 2017, 08:50:41 am »
lol... Have a great day!
Autodesk Infrastructure Design Suite 2017

PKENEWELL

  • Newt
  • Posts: 159
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #40 on: September 07, 2017, 10:06:34 am »
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"
...

Thanks MP! That does work and gives the OP an option using VBA.

The only minor thing I noticed is that - at least on my machine - the sub does not return the active document to the original. I can see that you have code in there for this i.e.
Code: [Select]
If restore.Name <> ThisDrawing.Name Then restore.ActivateHowever this does not seem to be doing the job to return focus to the calling document.

Otherwise - a good simple solution provided the OP has VBA Installed.
"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: 17000
  • brevity != aggression
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #41 on: September 07, 2017, 10:44:50 am »
Thanks MP! That does work and gives the OP an option using VBA.

The only minor thing I noticed is that - at least on my machine - the sub does not return the active document to the original.

Not sure why that's happening and don't have time to investigate. Could just force it, so ...

Replace:
    If restore.Name <> ThisDrawing.Name Then restore.Activate

With:
    restore.Activate

Which I've done in the original post.

Thanks for the feedback & comments, cheers! :)
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

MP

  • Seagull
  • Posts: 17000
  • brevity != aggression
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #42 on: September 07, 2017, 10:48:10 am »
... PS -- there's more than one way to ... load code into vbe ...

confirmed (abuse vbe directly) lol ... when I've time ... :evil:
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About

PKENEWELL

  • Newt
  • Posts: 159
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #43 on: September 07, 2017, 11:28:32 am »
Not sure why that's happening and don't have time to investigate. Could just force it, so ...

Replace:
    If restore.Name <> ThisDrawing.Name Then restore.Activate

With:
    restore.Activate

Which I've done in the original post.

Thanks for the feedback & comments, cheers! :)

No problem MP!

Yes - I tried changing the line you mentioned, and I also tried:

Code: [Select]
    If restore.Active = False Then
        restore.Activate
    End If

Neither seem to work. Still leaves you in the last drawing in the list. In any case - not a big deal since it still does what the OP wants. I just added "doc.Save" and "restore.Save" into your version of the code to match what the OP asked for:

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
        doc.Save
    Next
   
    'If restore.Name <> ThisDrawing.Name Then restore.Activate
    If restore.Active = False Then
        restore.Activate
    End If
   
    restore.Save

End Sub
"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: 17000
  • brevity != aggression
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #44 on: September 07, 2017, 12:36:38 pm »
Perhaps:

Code: [Select]
Sub ZoomExtentsInAllDocs()

    Dim doc     As AcadDocument, _
        restore As AcadDocument
       
    Set restore = Application.ActiveDocument
   
    For Each doc In Documents
        doc.Activate
        Call ZoomExtentsInAllLayouts
    Next
   
    restore.Activate

End Sub
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox | About