Open drawing by lisp

Open drawing by lisp

franc_as
Enthusiast Enthusiast
1,796 Views
11 Replies
Message 1 of 12

Open drawing by lisp

franc_as
Enthusiast
Enthusiast

I have this lisp routine to open specific drawing:

(defun c:TEST1 ()
(setq acApp (vlax-get-acad-object))
(setq acDocs (vla-get-documents acApp))
(vla-open acDocs "c:/Delo/Test1.dwt")
(princ)
)

Problem is ... my new opened drawing not become current, but goes in background (active stays my previous working drawing). 

franc_as_0-1726478786271.png


I need to make it current, because it is connected with other macro command.
Is it possible to modify my lisp or.... maybe some kind of system variable setting?

0 Likes
Accepted solutions (1)
1,797 Views
11 Replies
Replies (11)
Message 2 of 12

EnM4st3r
Advocate
Advocate

im wondering why its not staying active after the open method. It instantly goes back to the drawing the command is running in.

EnM4st3r_0-1726553252232.png

 

you can try to use vla-put-activedocument. So:

 

(defun c:TEST1 (/ acApp acDocs)
  (setq acApp (vlax-get-acad-object))
  (setq acDocs (vla-get-documents acApp))
  (vla-put-activedocument acApp (vla-open acDocs "c:/Delo/Test1.dwt"))
  (princ)
)

 


But your lisp will still keep running in the original document so not everything will work.

Message 3 of 12

franc_as
Enthusiast
Enthusiast

It works ...thank you
Can you help me also... how to add command at the end of this lisp, to save this drawing immediately to other location, with same name as dwg?
For instance to c:/Delo1/Test1.dwg

0 Likes
Message 4 of 12

EnM4st3r
Advocate
Advocate

use the SaveAs method.: 

(vla-saveas doc "c:/Delo1/Test1.dwg" acNative)

Also you can get the name of the dwg using 
(vla-get-name doc)

then combine it with your directory path using strcat. So for example
(setq dir "c:/Delo1")
(setq file (strcat dir "/" (vla-get-name doc)))
(vla-saveas doc file acNative)

you could also add some findfile checks to ensure the directory exists or if there isnt a file with that name already.

0 Likes
Message 5 of 12

franc_as
Enthusiast
Enthusiast

I put your line ((vla-saveas doc "c:/Delo1/Test1.dwg" acNative)) in lisp:

 

(defun c:TEST1 (/ acApp acDocs)
(setq acApp (vlax-get-acad-object))
(setq acDocs (vla-get-documents acApp))
(vla-put-activedocument acApp (vla-open acDocs "c:/Delo/Test1.dwt"))
(vla-saveas doc "c:/Delo1/Test1.dwg" acNative)
(princ)
)

...but it not working, just open dwt and stop. I dont know much about writing lisp, so I am confused by combine your instructions. I must write it wrong.
Could you write whole lisp correct?

0 Likes
Message 6 of 12

EnM4st3r
Advocate
Advocate
Accepted solution

you didnt save your document in the 'doc' variable so your variable was empty.

 

(defun c:TEST1 (/ acApp doc)
  (setq acApp (vlax-get-acad-object))
  (setq doc (vla-open (vla-get-documents acApp) "c:/Delo/Test1.dwt"))
  (vla-put-activedocument acApp doc)
  (vla-saveas doc "c:/Delo1/Test1.dwg" acNative)
  (princ)
)

 

 

Message 7 of 12

franc_as
Enthusiast
Enthusiast

Thank you...it is working now.
But one strange thing happened. All palettes (ribbon, properties....) and icons disappeared. Just like use CLEANSCREENON command.
Do you know why?
I solved this situation by inserting line... (command "CLEANSCREENOFF").... at the end of lisp, and it works. Is there any other solution?

0 Likes
Message 8 of 12

EnM4st3r
Advocate
Advocate

nothings closing for me. Maybe its your makro?

0 Likes
Message 9 of 12

franc_as
Enthusiast
Enthusiast

I don't think so... Macro is simple ^C^C_TEST1
I've changed lisp and macro TEST1 to different name, but same result.

Thanks again for your help.

0 Likes
Message 10 of 12

chris.klukan
Explorer
Explorer

This works great. 

 

Is there a way do this and open the drawing file read only?

Thank you

0 Likes
Message 11 of 12

EnM4st3r
Advocate
Advocate

yes just add :vlax-true add the end.

(vla-open (vla-get-documents acApp) "C:\\Crap\\Drawing1.dwg" :vlax-true)
Message 12 of 12

chris.klukan
Explorer
Explorer

Thank you, works great.

 

Is there a way in the original command to have the read-only dialog box pop up if another person has the drawing open.

0 Likes