TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: domenicomaria on May 18, 2022, 10:46:31 AM

Title: Zoom all in all the open documents
Post by: domenicomaria on May 18, 2022, 10:46:31 AM
Zoom all in all the open documents . . .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ZE   (/ count docs i x-doc-obj )
  2.    (setq docs  (vlax-get-property (vlax-get-acad-object) "documents")
  3.          count (vlax-get-property docs "count")
  4.          i   0
  5.    )
  6.    (while (< i count)
  7.       (setq x-doc-obj (vla-item docs i) )
  8.       (vla-activate x-doc-obj)
  9.       (vla-ZoomAll  x-doc-obj)
  10.       (setq i (+ i 1) )
  11.    )
  12. )

why it does not work ?

is there a solution without scripts and without VBA ?


Title: Re: Zoom all in all the open documents
Post by: JohnK on May 18, 2022, 12:06:39 PM
I don't think so. If I remember right, doing things to all the open docs is very buggy or just doesn't work.

I think the theory was as simple as (but doesn't work):
Code - Auto/Visual Lisp: [Select]
  1. (defun vl-ZoomAllDocs ( / item)
  2.   (vlax-for item (vla-Get-Documents (vlax-get-object "AutoCAD.Application"))
  3.     (vla-Activate item)
  4.    )
  5.  )
Title: Re: Zoom all in all the open documents
Post by: mhupp on May 18, 2022, 12:08:34 PM
This will zoom extents all open drawings and return to the original drawing it was executed in. or it does in BricsCAD.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ZE-ALL (/ org docs item docobjlst drawing)
  2.   (setq org (vla-get-ActiveDocument (vlax-get-Acad-Object))) ;set original drawing
  3.   (vlax-for item docs
  4.     (setq docobjlst (cons item docobjlst))
  5.   )  
  6.   (foreach drawing docobjlst
  7.     (vla-activate  drawing)
  8.   )
  9.   (vla-activate  org) ;return to original drawing
  10.   (princ)
  11. )

--Edit simplified code from JohnK

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ZE-ALL (/ org item)
  2.   (setq org (vla-get-ActiveDocument (vlax-get-Acad-Object))) ;set orignal drawing
  3.     (vla-activate  item)
  4.   )
  5.   (vla-activate  org) ;return to orginal drawing
  6.   (princ)
  7. )
Title: Re: Zoom all in all the open documents
Post by: JohnK on May 18, 2022, 12:48:03 PM
nice entries, mhupp. However doesn't work for me (ACAD 2022) but the user could be using BricsCAD...

NOTE:
I also just tried the following (does not work for me in acad either).
Code - Auto/Visual Lisp: [Select]
  1. (defun vl-ZoomAllDocs ( / item cur)
  2.   (vlax-for item (vla-Get-Documents (vlax-get-object "AutoCAD.Application"))
  3.     (if (= (vla-Get-Active item) :vlax-False)
  4.       (vla-SendCommand item "_.zoom extents ")
  5.       (setq cur item)
  6.     )
  7.   )
  8.   (vla-zoomall (vlax-get-object "AutoCAD.Application"))
  9. )
Title: Re: Zoom all in all the open documents
Post by: domenicomaria on May 18, 2022, 01:41:07 PM
nothing works !
Title: Re: Zoom all in all the open documents
Post by: JohnK on May 18, 2022, 02:16:52 PM
nothing works !
In AutoCAD, correct.
Title: Re: Zoom all in all the open documents
Post by: domenicomaria on May 18, 2022, 02:35:11 PM
nothing works !
In AutoCAD, correct.
:lol:
Title: Re: Zoom all in all the open documents
Post by: mhupp on May 18, 2022, 03:45:18 PM
:lol:

Yeah sorry switched over to bricsCAD over 5-6 years ago and haven't looked back.
If your trying to get the same zoom location between drawings this should work. tho you have to manual switch and type the command again.

