Author Topic: How to set a drawing to be Active Document in Vlisp?  (Read 2944 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Guest
How to set a drawing to be Active Document in Vlisp?
« on: October 17, 2006, 02:06:51 PM »
Hello there,

How can I set a drawing ( it is already open) to be the active one?

Thanks in Advance,

Bernd

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to set a drawing to be Active Document in Vlisp?
« Reply #1 on: October 17, 2006, 02:12:30 PM »
Find it in the document collection, and then use the 'Activate' method on it.  One this is that your lisp will still be waiting to end in the previous drawing, so I would use a VBA statement.  Here is an example I have to switch to the next drawing in the document collection.
Code: [Select]
(defun c:NextInDocManager (/ DocCol ActDoc CurName cnt)

(setq DocCol (vla-get-Documents (vlax-get-Acad-Object)))
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq CurName (vla-get-Name ActDoc))
(setq cnt 0)
(vl-catch-all-apply
 '(lambda ()
  (vlax-for i DocCol
   (if (= (vla-get-Name i) CurName)
    (exit)
    (setq cnt (1+ cnt))
   )
  )
 )
)
(if (>= (1+ cnt) (vla-get-Count DocCol))
 (alert "\n This IS the last drawing in document collection.")
 (command "_.vbastmt" (strcat "documents.item \(\"" (vla-get-Name (vla-Item DocCol (1+ cnt))) "\"\).activate"))
)
(princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Amsterdammed

  • Guest
Re: How to set a drawing to be Active Document in Vlisp?
« Reply #2 on: October 17, 2006, 08:52:13 PM »
Tim,
Thanks for your Help. :-)

 But should I be able to continue in the desired drawing with lisp when using the VBA statement? That doesn't work in my case. :cry:

Bernd

T.Willey

  • Needs a day job
  • Posts: 5251
Re: How to set a drawing to be Active Document in Vlisp?
« Reply #3 on: October 18, 2006, 11:09:17 AM »
Nope.  Lisp will only work in the drawing it is called in, unless you have sdi = 1, and lispinit = 0.  Plus, I think, that the VBA statement has to be the last thing in the lisp code.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: How to set a drawing to be Active Document in Vlisp?
« Reply #4 on: October 18, 2006, 12:23:30 PM »
Maybe this will work for you?

Code: [Select]
;;;The NEXT.LSP function that opens the next drawing in a directory.
;;;http://www.cad-code.com/archive.htm
;;;by: Peter Jamtgaard

(defun NEXT-IT  (/ CNT FILELIST NEXTDWG objDWG acadObject)
  (vl-load-com)
  (setq FILELIST (acad_strlsort (vl-directory-files (getvar "dwgprefix") "*.dwg"))
        CNT      (length (member (getvar "dwgname") (reverse FILELIST))))
  (if (< CNT (length FILELIST))
    (progn (setq NEXTDWG (strcat (getvar "dwgprefix") (nth CNT FILELIST)))
           (if (IsItOpen NEXTDWG)
             (princ)
             (command
               "vbastmt"
               (strcat "AcadApplication.Documents.Open \"" NEXTDWG "\""))))
    (ARCH:ALERT-I
      "MsgBox \"
     Open Next Drawing Message
--------------------------------------------------------------------------------------------
     You already are in the Last Drawing of this Directory!\""))
  (prin1)
  (if objDwg
    (progn (setq acadObject (vlax-get-acad-object))
           (vlax-put-property acadObject 'Activedocument objDWG))))
(defun NEXTIT () (NEXT-IT))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun PREV-IT  (/ CNT FILELIST NEXTDWG objDWG acadObject)
  (vl-load-com)
  (setq FILELIST (acad_strlsort (vl-directory-files (getvar "dwgprefix") "*.dwg"))
        CNT      (length (member (getvar "dwgname") (reverse FILELIST))))
  (cond
    ((= CNT 1)
     (ARCH:ALERT-I
       "MsgBox \"
     Open Previous Drawing Message
--------------------------------------------------------------------------------------------
     You are already in the First Drawing of this Directory!\"")))
  ((< CNT (length FILELIST))
    (progn (setq NEXTDWG (strcat (getvar "dwgprefix") (nth (- CNT 2) FILELIST)))
           (if (IsItOpen NEXTDWG)
             (princ)
             (command
               "vbastmt"
               (strcat "AcadApplication.Documents.Open \"" NEXTDWG "\"")))))
  (prin1)
  (if objDwg
    (progn (setq acadObject (vlax-get-acad-object))
           (vlax-put-property acadObject 'Activedocument objDWG))))

(defun PREVIT () (PREV-IT))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;IsItOpen by Bill Kramer
(defun IsItOpen  (DwgName / DWGS DWG Flag)
  (setq DWGS (vlax-get-property (vlax-get-acad-object) "Documents"))
  (setq objDWG nil)
  (vlax-for
         DWG  DWGS
    (if (or (= (strcase (vlax-get-property DWG "Name")) (strcase DwgName))
            (= (strcase (vlax-get-property DWG "FullName")) (strcase DwgName)))
      (progn (setq objDWG DWG) (setq Flag 'T))))
  Flag)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64