Results 1 to 10 of 10

Thread: Opening a drawing from AutoLISP...

  1. #1
    100 Club FWSchreck's Avatar
    Join Date
    2000-12
    Posts
    177
    Login to Give a bone
    0

    Default Opening a drawing from AutoLISP...

    Hello:

    I've got an AutoLISP routine that opens an existing drawing file from the command line. The command works, but upon completion AutoCAD returns to the current drawing, rather than the newly opened file.

    Here's a code snippet:

    Code:
    (defun C:DETLOPEN ( / )
    
    	(setq olderr *error*)
    	(setq *error* dellerr)
    	(setvar "CMDECHO" 0)
    
            ...
    
    	(setq stDetailName (strcat stDetailFolder stCSIDivision stDetailName ".dwg"))
    
    	(if (findfile stDetailName)
    		(OpenDwgFile stDetailName nil)
    		(alert "File not found...")
    	);if
    
    	(princ)
    
    );defun
    
    ;; ---------------------------------------------------------
    
    (defun OpenDwgFile (arg1 arg2 / )
    
    	(vla-Open (vla-get-Documents (vlax-get-Acad-Object)) arg1
    		(if arg2
    			:vlax-true
    			:vlax-false
    		);if
    	);vla-Open
    
    ); defun
    
    ;; ---------------------------------------------------------
    Any ideas how I can force AutoCAD to make the newly opened file the active drawing?
    Last edited by Opie; 2011-05-19 at 06:33 PM. Reason: [code] tags added to disable smilies within posted code
    Fred Schreck
    KMD Architects
    San Francisco, CA, USA
    www.kmdarchitects.com

  2. #2
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    Vla-activate the newly opened drawing
    Civil 3D 2017 ~ Windohz 7
    Dropbox

  3. #3
    100 Club
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    116
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    Try the following as a replacement of your OpenDwgFile routine:

    Code:
    (defun OpenDwgFile (arg1 / )
      (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) arg1))
      ); defun
    Note that I have removed arg2. As long as the routine is trying to return a value (i.e. vlax-true or vlax-false) it will continue running after the new drawing is opened, and this will serve to keep focus from shifting to the new drawing. Also, I am unsure of its purpose in any case, as it only tells OpenDwgFile to return what you want it to return.

    Note that

    Code:
    (OpenDwgFile stDetailName nil)
    Will need to be replaced by

    Code:
    (OpenDwgFile stDetailName)
    in C:DETLOPEN

    I hope this proves helpful.

  4. #4
    100 Club FWSchreck's Avatar
    Join Date
    2000-12
    Posts
    177
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    Thanks, GHarvey... that works like a charm !
    Fred Schreck
    KMD Architects
    San Francisco, CA, USA
    www.kmdarchitects.com

  5. #5
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    The parameters are as follows:
    Code:
    (vla-open <Document> <File String> <Read Only :vlax-true or :vlax-false> [and the optional Password parameter])
    Civil 3D 2017 ~ Windohz 7
    Dropbox

  6. #6
    100 Club
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    116
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    Quote Originally Posted by alanjt View Post
    The parameters are as follows:
    Code:
    (vla-open <Document> <File String> <Read Only :vlax-true or :vlax-false> [and the optional Password parameter])
    Yes, on reflection afterward I figured it might be something like that. I'm afraid I was a bit rushed, and didn't take the time to consult the help file

  7. #7
    AUGI Addict alanjt's Avatar
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    Quote Originally Posted by GHarvey View Post
    Yes, on reflection afterward I figured it might be something like that. I'm afraid I was a bit rushed, and didn't take the time to consult the help file
    Well, now you don't even have to do that.
    Civil 3D 2017 ~ Windohz 7
    Dropbox

  8. #8
    Programming Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,398
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    Quote Originally Posted by alanjt View Post
    Well, now you don't even have to do that.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 32GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  9. #9
    I could stop if I wanted to Lee Mac's Avatar
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    Another way:

    http://lee-mac.com/open.html

    Haven't posted here in a while, nice to see a few familiar faces
    Lee Mac ProgrammingTwitter

    With Mathematics there is the possibility of perfect rigour, so why settle for less?


  10. #10
    Member
    Join Date
    2000-12
    Posts
    4
    Login to Give a bone
    0

    Default Re: Opening a drawing from AutoLISP...

    I realize this is a very old thread, but I hope someone may be able to help.

    The above code has been very helpful to open drawings and set them active.

    However, using the vla-open function, you do not know if the drawing opened as read-only because another user already had the drawing open.

    My questions:
    How can you check a drawing to see if it is open by another user before you open it with your function?
    How can you check an already open drawing to see if it is read-only. In other words, errors result if you try to save a drawing that was opened as read-only. I need to check current drawing's read-only status.

    I look forward to any replies.


    Regards,
    Jerry

Similar Threads

  1. View XREFS in a Drawing Without Opening the Host Drawing
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2013-11-27, 01:23 PM
  2. Opening dwgs/xrefs with Autolisp...
    By brwatts22 in forum AutoLISP
    Replies: 2
    Last Post: 2012-12-26, 11:50 AM
  3. I want to create a drawing without opening a drawing.
    By mikeosborne in forum VBA/COM Interop
    Replies: 6
    Last Post: 2009-10-01, 06:12 PM
  4. Replies: 2
    Last Post: 2008-07-09, 12:17 AM
  5. Macro or AutoLisp for opening multiple .dwt files
    By caduzer in forum AutoCAD Customization
    Replies: 2
    Last Post: 2006-07-24, 08:04 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
  •