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

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 991
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #60 on: September 12, 2017, 04:24:27 PM »
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.
I used this method for over 10 years with VBA 32bit up to 64bit VBA arrival to avoid writing scripts and having a much better error control.

Comando: (setq
(_>       *AcadApp* (vlax-get-Acad-Object)
(_>       *AcDrwgs* (vla-get-documents      *AcadApp*)
(_>       *AcAcDwg* (vla-get-ActiveDocument *AcadApp*)
(_> )
#<VLA-OBJECT IAcadDocument 000000002d8363c8>  <<< ACTIVE DOCUMENT

Comando: (setq DwgNum (vlax-get-property *AcDrwgs* 'Count))
1

Comando: (vla-item *AcDrwgs* (1- DwgNum))
#<VLA-OBJECT IAcadDocument 000000002d8363c8>  <<< ACTIVE DOCUMENT

When I open with:
Comando: (setq NewDoc (vl-catch-all-apply 'vlax-invoke-method (list *AcDrwgs* 'Open "Z:/Temp/Test/Dwg1.dwg" :vlax-false)))
#<VLA-OBJECT IAcadDocument 00000000329439c8>

then it does not give the active document:

Comando: (setq DwgNum (vlax-get-property *AcDrwgs* 'Count))
2

Comando: (vla-item *AcDrwgs* (1- DwgNum))
#<VLA-OBJECT IAcadDocument 00000000329439c8> <<< NEW DOCUMENT

It works in 2013 not in 2017.

%%
(vl-cmdf "_.VBASTMT" "documents.item(documents.count-1).sendcommand \"(load \"\"ExeTest\"\")\n\"")

Run in the NEW DOCUMENT and when closed return back to the ACTIVE DOCUMENT.
With this I can do anything in the new document and in case of error the control returns to the starting document.

MP

  • Seagull
  • Posts: 17446
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #61 on: September 12, 2017, 06:18:05 PM »
Marc my friend -- my brief observations with 2015 suggest documents.item(documents.count-1) is not reliable -- in particular if one has cycled to other drawings via [ctrl][tab] or [ctrl][shift][tab] or via the pull-down drawing selector after initial file loading --  whereas activedocument has proven consistent and reliable -- and why I shared in the hopes of helping you.

Did you try --

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


I don't have 2017 at my disposal so I cannot test.

Off to check out some yoga pants ...
« Last Edit: September 12, 2017, 07:34:50 PM by MP »
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 991
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #62 on: September 13, 2017, 04:15:54 PM »
Marc my friend -- my brief observations with 2015 suggest documents.item(documents.count-1) is not reliable -- in particular if one has cycled to other drawings via [ctrl][tab] or [ctrl][shift][tab] or via the pull-down drawing selector after initial file loading --  whereas activedocument has proven consistent and reliable -- and why I shared in the hopes of helping you.

Did you try --

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


I don't have 2017 at my disposal so I cannot test.

Off to check out some yoga pants ...
Michael, -- Command: activedocument.sendcommand "(load ""ExeTest"") " load ExeTest.lsp in the starting document not in the new document just opened (that is what I want to do) maybe this can explain:
Code: [Select]
; TVBA.lsp
(defun C:TVBA (/ NewDoc FlsLst FilPtr)
  (vl-load-com) (defun errdump (s) (vl-bt) (princ)) (setq *error* errdump)
  (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 (vla-get-documents (vlax-get-acad-object)) 'Open ForElm :vlax-false)))
      )
      (progn
        (alert (vl-catch-all-error-message NewDoc))
        (setq NewDoc nil)
      )
      (progn
        (setq FilPtr (open "Z:/Temp/Test/Report.txt" "a"))
        (princ "\nActive document BEFORE of VBASTMT: " FilPtr) (princ (vla-get-ActiveDocument (vlax-get-acad-object)) FilPtr)
        (close FilPtr)
        (vl-cmdf "_.VBASTMT" "documents.item(documents.count-1).sendcommand \"(load \"\"ExeTest\"\")\n\"")
        (setq FilPtr (open "Z:/Temp/Test/Report.txt" "a"))
        (princ "\nActive document AFTER  of VBASTMT: " FilPtr)
        (princ (vla-get-ActiveDocument (vlax-get-acad-object)) FilPtr)
        (princ "\n\n\n" FilPtr)
        (close FilPtr)
      )
    )
  );foreach
)
Code: [Select]
; ExeTest.lsp
(defun ExeTest (DwgNam / FilPtr)
  (setvar 'CMDECHO 0)
  (setq FilPtr (open "Z:/Temp/Test/Report.txt" "a"))
  (setq #BS (getvar "Millisecs"))
  (repeat 10
    (command "_.POINT" "_NONE" "0.0,0.0,0.0") (command "_.ERASE" "_LAST" "")
    (command "_.LAYER" "_OFF" "*" "" "") (command "_.LAYER" "_ON" "*" "")
  )
  (princ (strcat "\n" DwgNam "  Elapsed: "(rtos (* 0.001 (- (getvar "Millisecs") #BS)))) FilPtr)
  (setvar 'CMDECHO 1)
  (princ "\nActive document INSIDE of VBASTMT: " FilPtr) (prin1 (vla-get-ActiveDocument (vlax-get-acad-object)) FilPtr)
  (close FilPtr)
  (vl-cmdf "_.CLOSE" "_Y")
)
(ExeTest (getvar "DWGNAME"))

After load TVBA.lsp the command: TVBA make this report:
Code: [Select]
Active document BEFORE of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>
Dwg1.dwg  Elapsed: 0.078
Active document INSIDE of VBASTMT: #<VLA-OBJECT IAcadDocument 0000000032ef0298>
Active document AFTER  of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>



Active document BEFORE of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>
Dwg2.dwg  Elapsed: 0.093
Active document INSIDE of VBASTMT: #<VLA-OBJECT IAcadDocument 0000000032ef0bb8>
Active document AFTER  of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>



Active document BEFORE of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>
Dwg3.dwg  Elapsed: 0.078
Active document INSIDE of VBASTMT: #<VLA-OBJECT IAcadDocument 0000000032ef0728>
Active document AFTER  of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>



Active document BEFORE of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>
Dwg4.dwg  Elapsed: 0.078
Active document INSIDE of VBASTMT: #<VLA-OBJECT IAcadDocument 0000000032ef0298>
Active document AFTER  of VBASTMT: #<VLA-OBJECT IAcadDocument 000000002cc78568>

The Active document change only inside VBASTMT, when (vl-cmdf "_.CLOSE" "_Y") the Active document return the starting document.

In AutoCAD 2017 (and I think >=2014, see link below) I get the error: *** INTERNAL ERROR: VL namespace mismatch
maybe is due to this:
http://through-the-interface.typepad.com/through_the_interface/2014/03/autocad-2015-calling-commands.html

MP

  • Seagull
  • Posts: 17446
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #63 on: February 05, 2018, 11:31:49 AM »
This "challenge" can also be addressed using the RunAll utility.

For example:

Code: [Select]
(defun-q c:ZEAL ( / app doc restore )

    ;;  Zoom Extents All Layouts

    (vl-load-com)
   
    (setq
        app     (vlax-get-acad-object)
        doc     (vla-get-activedocument app)
        restore (vla-get-activelayout doc)
    )
   
    (vlax-for layout (vla-get-layouts doc)
        (vla-put-activelayout doc layout)
        (if (or (eq 1 (getvar 'tilemode)) (eq 1 (getvar 'cvport)))
            (vla-zoomextents app)
            (progn
                (vla-put-mspace doc :vlax-false)
                (vla-zoomextents app)
                (vla-put-mspace doc :vlax-true)
            )
        )
    )
   
    (vla-put-activelayout doc restore)
   
    (princ)

)

(vl-propagate 'c:ZEAL)

(_RunAll "(c:ZEAL)")


Normally I'd just add c:ZEAL's (defun) definition to my standard library and thus it would already be available. I used the defun-q option to demonstrate the fast propagation technique.

FWIW, Cheers.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MSTG007

  • Water Moccasin
  • Posts: 2397
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #64 on: February 05, 2018, 01:01:14 PM »
I was thinking something like this . . . with you routine... ;)
Autodesk Infrastructure Design Suite 2019

MP

  • Seagull
  • Posts: 17446
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #65 on: February 05, 2018, 01:21:23 PM »
I was thinking something like this . . . with you routine... ;)

\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 991
  • Marco
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #66 on: February 06, 2018, 02:32:20 AM »
I hope mine is a coherent question, is it possible to use your function _RunAll on many files without opening them all together? For example, to perform operations on hundreds of files and avoid the use of scripts?

MSTG007

  • Water Moccasin
  • Posts: 2397
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #67 on: February 06, 2018, 09:39:58 AM »
My lazy cheat at the moment is to use the acaddoc.lsp. Its just a pain to remember to change it back to default once I am done running what ever commands I need. (I kinda use it as a script) lol
Autodesk Infrastructure Design Suite 2019

MP

  • Seagull
  • Posts: 17446
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #68 on: February 06, 2018, 10:18:54 AM »
I hope mine is a coherent question, is it possible to use your function _RunAll on many files without opening them all together? For example, to perform operations on hundreds of files and avoid the use of scripts?

The intention of _RunAll is to run an arbitrary command string in every drawing currently open.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MSTG007

  • Water Moccasin
  • Posts: 2397
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #69 on: February 06, 2018, 10:21:20 AM »
I do have a question. In the Express Tools \ File Tools \ Save All Drawings - Close All Drawings.

How do those lisp routines work? They go through all open drawings... Just curious.
Autodesk Infrastructure Design Suite 2019

MP

  • Seagull
  • Posts: 17446
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #70 on: February 06, 2018, 11:24:49 AM »
They iterate the docs collection and then invoke the close or save method as applicable for the desired action and their state etc.
\|// Set goal. Experiment tirelessly until
|Oo| practice has become expertise.  Loop.
|- | LinkedIn | Dropbox

MSTG007

  • Water Moccasin
  • Posts: 2397
  • I can't remeber what I already asked! I need help!
Re: Zoom Extend All Layouts in All Open Drawings?
« Reply #71 on: February 06, 2018, 11:28:30 AM »
It basically does what yours does except with a heck of a lot more capability.

If I have a dozen drawings open... (Similar to the express tools)

regen all drawings
set imageframe to 0 in all drawings
etc...

watchout when are able to record what you want to do to all opened drawings lol.

again... pretty sweet stuff here.
Autodesk Infrastructure Design Suite 2019