Guest odon Posted June 10, 2004 Posted June 10, 2004 How can I open a *.dwg file from Autolisp? The line: (command "_open" "file path and name") doesn't seem to be working. Quote
Dommy2Hotty Posted June 11, 2004 Posted June 11, 2004 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. 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. Quote
Guest odon Posted June 12, 2004 Posted June 12, 2004 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? Quote
Dommy2Hotty Posted June 12, 2004 Posted June 12, 2004 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] This site had the following code on it. I haven't tried it (as I'm getting ready to hit the club ), 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--------------------------- Quote
Guest SpeedCAD Posted June 12, 2004 Posted June 12, 2004 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 Quote
Dommy2Hotty Posted June 12, 2004 Posted June 12, 2004 I knew the vla stuff would be able to do it...haven't learned it yet... Quote
Guest odon Posted June 13, 2004 Posted June 13, 2004 Thank you Dommy2Hotty and SpeedCAD for your help. Vla is definately on my programming to learn list. Quote
Guest alanhuro Posted May 12, 2005 Posted May 12, 2005 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 Quote
Guest alanhuro Posted May 12, 2005 Posted May 12, 2005 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 Quote
Guest alanhuro Posted May 13, 2005 Posted May 13, 2005 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 Quote
sunil Posted May 15, 2009 Posted May 15, 2009 How to opwn a new file & insert a drawing template using autolisp Quote
sunil Posted May 15, 2009 Posted May 15, 2009 I want to use database created in excel file to draw a rectangular plate with a hole at its center by programming in autolisp. Quote
Lee Mac Posted May 15, 2009 Posted May 15, 2009 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. Quote
Recommended Posts
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.