Jump to content

Opening *.dwg files from Autolisp


Guest odon

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :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---------------------------

Link to comment
Share on other sites

Guest SpeedCAD
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

Link to comment
Share on other sites

  • 10 months later...
Guest alanhuro

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

Link to comment
Share on other sites

Guest alanhuro

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

Link to comment
Share on other sites

Guest alanhuro

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

Link to comment
Share on other sites

  • 4 years later...
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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...