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

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 705
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.
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega

MP

  • Seagull
  • Posts: 16985
  • brevity != aggression
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 | About

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 705
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
Marc'Antonio Alessi http://alessi.xoom.it//alessi/  Coding manual: http://tinyurl.com/zza7ega