PDA

View Full Version : I can not open a Drawing File from within AutoCAD using AutoLISP


partha_ghosh70
2007-06-18, 12:08 PM
Dear All,

I want to open "PDOC-BUILDING-ELC-61001C.dwg" drawing file.

To open it using AutoLISP, I have used this expression: (Command "_open" "PDOC-BUILDING-ELC-61001C.dwg") . But, the drawing is not getting opened.

Please help me providing the exact expression.

Avatart
2007-06-18, 03:13 PM
It is always a problem, trying to open drawings from within routines, as the lisp may try and reload on document startup. Are there variables you are taking from the routine in one drawing that you want to be applied in the one you are opening?

T.Willey
2007-06-18, 04:53 PM
See this thread for your problem.

http://forums.augi.com/showthread.php?t=35374&highlight=MyOpen

peter
2007-06-18, 11:53 PM
It is always a problem, trying to open drawings from within routines, as the lisp may try and reload on document startup. Are there variables you are taking from the routine in one drawing that you want to be applied in the one you are opening?

AutoLISP is a document level language. Which means the instant the drawing switches to a new drawing. The program stops, in mid command. VBA is a application level language and can switch drawings and continue running.

AutoLISP was added to AutoCAD when you could only have one document open, the VBA was added to AutoCAD later when it was being configured to run on Windows so its ability to handle the multiple documents.

You can open a drawing with LISP using something like this with the variable FILENAME as the drawing name (without hanging up in mid command)

(command "vbastmt" (strcat "AcadApplication.Documents.Open \"" FILENAME "\""))

You can also set a script file to do this, or have a startup routine that will load and restart your routine using lisp.

My opinion it would be better to just do the routine with VBA.

IMHO if you deal with multiple documents VBA is the choice, if you are dealing with drafting tools in LISP is the choice.

:)

Peter

Avatart
2007-06-19, 09:38 AM
^^^ That's the proper technical description of what I was getting at. You can run Lisps over multiple drawings, but it is very difficult (you need to write out a temporary Lisp file, set it to run at drawing start-up, then close the drawing and remove from start-up).

I'd go with the VBA, it sounds a whole lot easier!

partha_ghosh70
2007-06-19, 11:25 AM
AutoLISP is a document level language. Which means the instant the drawing switches to a new drawing. The program stops, in mid command. VBA is a application level language and can switch drawings and continue running.

AutoLISP was added to AutoCAD when you could only have one document open, the VBA was added to AutoCAD later when it was being configured to run on Windows so its ability to handle the multiple documents.

You can open a drawing with LISP using something like this with the variable FILENAME as the drawing name (without hanging up in mid command)

(command "vbastmt" (strcat "AcadApplication.Documents.Open "" FILENAME """))

You can also set a script file to do this, or have a startup routine that will load and restart your routine using lisp.

My opinion it would be better to just do the routine with VBA.

IMHO if you deal with multiple documents VBA is the choice, if you are dealing with drafting tools in LISP is the choice.

:)

Peter


I put the drawing name as a variable and run the expression as suggested. But it shows "Run-time Error '-2145320924 (80210024)': " and "File ..... is not found", though I referred the corresponding folder in "Support file search path".

Pleas suggest.

peter
2007-06-19, 02:25 PM
What is the exact full path and filename?

Adesu
2007-06-20, 02:19 AM
Hi partha,
test this code, I hope can help you

(setq filename "D:/YBI/Drawing/Lat/Test-1.dwg")
(setq vgao (vlax-get-acad-object))
(setq vgad (vla-get-activedocument vgao))
(setq vgd (vla-get-documents vgao))
(if
(= 0 (getvar "SDI"))
(vla-activate (vla-open vgd filename)) ; if sdi = 0
(vla-sendcommand vgad (strcat "(command \"_open\")\n" filename "\n")); if sdi = 1
)


I put the drawing name as a variable and run the expression as suggested. But it shows "Run-time Error '-2145320924 (80210024)': " and "File ..... is not found", though I referred the corresponding folder in "Support file search path".

Pleas suggest.

partha_ghosh70
2007-06-20, 09:48 AM
Dear Peter,

The exact full path : "E:/As Built/As Built from MMC - MOGA Project/As-Built Dwgs-MECH-PIPING/ISOMETRICS/CO"

The drawing name:- "CO2002601.dwg"

The code which Adesu has given in next post is working.

But, I would like to request you to feed us back on your suggested code also to enhance our knowledge.

Thanks a lot.

---------------------------------------------------------------------------------------------------------------------------------
Dear Adesu,

The code is working nicely. Thank you very much.

-------------------------------------------------------------------------------------------------------------------------------

Thanks a lot to you all, friends.

Partha

Adesu
2007-06-21, 02:09 AM
You are welcome.
I glad you have solve your problem.


Dear Adesu,

The code is working nicely. Thank you very much.

-------------------------------------------------------------------------------------------------------------------------------

Thanks a lot to you all, friends.

Partha