Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

open file, select, copy and close with another drawing open

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
brandtpileggi
2142 Views, 4 Replies

open file, select, copy and close with another drawing open

Hey everyone! First post. I apologize for any lapses in etiquette. I promise, I have been looking this up already and haven't been able to find anything on it. Thanks!

 

Background: With a drawing already open, I want to open another drawing, select all objects no a few layers, copy and close without saving. 

 

Where I'm at: I currently have a half working code that almost does everything, however, even thought I am activating the second drawing, it's still selecting the objects from the original drawing that is still open instead of the one that I'm opening to get the selected objects from. 

 

Code so far:

 

(defun c:IMPORTSITE (/)

 

; open dwg

(setq acApp (vlax-get-acad-object))
(setq acDocs (vla-get-documents acApp))
(vla-activate
(vla-open acDocs "[filepath to dwg file]")
)


; Delay 5 seconds while the file is opened

(command "DELAY" 5000)

; Select all line work layers for the site and N arrow

(sssetfirst nil (ssget "_X" '((8 . "cxsite,cxarrow"))))

 

; copy lines

(initcommandversion) (command "._copy")
)

 

Thank you to whomever can help!

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: brandtpileggi

Unfortunately, AutoLisp can't start in one drawing and continue in another under the multiple-drawing interface.  If you're willing, I think you can set SDI to 1 [Single-Drawing Interface], and your routine would need to QSAVE the current drawing, OPEN the other one [which will CLOSE the current one], COPYCLIP or COPYBASE the stuff you want [I think that's what you're talking about, not COPY, if you really mean "get the selected objects from" in the sense of then using them elsewhere], OPEN the first drawing again [which will CLOSE the other one -- build in the answer to the question about Saving], and PASTECLIP the stuff into it.  Then presumably you would set SDI back to 0 so you can have multiple drawings open at the same time again.

 

EDIT:

For example, if I'm in a drawing called Trash, and there's a drawing called Junk with at least one object drawn in it, and I set SDI to 1 and Qsave Trash first to avoid the question, the following works to bring the last object from Junk into the Trash drawing:

(command "_.open" "junk" "_.copyclip" "_last" "" "_.open" "_no" "trash" "_.pasteclip" "0,0")

Kent Cooper, AIA
Message 3 of 5
brandtpileggi
in reply to: Kent1Cooper

Thanks so much Kent! That's where I was heading but wanted to make sure there was no other options that I was missing. Thanks for the rest of the supporting explanations and examples. Those will be invaluable. And as a side note... I'm kind of fanboying over here that it was you that replied. Seems like I've been reading nothing but you and Lee Mac for the last couple months. Thank you for helping create so many LISP professionals throughout your career.

Message 4 of 5
brandtpileggi
in reply to: Kent1Cooper

I am so close, but the use of (command) (command) is making the following not work:

 

(sssetfirst nil (ssget "_X" '((8 . "layer1,layer2,layer3,layer4"))))

(command "._copybase" "0,0")

 

and I need something to act as pressing the escape button twice because it asks me to "select objects" and tries to use "_.open" to select objects. When I run the whole code line by line in the command box in Autocad, it doesn't ask me to do that. Only when I run it as a as a lisp, does it ask to "select objects" for some reason. Also when I run just

the aforementioned section of code to select and copy lines without the (command) (command), it works perfectly. Any ideas? Thank you!

 

(defun c:ImportThing ()

;set SDI to 1 [Single-Drawing Interface],
(setvar "filedia" 0)
(setvar "SDI" 1)

;QSAVE the current drawing,
(command "_qsave")

;OPEN the other one [which will CLOSE the current one],
(command "_.open" "c:\\source\\filepath")

;wait for file to open
(command "delay" 3000)

;select all lines on specified layers
(sssetfirst nil (ssget "_X" '((8 . "layer1,layer2,layer3,layer4"))))

 

;copy with a base of origin

(command "._copybase" "0,0")

 

;get rid of "select objects" X2

(command) (command)

 

;OPEN the other original [which will CLOSE the current one],
(command "_.open" "_Y" "C:\\target\\filepath")

;wait for file to open
(command "delay" 3000)

;and paste to coordinates
(command "_.pasteclip" "1.25275090E+04,33'-11.38671875")

;reset filedia and sdi
(setvar "filedia" 1)
(setvar "SDI" 0)

;lay back and greet our robot overlords
)

Message 5 of 5
Anonymous
in reply to: brandtpileggi

(command "._copybase" "0,0" "")

should do the trick, as it is like pressing enter on the command line

 

another approach would be to get the modelspace of the new drawing

 

(vl-load-com)
(setq app (vlax-get-acad-object))
(setq docs (vla-get-documents app))

(setq file (vla-add docs "acadiso.dwt"))

(setq modelspace (vla-get-modelspace f))

 

and work from there with active-x methods

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report