Author Topic: Need to close a DWG after a script has started ...  (Read 7384 times)

0 Members and 1 Guest are viewing this topic.

nivuahc

  • Guest
Re: Need to close a DWG after a script has started ...
« Reply #15 on: January 25, 2011, 06:34:54 PM »
This is how I do it, quick and dirty, works like a charm (for me)

Code: [Select]
(defun c:scriptit ( / file files open_file f )
(setq file "C:\\MYPATH\\" ; where we start looking for drawings
      open_file (open "C:\\MYPATHANDSCRIPTNAME.scr" "w") ; where we store the script and what we call it
) ;_ end setq

(while
  (setq file (getfiled "Select files to include in script" file "dwg" 128))
  (setq files (cons file files))
) ; end while

(write-line "sdi\n1" open_file) ;_ turn on single document interface
(foreach f (reverse files)
(write-line
(strcat "open\n\"" f "\"
;;;;;;;;;;; Erase this comment and put all of your commands in here (including calls to LISP routines), open and closed quotes are already handled
qsave")
open_file)
) ; end foreach

(write-line "sdi\n0" open_file) ;_ turn off single document interface
(close open_file)
) ; end defun

Hangman

  • Swamp Rat
  • Posts: 566
Re: Need to close a DWG after a script has started ...
« Reply #16 on: January 25, 2011, 07:04:16 PM »
Lee,
I need some assistance with your code:
Also

Code: [Select]
(vla-activate (vla-add (vla-get-Documents (vlax-get-acad-object))))

I ended up using ronjonp's but I want to know what I did wrong with your line here.
This is what I did:
Code: [Select]
(defun CloseOrigDWG (/ FNnote NewFName j)
  (prompt "\nClosing Original DWG ... ")
  (setq FNnote (open FNnotePath "R")
        NewFName (read-line FNnote)    [color=blue]There are two lines in the document, I only need the second[/color]
        NewFName (read-line FNnote))   [color=blue]I'll go back and put in some testing to make sure it is the correct line[/color]
  (setq FNnote (close FNnote))
  (vla-activate (vla-add (vla-get-Documents (vlax-get-acad-object)))
    (setq j (vla-item NewFName))
  )
  (vla-close j)
)

This is what I got back:
Quote
Application Error: 2 :- bad argument type: VLA-OBJECT "5N15B-2-P0210 S3_orig.dwg"
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Need to close a DWG after a script has started ...
« Reply #17 on: January 25, 2011, 07:09:58 PM »
Hint:

Code: [Select]
(setq j (vla-item NewFName))
NewFName is an item of which collection?

I think you'll get the same result as my post #11 however... "Automation Error: Drawing is Busy"

Hangman

  • Swamp Rat
  • Posts: 566
Re: Need to close a DWG after a script has started ...
« Reply #18 on: January 27, 2011, 02:07:55 PM »
I have just noticed something in regards to Ronjon's code:

Quote
< .. >
See if this gives you any ideas:

Code: [Select]
(setq docs (vla-get-documents (vlax-get-acad-object)))
(setq i (vla-item docs "Drawing1.dwg"));;<-Name is case sensitive
;;Should work for drawings in the background but not if drawing is current
(vla-close i)


Did you know this code will save the document as is when it closes?
I hadn't noticed this before, but as I was running some final tests before putting this out to my users, I noticed my drawings are not what they were when first opened.

So, how can I tell it to close without saving?
There's gotta be some kind of
Code: [Select]
(vla-close ::(save=false) i)right?
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Need to close a DWG after a script has started ...
« Reply #19 on: January 27, 2011, 02:10:31 PM »
Look into the arguments for the vla-close method.  :-)

Hangman

  • Swamp Rat
  • Posts: 566
Re: Need to close a DWG after a script has started ...
« Reply #20 on: January 27, 2011, 04:52:25 PM »
Look into the arguments for the vla-close method.  :-)

OK, I am blind and dumb; I can't find the arguments for the vla-close method.   Where do I look?

I did find this http://www.theswamp.org/index.php?action=printpage;topic=26699.0 which gave me the example I needed to get it working.  But I want to read up on the possible arguments of - not just vla-close - the vla commands.

Thanks.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Need to close a DWG after a script has started ...
« Reply #21 on: January 27, 2011, 04:54:23 PM »
Look into the arguments for the vla-close method.  :-)

OK, I am blind and dumb; I can't find the arguments for the vla-close method.   Where do I look?

A little tutorial for ya  :lol:

http://lee-mac.com/functioninfo.html

Note that the help for the VL props/methods will be written with VBA in mind, but the arguments, their types and order all apply to VL, so it shouldn't be difficult to make the connections.

Also, if you're using 2011, I think ADesk removed the help for the VL props/methods when they went online with it :-(

Hangman

  • Swamp Rat
  • Posts: 566
Re: Need to close a DWG after a script has started ...
« Reply #22 on: January 27, 2011, 05:31:10 PM »
< .. >
http://lee-mac.com/functioninfo.html
 < .. >

DOHT!!!  Where is my brain.  I went through the ACAD help file, the AutoLisp Reference, AutoLisp Developers guide, and a brief search online.
didn't even think of VLIDE even though I use it to check my code.


Quote from: Lee Mac
Also, if you're using 2011, I think ADesk removed the help for the VL props/methods when they went online with it :-(

And that would be why I can't find it.  Hehehe, blame it on Autodesk.    :thumbsup:
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Need to close a DWG after a script has started ...
« Reply #23 on: January 27, 2011, 05:40:18 PM »
And that would be why I can't find it.  Hehehe, blame it on Autodesk.    :thumbsup:

I think there's a .chm alternative for 2011 that is available here, but I couldn't say whether it would include the VL props/methods...

Scratch the above, upon looking at the Readme here, it appears the help is available, but in a separate chm:

Quote from: AutoCAD 2011 Readme
For help with vla-* functions, see the AutoCAD ActiveX and VBA Reference available at C:\Program Files\Common Files\Autodesk Shared\acadauto.chm (not available online).

Why do they have to make our lives harder...  :-(
« Last Edit: January 27, 2011, 05:43:26 PM by Lee Mac »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need to close a DWG after a script has started ...
« Reply #24 on: January 27, 2011, 07:20:15 PM »
FWIW.

I have links to some Help Files on a Windows Toolbar

quite handy sometimes ..

.. a piccy at work ... home is different :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: Need to close a DWG after a script has started ...
« Reply #25 on: January 27, 2011, 07:21:14 PM »
I have links to some Help Files on a Windows Toolbar

Nice idea  :-)

On a similar note, I have a dock with links to ACAD, my LISP Sub library etc... - saves so much time.