Code - Auto/Visual Lisp: [Select]
  1. ;;----------------------------------------------------------------------------;;
  2. ;; Zoom Area Across Multiple Drawings - BIGAL
  3. (defun C:ZAD (/ a)  ;Zoom Across Drawings
  4.   (initget "Yes No")
  5.   (setq a
  6.     (cond
  7.       ((getkword "\nRedefine Zoom Area? [Yes/No]: ")) ( "No")
  8.     )
  9.   )
  10.   (if (= "Yes" a)
  11.     (progn
  12.       (vl-cmdf "_.Zoom" "W" Pause Pause)  ;could change this to zoom extents
  13.       (setq vc (getvar 'viewctr))
  14.       (setq SZ (getvar 'viewsize))
  15.       (vl-propagate 'vc)
  16.       (vl-propagate 'sz)
  17.     )
  18.     (and vc sz)
  19.       (vl-cmdf "_.Zoom" "C" VC SZ)
  20.       (prompt "\nPlease Define Zoom Area")
  21.     )
  22.   )
  23.   (princ)
  24. )

--- updated code Thanks ronjonp
Title: Re: Zoom all in all the open documents
Post by: ronjonp on May 18, 2022, 04:35:12 PM
:lol:

Yeah sorry switched over to bricsCAD over 5-6 years ago and haven't looked back.
If your trying to get the same zoom location between drawings this should work. tho you have to manual switch and type the command again.

Code - Auto/Visual Lisp: [Select]
  1. ;;----------------------------------------------------------------------------;;
  2. ;; Zoom Area Across Multiple Drawings - BIGAL
  3. (defun C:ZAD (/ a)  ;Zoom Across Drawings
  4.   (initget "Yes No")
  5.   (setq a
  6.     (cond
  7.       ((getkword "\nRedefine Zoom Area? [Yes/No]: ")) ( "No")
  8.     )
  9.   )
  10.   (if (= "Yes" a)
  11.     (progn
  12.       (vl-cmdf "_.Zoom" "W" Pause Pause)
  13.       (setq vc (getvar 'viewctr))
  14.       (setq SZ (getvar 'viewsize))
  15.       (vl-propagate 'vc)
  16.       (vl-propagate 'sz)
  17.     )
  18.     (if (or (= vc nil) (= sz nil))
  19.       (prompt "\nPlease Define Zoom Area")
  20.       (vl-cmdf "_.Zoom" "C" VC SZ)
  21.     )
  22.   )
  23.   (princ)
  24. )
Code - Auto/Visual Lisp: [Select]
  1. ;; This
  2. (or (= vc nil) (= sz nil))
  3. ;; Could be this
  4. (and vc sz)
Then swap the returns.
Title: Re: Zoom all in all the open documents
Post by: Marc'Antonio Alessi on May 19, 2022, 04:40:12 AM
Zoom all in all the open documents . . .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:ZE   (/ count docs i x-doc-obj )
  2.    (setq docs  (vlax-get-property (vlax-get-acad-object) "documents")
  3.          count (vlax-get-property docs "count")
  4.          i   0
  5.    )
  6.    (while (< i count)
  7.       (setq x-doc-obj (vla-item docs i) )
  8.       (vla-activate x-doc-obj)
  9.       (vla-ZoomAll  x-doc-obj)
  10.       (setq i (+ i 1) )
  11.    )
  12. )

why it does not work ?

is there a solution without scripts and without VBA ?
1) the argument must be a reference to the Application object  > (setq acadapplic (vlax-get-acad-object))
    (vla-ZoomAll acadapplic)

2) in AutoCAD maybe you have to use a script…

http://www.theswamp.org/index.php?topic=53912.0
http://www.theswamp.org/index.php?topic=53336.0
Title: Re: Zoom all in all the open documents
Post by: domenicomaria on May 19, 2022, 07:26:37 AM
@ MARC'ANTONIO


1) the argument must be a reference to the Application object  > (setq acadapplic (vlax-get-acad-object))
    (vla-ZoomAll acadapplic)


Right

. . . . . . . . . .

2) in AutoCAD maybe you have to use a script…

I would like a solution without the use of a script
but it seems that in ACAD it is not possible !
Title: Re: Zoom all in all the open documents
Post by: mhupp on May 19, 2022, 09:09:09 AM
I would like a solution without the use of a script
but it seems that in ACAD it is not possible !

Look into accoreconsole.exe its dos command line interface that allows you to change/edit drawings. running a script with that would be easier then running it in AutoCAD.

Quote
accoreconsole.exe is an executable file that is part of the AutoCAD 2013 - English program developed by Autodesk, Inc.. The software is usually about 710.29 KB in size.
Title: Re: Zoom all in all the open documents
Post by: Marc'Antonio Alessi on May 19, 2022, 11:13:04 AM
Tested new function vla-postcommand on A2023 but seem dot not works…  :tickedoff:

(defun c:ZoomAllAll (/ item)
  (vlax-for item (vla-get-documents (vlax-get-acad-object))
    (vla-postcommand item "_ZOOM _A\n")
  )
  (princ)
)

BricsCAD is different... (vla-PostCommand cmdString [echo])
to execute native commands and Lisp expressions in asynchronous mode.
The "cmdString" must end with a newline '\n', as with (vla-sendCommand cmdString).
Title: Re: Zoom all in all the open documents
Post by: mhupp on May 19, 2022, 11:31:54 AM
BricsCAD is different... (vla-PostCommand cmdString [echo])
to execute native commands and Lisp expressions in asynchronous mode.
The "cmdString" must end with a newline '\n', as with (vla-sendCommand cmdString).

What i posted above works in BricsCAD
Gif https://ibb.co/sJ3X37s
Title: Re: Zoom all in all the open documents
Post by: Marc'Antonio Alessi on May 19, 2022, 12:47:08 PM
BricsCAD is different... (vla-PostCommand cmdString [echo])
to execute native commands and Lisp expressions in asynchronous mode.
The "cmdString" must end with a newline '\n', as with (vla-sendCommand cmdString).

What i posted above works in BricsCAD
Gif https://ibb.co/sJ3X37s (https://ibb.co/sJ3X37s)
yes... BricsCAD is different  :)