View Full Version : Opening *.dwg files from Autolisp
odon
10th Jun 2004, 09:33 pm
How can I open a *.dwg file from Autolisp? The line: (command "_open" "file path and name")
doesn't seem to be working.
Dommy2Hotty
11th Jun 2004, 03:25 pm
The reason why it's not working is because you need to change the variable "FILEDIA" to "0" to display the command line version of the open command.
(command "FILEDIA" 0)
In what way will you be using this? As just an open routine, or as part of a bigger routine? That will help us understand how to go further with this. :twisted:
EDIT: The open command, when "FILEDIA" is set to "0" will require the FULL DRAWING PATH in order to open the correct drawing. If this is going to be just to open a drawing, not part of a bigger routine, you'd be better off just using the open dialog box, I.M.O.
odon
12th Jun 2004, 01:18 am
Here's what I have:
(defun C:OpenDwg ()
(setvar "filedia" 0)
(command "_.open" "c:\\temp\\18-99.dwg")
(setvar "filedia" 1)
(princ)
)
It works from the command line but not the code.
What needs to be changed to make it work?
Dommy2Hotty
12th Jun 2004, 03:37 am
I've looked into it further, and although I couldn't get it to work correctly either, I did come across this page on AfraLisp:
[AfraLisp page] (http://www.afralisp.com/newsletter/code/code19.htm)
This site had the following code on it. I haven't tried it (as I'm getting ready to hit the club :twisted:), but see if this helps you any:
;;;----------------CODING STARTS HERE---------------------------
;;; ( GEN:OpenDwgFile filename bit )
;;; Function discerns which Acad version and applies appropriate command.
;;; Bit controls as follows
;;; 0 = Open file if Acad2000 or separate session if Acad14
;;; 1 = Open file - Don't save current drawing
;;; 2 = Open file - Save current drawing.
( defun GEN:OpenDwgFile ( filenm bit / cmd f )
;;; local functions
( defun OpenDwgFileR15 ( f / cmd )
; string together the cmd expression and send to VBASTMT e.g.
; ( command "vbastmt" "AcadApplication.Documents.Open
\"x:/ADG/templates/ControlledSurveys.dwt\"")
( setq cmd ( strcat "AcadApplication.Documents.Open \"" f "\"" ))
( command "vbastmt" cmd )
) ; local defun
( defun OpenDwgFileR14 ( f bit / cmd )
( command "pan" "0.0,1.0,0.0" "0.0,0.0,0.0" ) ; force prompt
( if ( = bit 1 )
( command "_.open" "n" f ) ; save changes
( command "_.open" "y" f ) ; don't save changes
)
) ; local defun
( defun OpenDwgFile>0 ( f )
( alert "When using this file either SAVEAS and edit file \n OR
\nCUT and PASTE but don't overwrite original." )
(if ( wcmatch ( getvar "ACADVER" ) "15*" )
( progn
( setvar "SDI" 0 ) ; turn on multiple document interface
( OpenDwgFileR15 f ) ; if R2000 open dwg otherwise start separate
session of Acad.
); progn
( startapp "acad.exe" f)
)
); local defun
( defun OpenDwgFile>1 ( filenm / f ) ; don't save changes
(if ( wcmatch ( getvar "ACADVER" ) "15*" )
( progn ( OpenDwgFileR15 filenm ));progn
( OpenDwgFileR14 filenm 0 )
)
); local defun
( defun OpenDwgFile>2 ( filenm / f ) ;save changes
(if ( wcmatch ( getvar "ACADVER" ) "15*" )
( progn ( OpenDwgFileR15 filenm ));progn
( OpenDwgFileR14 filenm 1 )
)
); local defun
; main function
( if ( setq f ( findfile filenm )) ; locate file
( progn
( cond
(( = bit 0 )( OpenDwgFile>0 f )); access another drawing
(( = bit 1 )( OpenDwgFile>1 f )); don't save changes
(( = bit 2 )( OpenDwgFile>2 f )); save changes
);cond
);progn
( alert ( strcat "AutoCad cannot find " filenm ))
)
) ; defun
;;;----------------CODING ENDS HERE---------------------------
SpeedCAD
12th Jun 2004, 03:42 am
Here's what I have:
(defun C:OpenDwg ()
(setvar "filedia" 0)
(command "_.open" "c:\\temp\\18-99.dwg")
(setvar "filedia" 1)
(princ)
)
It works from the command line but not the code.
What needs to be changed to make it work?
Hi...
prove this:
(defun c:OpenDwg ()
(vla-open (vla-get-documents
(vla-get-application (vlax-get-acad-object))
)
"c:\\temp\\18-99.dwg"
)
) ;_defun
Dommy2Hotty
12th Jun 2004, 08:47 am
I knew the vla stuff would be able to do it...haven't learned it yet... :(
odon
13th Jun 2004, 02:53 am
Thank you Dommy2Hotty and SpeedCAD for your help. Vla is definately on my programming to learn list.
:)
alanhuro
12th May 2005, 08:32 pm
Hi
It's happen that I ran in the same problem as you do. I have tried all the code in this topic but could not make it to work neither. What a bummer. Wonder why it works from command line but does not work from script. This is really dump. Odon I just wonder have you found out a solution yet? I try the code of Speedcad but don't know how it works.
thanks
Alan
alanhuro
12th May 2005, 09:04 pm
I went to Autocad website support and found a solution for it. We have to disable the Multiple Design Environment (MDE) before we are able to use that command
(setvar "SDI" 1)
Here is a code I use
(command "FILEDIA" 0)
(command "_.OPEN" "y" file)
(setvar "filedia" 1)
Hope this help
Alan
alanhuro
13th May 2005, 04:16 pm
I still have problem with is
It is weird that as soon as I open the file all of my variable define in my fuction is reset to NIL. What I try to do with my script is to open the file make a change and then save as different name. But when I execute that command all my variable set is gone. Do you know how can I define the variable so it will stay what it is.
Thanks
alan
sunil
15th May 2009, 01:40 pm
How to opwn a new file & insert a drawing template using autolisp
sunil
15th May 2009, 01:45 pm
I want to use database created in excel file to draw a rectangular plate with a hole at its center by programming in autolisp.
Lee Mac
15th May 2009, 05:05 pm
I want to use database created in excel file to draw a rectangular plate with a hole at its center by programming in autolisp.
If you have a new question, could you please not tack it onto an existing thread, but rather create a new thread.
This will help with searches, and get your question answered quicker.
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.