Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: I can not open a Drawing File from within AutoCAD using AutoLISP

  1. #1
    Member
    Join Date
    2004-09
    Posts
    8
    Login to Give a bone
    0

    Question I can not open a Drawing File from within AutoCAD using AutoLISP

    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.

  2. #2
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    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?

  3. #3
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    See this thread for your problem.

    http://forums.augi.com/showthread.ph...ghlight=MyOpen

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    Quote Originally Posted by carl_hd_collins
    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

  5. #5
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    ^^^ 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!

  6. #6
    Member
    Join Date
    2004-09
    Posts
    8
    Login to Give a bone
    0

    Unhappy Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    Quote Originally Posted by peter
    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.

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    What is the exact full path and filename?

  8. #8
    I could stop if I wanted to
    Join Date
    2003-11
    Posts
    277
    Login to Give a bone
    0

    Default Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    Hi partha,
    test this code, I hope can help you
    Code:
    (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
      )
    Quote Originally Posted by partha_ghosh70
    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.

  9. #9
    Member
    Join Date
    2004-09
    Posts
    8
    Login to Give a bone
    0

    Smile Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    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

  10. #10
    I could stop if I wanted to
    Join Date
    2003-11
    Posts
    277
    Login to Give a bone
    0

    Default Re: I can not open a Drawing File from within AutoCAD using AutoLISP

    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

Page 1 of 2 12 LastLast

Similar Threads

  1. AutoCAD 2008 unable to open a drawing file that crashed
    By gregoran in forum AutoCAD General
    Replies: 6
    Last Post: 2007-06-28, 06:17 PM
  2. Open AutoCAD with the last saved drawing file
    By Bear31831 in forum AutoCAD General
    Replies: 5
    Last Post: 2007-04-06, 09:13 PM
  3. Replies: 15
    Last Post: 2006-11-23, 03:47 AM
  4. Replies: 5
    Last Post: 2006-07-14, 07:19 PM
  5. AutoCAD Text window pops-up every time I open a drawing file.
    By robert.1.hall72202 in forum AutoCAD General
    Replies: 3
    Last Post: 2006-05-08, 01:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •