Jump to content

open drawing using lisp


kalai

Recommended Posts

FWIW - Just be aware that when you change document namespaces (using vla-activate...) your code will stop working, unless your code is run from a separate namespace (outside of the ActiveDocument prior to vla-activate...).

 

HTH

Link to comment
Share on other sites

FWIW - Just be aware that when you change document namespaces (using vla-activate...) your code will stop working, unless your code is run from a separate namespace (outside of the ActiveDocument prior to vla-activate...).

 

HTH

 

Yes , I used to load my routines too much directly from the Vlide and when I run the vla-open with vla-activate , I can not do anything except shutting down the Vlide

and released that the document it self keep on loading for a while .

 

Thanks.

Link to comment
Share on other sites

this is the code i could get

(defun c:old (/ cd vgad vgao vgd)
 (vl-load-com)
 (setq vgao (vlax-get-acad-object))
 (setq vgad (vla-get-activedocument vgao))
 (setq vgd (vla-get-documents vgao))
 (setq cd "D:/YBI/Drawing/Layout/global/Master/YBI.dwg") 
 (if
   (= 0 (getvar "SDI"))
   (vla-activate (vla-open vgd cd))                               ; if sdi = 0
   (vla-sendcommand vgad (strcat "(command \"_open\")\n" cd "\n")); if sdi = 1
   )                              ; if
 (princ)
 )

But i doesnot end.

now the drawing is opened.but i am not able to work.

i am getting fatal errror

could anyone help

Link to comment
Share on other sites

Try it this way .

 

(defun c:old nil
 (vl-load-com)
 (if
   (= 0 (getvar "SDI"))
    (vla-activate
      (vla-open (vla-get-documents (vlax-get-acad-object))
                "D:\\YBI\\Drawing\\Layout\\global\\Master\\YBI.dwg"
                :vlax-false
      )
    )
 )
 (princ)
)

 

Tharwat

Link to comment
Share on other sites

  • 10 months later...

Lee,

I have a question about your code, so I copied it here:

;;------------------------=={ Open }==------------------------;;
;;                                                            ;;
;;  Uses the 'Open' method of the Shell Object to open the    ;;
;;  specified file or folder.                                 ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  target - file, folder or ShellSpecialFolderConstants enum ;;
;;------------------------------------------------------------;;
;;  Returns:  T if successful, else nil                       ;;
;;------------------------------------------------------------;;

(defun LM:Open ( target / shell result )
   (if
       (and
           (or
               (eq 'INT (type target))
               (setq target (findfile target))
           )
           (setq shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
       )
       (progn
           (setq result (vl-catch-all-apply 'vlax-invoke (list shell 'open target)))
           (vlax-release-object shell)
           (not (vl-catch-all-error-p result))
       )
   )
)
(vl-load-com)

As I understand, the active drawing after the line including:

(setq result (vl-catch-all-apply 'vlax-invoke (list shell 'open target)))

will be the opened file, so the following lines:

(vlax-release-object shell)
(not (vl-catch-all-error-p result))

can't be done, for forgetting shell and result values.

 

..., or I am wrong?

Link to comment
Share on other sites

Ahankhah,

 

As I am new to this method of open a drawing also (I typically use the Document's Collection + Activate Method), if I understand correctly, Lee is employing the Shell.Application Object to open the drawing outside of AutoCAD (think double click in Windows Explorer), which allows for the code to release the Object within the Document that called. This code itself is quite brilliant in that way.

 

I am still attempting to determine if I am able to properly use this methodology, as we have 3+ version years (and vertical/non-vertical flavors of each) installed at any given time.

 

HTH

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