Jump to content

Switch to another opened drawing in a script


Steven P

Recommended Posts

Good morning,

 

I couldn't see an answer to this so sorry if I have missed it somewhere, or am asking a very simple question.

 

I am trying to get my head round Scripts and have got so far. I am now stuck. If I have a script how do I make it switch to another open drawing to do stuff to that one?

 

For example, in a batch script, I can get it to open, do stuff, save and close a drawing that is currently closed, I can make the script do stuff to the current drawing but not other drawings that are open. So how do I do that?

 

 

Thanks in advance

Link to comment
Share on other sites

Using Vl you can get at what drawings are open and change to another dwg, I don't know about in a script. Google change dwgs using VL. Not something I know a lot about but know it exists.

Link to comment
Share on other sites

Thanks BigAl,

 

I haven't got it to work yet...

 

I have got little LISP routines that switch between drawings but when a script tries to run them it all goes wrong. Probably just me doing something wrong.

Link to comment
Share on other sites

Post the little bit of code you use to change dwgs, it may though be that once you change to another dwg control is lost to the script.

 

(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(repeat (setq howmany (vla-get-count acdocs))
(princ (vla-get-name (vla-item acdocs (setq howmany (- howmany 1)))))
)
; replace 1 with correct item number that matches say a dwg name
; (vla-activate (vla-item acdocs 1)) 

Link to comment
Share on other sites

Just thinking you may have to run the code above every time you change a dwg as the acdocs variable is refreshed in every dwg so opening a new one is not recognised until acdocs is reinitialised.

Link to comment
Share on other sites

Thanks,

 

I have been trying this on and off for the last couple of days.

 

I have been trying VLA-Activate. I can switch drawings OK but then the focus of the drawing doesn't shift fully - so I can see the new drawing OK and work with it, but any other commands in the script are still wanting to run on the first drawing -and when I go back to it they will continue where it left off.

 

If however I close the first drawing then whichever drawing becomes active will carry on the scrip... just hoping I can influence which drawing becomes active

 

I'm going to try your bity of code to see what that does, Tomorrow (depending on work), I'll strip out what I am trying to do and see if anyone can spot something I can't

 

I know with a LISP it will only run in the drawing that called it.

 

 

 

Thanks again for your help

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...