Jump to content
bababarghi

How to run a lisp across 'all open drawings' ?

Recommended Posts

bababarghi

All,

 

I have two preliminary routines called CA (CloseAll) and PA (PrintAll) tailored for my needs as following:

 

CloseAll:

(defun C:CA()
(setvar "TILEMODE" 1)
(command "._ZOOM" "_Extents")
(command "._PURGE" "all" "*" "No")
(command "._PURGE" "all" "*" "No")
(command "._PURGE" "all" "*" "No")
(setvar "TILEMODE" 0)
(command "._MSPACE")
(command "._Grid" "_OFF")
(command "._OVERKILL" "ALL" \\P "DONE")	
(command "._PSPACE")
(command "._VPORTS" "L" "ON" "ALL" "")
(command "._ZOOM" "_Extents")
(command "._QSAVE")
(command "._CLOSE")
)

 

PrintAll:

(defun C:PA()
 (foreach x  (LAYOUTLIST)
   (setvar "CTAB" x)
   (command "-PLOT" "" "" "" "" "" "" ""))
 )

 

Above codes work perfect for a single drawing. However, I am stuck on applying them to all of my open drawings (trying to learn LSP gradually :oops:).

 

Note I don't want to 'browse' for any specific folders or drawings or load some script to do so. Instead I need to apply my code across all open drawings.

 

 

The intent is to put them both in my Startup Suite and call them whenever needed.

 

 

Attentions are appreciated in advance.

Share this post


Link to post
Share on other sites
Lee Mac

Since AutoLISP runs in the document namespace (that is, in the active drawing) you will need to use an AutoCAD Script (.scr file) if you wish to run the programs in more than one drawing.

Share this post


Link to post
Share on other sites
bababarghi
Since AutoLISP runs in the document namespace (that is, in the active drawing) you will need to use an AutoCAD Script (.scr file) if you wish to run the programs in more than one drawing.

 

Thanks for the reply Lee.

The reason why I am pursuing such approach is, because I noticed to an option in your BFind program which gives me the pleasure of searching (let's say processing) on open drawings.

 

BFind_V2_0_1.png

 

Can you show me the pathway toward that direction maybe?

Share this post


Link to post
Share on other sites
Lee Mac

When processing all open drawings, my BFind application iterates over the ActiveX documents collection and manipulates the ActiveX properties of each document object (and objects derived from the document) whilst running in the active document namespace.

 

This is only possible to achieve using Visual LISP ActiveX properties & methods which operate only on the document object or objects derived from the document object; hence, in general it is not possible to run an arbitrary AutoLISP program on any drawing except the active drawing and instead an AutoCAD Script must be used, as stated above.

 

Furthermore, it would not be possible to convert your programs to functions which operate only on the ActiveX document object as the programs contain operations (such as zooming) which are methods of the Application object and hence cannot be applied outside of the active document, and custom commands (such as overkill) which would need to be entirely recreated using only Visual LISP.

Share this post


Link to post
Share on other sites
bababarghi

Frankly, that was too much information for me to digest but thanks for that. At least, I realised it is not that easy as I thought. Can you refer me to more resources? I am curious to read about it more thoroughly.

Share this post


Link to post
Share on other sites
BIGAL

here is a start list of dwg names

 

 



; THANKS TO AHANKHAH for original code
(vl-load-com)
(setq acadobject (vlax-get-Acad-Object))
(setq documentcollection (vla-get-documents acadobject))
(vlax-for <doc> documentcollection
 (if (eq "" (setq *dwg* (vla-get-fullname <doc>))) (setq *dwg* (vla-get-name <doc>))) 
 (setq *acdocs* (cons (cons (strcase *dwg*) <doc>) *acdocs*))
)
(reverse *acdocs*)
(princ *acdocs*)

Edited by BIGAL

Share this post


Link to post
Share on other sites
BIGAL

Lee found an old post of yours here http://www.theswamp.org/index.php?topic=29097.0

 

 

Can this help using (vla-activate (vla-open dwgname)) so long as we close the dwg then rerun a script that looks at open number of dwgs obviously once we have no more dwgs will not run.

Share this post


Link to post
Share on other sites
bababarghi

Since I have a similar concern, this time, I am not creating new thread for that.

 

Following post no. 4, by Lee, how can I set TILEMODE for all of open drawings? Is it possible at all? I need to set TILEMODE to "0" for all of my open drawings.

Share this post


Link to post
Share on other sites
bababarghi

bhull1985, mate, you must have had a really bad day. I don't know how you got the implication of ignorance or disrespect from my posts.

 

First of all, thanks for the hint about Setvar. You misunderstood my question. The concern is about applying Setvar on all open drawings not the fact of using Setvar itself.

 

Secondly, no offence but, would you please let Lee talks on his behalf? I have always appreciated his kind favour in all forums via direct replies, private messages or sometimes his twitter account. Person who is generously sharing his LSP collection with others for free while others sell their '2+2 = 4' lisp for $8.99, clearly intend to share his knowledge nothing whatsoever.

 

His comment was the final verdict for me not to pursuit my previous approach try applying that piece of code to all open drawings. That's why topic went silent from my side.

 

However, having the same question, I want to know how to get following code iterate through all open drawings. Not sure how to implement a ForEach for iteration. :unsure:

 

(defun c:S2L (/ OpenDwgs eachDwg)
 (setq OpenDwgs (vla-get-documents (vlax-get-acad-object)))
 (vlax-for eachDwg OpenDwgs
   (setvar "tilemode" 0)
 )
 (princ)
)

 

Now, if you don't mind, can I kindly ask to leave this 'pancake' stuff for others and myself?

Share this post


Link to post
Share on other sites
hmsilva

Something like this perhaps.

(defun c:S2L ( / )
 (vlax-for OpenDwgs (vla-get-documents (vlax-get-acad-object))
   (vla-setvariable OpenDwgs "TILEMODE" 0)
 );; vlax-for
 (princ)
)

 

HTH

Henrique

Share this post


Link to post
Share on other sites
bababarghi

That's it. Thank you so much.

Share this post


Link to post
Share on other sites
hmsilva

You're welcome.

Glad I could help

 

 

Henrique

Share this post


Link to post
Share on other sites
Lee Mac

Good stuff Henrique - thanks for stepping in whilst I have been busy.

Share this post


Link to post
Share on other sites
hmsilva
Good stuff Henrique - thanks for stepping in whilst I have been busy.

Thank you Lee. :)

Happy to help!

 

 

Henrique

Share this post


Link to post
Share on other sites
mikitari

Hi Guys!

Could this way of work be used to:

1. update a block definition from one drawing to all open drawings? (by hand it is through wblock/insert or design center)

2. Attsync that block or all blocks on all open drawings?

Share this post


Link to post
Share on other sites
rlx

is asked before :

 

have a block routine but some say it's rather complicated to drive so to spreak so I won't repost or refer to it , but the way my batch application works in case of mdi mode is to start a new drawing , save and close all open drawings and then reopen them and run all the scripts & commands I want. Totally dragon proof and totally don't care about the few seconds longer it takes compared to vba / odbx.

 

if you do want to use the fast lane (not sure about dynamic blocks though) the way my block routine handles it is for each block get its properties (inspoint , rotation etc) and all the attribute values , then burn them all , sorry can't help m'self , then delete them all , purge block definition , and then re-insert them one by one and transfer attribute data.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...