Author Topic: Zoom Extend All Layouts in All Open Drawings?  (Read 25955 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 #45 on: September 07, 2017, 12:55:53 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

That did It! Now works as expected. Thanks! LOL - I don't even know if the OP is paying attention anymore.  :-D
"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 #46 on: September 07, 2017, 01:00:42 PM »
I think this is great! Think of all the things you can do now you have this piece of the code squared away.

User has a bunch of drawings open: (They may want to:) i.e.

zoom extents in all layout tabs and save

purge all the opened drawings

possibly perform page setups


Again this is me, brain storming around. All in all. pretty cool.

Civil3D 2020

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #47 on: September 07, 2017, 05:25:40 PM »
Good job MP,
fluent on several languages, sadly only the computer completely understands what you said (wrote)! :lol:

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.

That sounds intriguing!  :-o
But (as a VBA newbie) it makes me wonder are there any advantages in Visual Basic, in order to the functionality, over LISP?
Like I was going thru some VBA tutorials and I saw how much easier is to create dialogs (forms), access objects with properties'n'methods (esp the scripting objects) - but the same could be achieved with pure LISP (although very hard, but still doable).
So is there anything that can be done in VBA and not in LISP? (finally found a VBA'n'LISP guy to ask!)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #48 on: September 07, 2017, 08:09:13 PM »
Good job MP

Merci. :)

... sadly only the computer completely understands what you said (wrote)! :lol:

So very not true, lol.

...are there any advantages in Visual Basic, in order to the functionality, over LISP?

Well there's the ability to iterate over all drawings open in the editor and perform a zoom extents on every layout. :-P


















