;Zoom Extents *ALL* layouts
(defun c:ZoomExtentsAllLayouts (/ acad acdoc aclay)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
aclay (vla-get-ActiveLayout acdoc)
)
(vlax-for layout (vla-get-Layouts acdoc)
(vla-put-ActiveLayout acdoc layout)
(vla-ZoomExtents acad)
)
(vla-put-ActiveLayout acdoc aclay)
(alert "Zoom Extents has been applied to all layouts!")
(princ)
)
(vl-load-com)
(DEFUN C:ZOOMANDSAVE ( / DOCS COUNT I TEMP_ELE)
(SETQ DOCS (VLAX-GET-PROPERTY (VLAX-GET-ACAD-OBJECT) "DOCUMENTS"))
(SETQ COUNT (VLAX-GET-PROPERTY DOCS "COUNT"))
(SETQ I 0)
(SETQ TEMP_ELE NIL)
(WHILE (< I COUNT)
(SETQ TEMP_ELE (VLAX-INVOKE-METHOD DOCS "ITEM" I))
(VLA-POSTCOMMAND TEMP_ELE "ZOOM E ")
(VLAX-INVOKE-METHOD TEMP_ELE "SAVE")
(SETQ I (+ I 1))
)
)
Code below for all layouts, current drawings only:Code: [Select];Zoom Extents *ALL* layouts
(defun c:ZoomExtentsAllLayouts (/ acad acdoc aclay)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
aclay (vla-get-ActiveLayout acdoc)
)
(vlax-for layout (vla-get-Layouts acdoc)
(vla-put-ActiveLayout acdoc layout)
(vla-ZoomExtents acad)
)
(vla-put-ActiveLayout acdoc aclay)
(alert "Zoom Extents has been applied to all layouts!")
(princ)
)
(vl-load-com)
;Zoom Extents *ALL* Document and layouts
(defun c:ZoomExtAllDocsLayouts (/ acad acdoc aclay doc lout)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
)
(vlax-for doc (vla-get-documents acad)
(vla-put-ActiveDocument acad doc)
(setq aclay (vla-get-ActiveLayout doc))
(vlax-for lout (vla-get-Layouts doc)
(vla-put-ActiveLayout doc lout)
(vla-ZoomExtents acad)
)
(vla-put-ActiveLayout doc aclay)
)
(vla-put-ActiveDocument acad acdoc)
(vla-Regen acdoc AcActiveViewport)
(alert "Zoom Extents has been applied to all Documents and layouts!")
(princ)
)
(vl-load-com)
(vla-put-ActiveLayout doc aclay)
the code works but does not return the documents to the starting layout. I have not figured out why it errors on this yet. Anyone else have an idea?
(vla-regen acdoc)
I have changed it to:(vla-regen acdoc acactiveviewport)
(vla-put-ActiveLayout doc aclay)
Code below for all layouts, current drawings only:Code: [Select];Zoom Extents *ALL* layouts
(defun c:ZoomExtentsAllLayouts (/ acad acdoc aclay)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
aclay (vla-get-ActiveLayout acdoc)
)
(vlax-for layout (vla-get-Layouts acdoc)
(vla-put-ActiveLayout acdoc layout)
(vla-ZoomExtents acad)
)
(vla-put-ActiveLayout acdoc aclay)
(alert "Zoom Extents has been applied to all layouts!")
(princ)
)
(vl-load-com)
Thanks Dommy2Hotty..
is it possible to use one more vlax-for loop for all open drawings? This is just a quick thought comes in my mind don't know realistic or not.
@PKENEWELL:
If I test your code in BricsCAD this line causes an error:Code: [Select](vla-regen acdoc)
I have changed it to:Code: [Select](vla-regen acdoc acactiveviewport)
BricsCAD does not have an issue with:Code: [Select](vla-put-ActiveLayout doc aclay)
The following ALMOST works:Code: [Select];Zoom Extents *ALL* Document and layouts
(defun c:ZoomExtAllDocsLayouts (/ acad acdoc aclay doc lout)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
)
(vlax-for doc (vla-get-documents acad)
(vla-put-ActiveDocument acad doc)
(setq aclay (vla-get-ActiveLayout doc))
(vlax-for lout (vla-get-Layouts doc)
(vla-put-ActiveLayout doc lout)
(vla-ZoomExtents acad)
)
(vla-put-ActiveLayout doc aclay)
)
(vla-put-ActiveDocument acad acdoc)
(vla-Regen acdoc AcActiveViewport)
(alert "Zoom Extents has been applied to all Documents and layouts!")
(princ)
)
(vl-load-com)
if you comment out this lineCode: [Select](vla-put-ActiveLayout doc aclay)
the code works but does not return the documents to the starting layout. I have not figured out why it errors on this yet. Anyone else have an idea?
This might be another topic but within Express Tools under Files. You can save all opened drawings in the current session. How does that work compared to what we are trying to do with this type of routine?
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.
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
...
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.
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
(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
)
(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)
)
Command: ZALL
Initializing VBA System...
Syntax Error
(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)
)
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")
"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."
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...
... Using vbastmt on 64 bit might I have this problem?
https://www.theswamp.org/index.php?topic=43869.msg491387#msg491387
Still getting the darn Syntax error.
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)
(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
)
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"
...
If restore.Name <> ThisDrawing.Name Then restore.Activate
However this does not seem to be doing the job to return focus to the calling document.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.
... PS -- there's more than one way to ... load code into vbe ...
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! :)
If restore.Active = False Then
restore.Activate
End If
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
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
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 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.
Good job MP
... sadly only the computer completely understands what you said (wrote)! :lol:
...are there any advantages in Visual Basic, in order to the functionality, over LISP?
Brutal test on old PC with A2017+VBA:... 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:
(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)
)
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"
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.
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 wanted to see is such technique 'worthy'. :)
(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: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
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:The problem is not due to this (the function only run once).
(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.
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"
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) ...
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 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.
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.
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.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:
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 ...
; 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
)
; 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"))
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>
(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)
)
I was thinking something like this . . . with you routine... ;)
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?