Sorry, couldn't resist -- way tired and not capable of much more than humor at present.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #49 on: September 08, 2017, 11:01:32 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:
Brutal test on old PC with A2017+VBA:
Code: [Select]
(defun BenchVBA (Times)
  (setvar 'CMDECHO 0)
  (setq #BS (getvar "Millisecs"))
  (repeat Times (command "_.POINT" "_NONE" "0.0,0.0,0.0"))
  (print (strcat "Elapsed: "(rtos (* 0.001 (- (getvar "Millisecs") #BS)))))
  (setvar 'CMDECHO 1)
  (princ)
)
Code: [Select]
Command: (progn
(_> (BenchVBA 10000)
(_> (repeat 10 (BenchVBA 10000))
(_> )
"Elapsed: 16.5"
"Elapsed: 16.406"
"Elapsed: 16.437"
"Elapsed: 16.437"
"Elapsed: 16.437"
"Elapsed: 16.5"
"Elapsed: 16.532"
"Elapsed: 16.485"
Code: [Select]
With VBA loaded:
Command: (progn
(_> (BenchVBA 10000)
(_> (command "_.VBASTMT" "ThisDrawing.SetVariable \"UserS1\", \"Test\"")
(_> (repeat 10 (BenchVBA 10000))
(_> )
"Elapsed: 16.609" _.VBASTMT
Expression: ThisDrawing.SetVariable "UserS1", "Test"
Command:
"Elapsed: 21.625"
"Elapsed: 21.641"
"Elapsed: 21.594"
"Elapsed: 21.578"
"Elapsed: 22.14"
"Elapsed: 21.735"
"Elapsed: 21.687"
"Elapsed: 21.64"
"Elapsed: 21.579"
"Elapsed: 22"
speed reduction is appreciable but NOT progressive (not depending by the number of commands performed) as with VBA6.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #50 on: September 08, 2017, 03:25:02 PM »
Sorry, couldn't resist -- way tired and not capable of much more than humor at present.

No worries, your contribution to this forum is alot anyways.
I just liked the idea you mentioned, about creating and running temporary .dvb files thru lisp, so with my previous question I wanted to see is such technique 'worthy'. :)
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #51 on: September 08, 2017, 11:00:56 PM »
No worries, your contribution to this forum is alot anyways.

Awesome comment -- thank you -- I will be worthy it some day.

I wanted to see is such technique 'worthy'. :)

Any automation that takes minutes to produce that increases efficiency, accuracy ... or reduces waste, errors ... ad infinitum is worthy.

And then some.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

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 #52 on: September 08, 2017, 11:09:11 PM »
Watch out... we might drain you with all our wacko ideas
Civil3D 2020

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #53 on: September 08, 2017, 11:19:58 PM »
I've observed a wide spectrum of ideas during my tenure here and few if any qualify as wacky. My only frustration is having nominal time to play and thus having to cherry pick one of every hundred or so challenges that are interesting yet can be solved quickly -- and of some benefit to the swamp community, me or those I serve -- ideally all three.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #54 on: September 10, 2017, 05:45:19 AM »
I apologize if I insist but i am interested in knowing if AutoCAD + VB7 has solved the problems that had AutoCAD + VB6 / 64bit.
The second question is why in A2017 I get an error: INTERNAL ERROR: VL namespace mismatch?
Code: [Select]
(defun C:TVBA (/ NewDoc FlsLst)
  (vl-load-com)
  (or *AcadApp* (setq *AcadApp* (vlax-get-acad-object)))
  (or *AcAcDwg* (setq *AcAcDwg* (vla-get-ActiveDocument *AcadApp*)))
  (or *AcDrwgs* (setq *AcDrwgs* (vla-get-documents *AcadApp*)))
  (setq FlsLst
   '("Z:/Temp/Test/Dwg1.dwg"
     "Z:/Temp/Test/Dwg2.dwg"
     "Z:/Temp/Test/Dwg3.dwg"
     "Z:/Temp/Test/Dwg4.dwg"
    )
  )
  (close (open "Z:/Temp/Test/Report.txt" "w"))
  (foreach ForElm FlsLst ; Drawing list
    (if
      (vl-catch-all-error-p
         (setq NewDoc (vl-catch-all-apply 'vlax-invoke-method (list *AcDrwgs* 'Open ForElm :vlax-false)))
      )
      (progn
        (alert (vl-catch-all-error-message NewDoc))
        (setq NewDoc nil)
      )
      (vl-cmdf "_.VBASTMT" "documents.item(documents.count-1).sendcommand \"(load \"\"ExeTest\"\")\n\"")
    )
  );foreach
)


; File to load and run every dwg > ExeTest.lsp
(defun ExeTest (DwgNam / FilPtr)
  (setvar 'CMDECHO 0)
  (setq FilPtr (open "Z:/Temp/Test/Report.txt" "a"))
  (setq #BS (getvar "Millisecs"))
  (repeat 10000
    (command "_.POINT" "_NONE" "0.0,0.0,0.0") (command "_.ERASE" "_LAST" "")
    (command "_.LAYER" "_OFF" "*" "" "") (command "_.LAYER" "_ON" "*" "")
  )
  (write-line (strcat DwgNam "  Elapsed: "(rtos (* 0.001 (- (getvar "Millisecs") #BS)))) FilPtr)
  (setvar 'CMDECHO 1)
  (close FilPtr)
  (if (= (getvar "DBMOD") 0) (vl-cmdf "_.CLOSE") (vl-cmdf "_.CLOSE" "_Y"))
)
(ExeTest (getvar "DWGNAME"))

Results:
Code: [Select]
A2013
(ExeTest (getvar "DWGNAME")) > Drawing1.dwg  Elapsed: 8.86 > No VBA

(c:tvba):
Dwg1.dwg  Elapsed: 92.032
Dwg2.dwg  Elapsed: 97.109
Dwg3.dwg  Elapsed: 92.187
Dwg4.dwg  Elapsed: 89.125



A2017
(ExeTest (getvar "DWGNAME")) > Drawing1.dwg  Elapsed: 8.688 > No VBA

with A2017
Command:_.VBASTMT Initializing VBA System...
Expression: documents.item(documents.count-1).sendcommand "(load ""ExeTest"")
"
Command: "\n*** INTERNAL ERROR: VL namespace mismatch\n"" type Y to reset: "y

Manual test
(vl-cmdf "_.VBASTMT" "documents.item(documents.count-1).sendcommand \"(load \"\"ExeTest\"\")\n\""):
Dwg1.dwg  Elapsed: 8.921

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #55 on: September 10, 2017, 09:35:34 AM »
Sorry I missed your posts Marc and I'm just heading off to work. That said, and it's a wild assed blurry eyed haven't had coffee yet guess, try:

(setq
    *AcadApp* (vlax-get-acad-object)
    *AcAcDwg* (vla-get-ActiveDocument *AcadApp*)
    *AcDrwgs* (vla-get-documents *AcadApp*)
)


(I'm guessing) There's nominal speed gains to be realized by trying to leverage the values between calls as globals and it may be the source of the problem. As for the other question I cannot answer at present as I've only access to AutoCAD 2012 and 2015 currently.  Thanks for your valued investigations in this thread. Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #56 on: September 12, 2017, 08:03:06 AM »
Sorry I missed your posts Marc and I'm just heading off to work. That said, and it's a wild assed blurry eyed haven't had coffee yet guess, try:

(setq
    *AcadApp* (vlax-get-acad-object)
    *AcAcDwg* (vla-get-ActiveDocument *AcadApp*)
    *AcDrwgs* (vla-get-documents *AcadApp*)
)


(I'm guessing) There's nominal speed gains to be realized by trying to leverage the values between calls as globals and it may be the source of the problem. As for the other question I cannot answer at present as I've only access to AutoCAD 2012 and 2015 currently.  Thanks for your valued investigations in this thread. Cheers.
The problem is not due to this (the function only run once).

VBA 7 is for >= A2014 see:
https://knowledge.autodesk.com/support/autocad/learn-explore/caas/sfdcarticles/sfdcarticles/Unable-to-download-VBA-Enabler-for-previous-versions-of-AutoCAD.html

Try this simple test (A2013 and VBA 6):

Code: [Select]
Comando: (progn
(_>   (setvar 'CMDECHO 0)
(_>   (setq #BS (getvar "Millisecs"))
(_>   (repeat 10000
((_>     (command "_.POINT" "_NONE" "0.0,0.0,0.0") (command "_.ERASE" "_LAST" "")
((_>     (command "_.LAYER" "_OFF" "*" "" "") (command "_.LAYER" "_ON" "*" "")
((_>   )
(_>   (print (strcat "Elapsed: "(rtos (* 0.001 (- (getvar "Millisecs") #BS)))))
(_>   (setvar 'CMDECHO 1)
(_>   (princ)
(_> )

"Elapsed: 9.88"

Comando: VBASTMT
Inizializzazione del sistema VBA in corso...
Espressione: *Annulla*

Comando: (progn
(_>   (setvar 'CMDECHO 0)
(_>   (setq #BS (getvar "Millisecs"))
(_>   (repeat 10000
((_>     (command "_.POINT" "_NONE" "0.0,0.0,0.0") (command "_.ERASE" "_LAST" "")
((_>     (command "_.LAYER" "_OFF" "*" "" "") (command "_.LAYER" "_ON" "*" "")
((_>   )
(_>   (print (strcat "Elapsed: "(rtos (* 0.001 (- (getvar "Millisecs") #BS)))))
(_>   (setvar 'CMDECHO 1)
(_>   (princ)
(_> )

"Elapsed: 20.69"

With VBA 7 the difference after the load of VBA is lower but I can not use:
(vl-cmdf "_.VBASTMT" "documents.item(documents.count-1).sendcommand \"(load \"\"ExeTest\"\")\n\"")
due to error:
Command:_.VBASTMT Initializing VBA System...
Expression: documents.item(documents.count-1).sendcommand "(load ""ExeTest"")
"
Command: "\n*** INTERNAL ERROR: VL namespace mismatch\n"" type Y to reset: "y


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #57 on: September 12, 2017, 08:41:58 AM »
That performance hit is unfortunate if it cannot be resolved. Guess it means one has to be judicious in VB's use -- sometimes the performance hit is will be worth it when VB hosted automation yields big benefits, dumping the session when the tasks are complete.

I believe you're getting the VL namespace mismatch error because you're trying to load lisp into a document that is not active.

Said another way, there's no guarantee documents.item(documents.count-1) will return the active document.

Have you tried:

Command: _.VBASTMT
Command: activedocument.sendcommand "(load ""ExeTest"") "


Cheers.
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 #58 on: September 12, 2017, 09:04:20 AM »
On the performance hit -- if you unload all the vba projects (this can be done programmatically) performance returns to normal even tho the vba editor is still alive. Cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #59 on: September 12, 2017, 04:06:18 PM »
On the performance hit -- if you unload all the vba projects (this can be done programmatically) performance returns to normal even tho the vba editor is still alive. Cheers.
Maybe I can not explain well (my english is not very good) ...
There is no VBA project loaded only: Command:_.VBASTMT Initializing VBA System...