Toggle between drawings?

Discussion in 'AutoCAD' started by Rudy Tovar, Feb 18, 2005.

  1. Rudy Tovar

    Rudy Tovar Guest

    Anyone written a toggle between drawings?

    I'd rather not use the mouse or 'Docbar'.

    Via the command line, (make active dwg)...
     
    Rudy Tovar, Feb 18, 2005
    #1
  2. have you tried CTRL-TAB keys
     
    Alan Henderson @ A'cad Solutions, Feb 18, 2005
    #2
  3. Rudy Tovar

    Rudy Tovar Guest

    Between 2 drawings, within the same directory, ignoring the any previous
    selected dwg.

    If open by you just make current active drawing...
     
    Rudy Tovar, Feb 18, 2005
    #3
  4. Rudy Tovar

    Rudy Tovar Guest

    If you're talking about switching between layers within the same drawing...
    nope...

    Between drawings in the same directory...

    Example...

    (defun c:next (/ files p file)
    (setq files (vl-directory-files (getvar "dwgprefix") "*.dwg"))
    (if files
    (progn
    (setq files (vl-sort files '<)
    p (vl-position (getvar "dwgname") files)
    )
    (if p
    (setq p (1+ p)
    file (nth p files)
    )
    )
    (if file
    (command
    "vbastmt"
    (strcat
    "AcadApplication.Documents.Open "
    (chr 34)
    (strcat (getvar "dwgprefix") file)
    (chr 34)
    )
    )
    )
    )
    )
    (princ)
    )

    This handles opening the next drawing in a directory...BUT...what if it's
    already open (By you and only you)...make it active without using Ctrl+tab
    and work visaversa...
     
    Rudy Tovar, Feb 18, 2005
    #4
  5. Rudy Tovar

    Jürg Menzi Guest

    Hi Rudy

    Not sure, but maybe is this what you are looking for...
    Visit my homepage -> Free Stuff and search for 'VxScrollDocs'.

    Cheers
     
    Jürg Menzi, Feb 18, 2005
    #5
  6. Rudy Tovar

    T.Willey Guest

    Maybe something like.

    (setq AcadObj (vla-get-Acad-Object))
    (setq DocCol (vla-get-Documents AcadObj))
    (setq ErrChk (vl-catch-all-apply 'vla-Item (list DocCol file)))
    (if (not (vl-catch-all-error-p ErrChk))
    (vla-put-ActiveDocument AcadObj ErrChk)
    <other wise open drawing here>
    )

    Tim
     
    T.Willey, Feb 18, 2005
    #6
  7. Hi Rudy,

    See if this code could help you...
    Code:
    (vl-load-com)
    
    (defun thisDwg	()
    (vla-get-activeDocument (vlax-get-acad-object)))
    
    (defun thaw-unLock-turnOn  (vla_layer)
    (if (/= (vla-get-freeze vla_layer) :vlax-false)
    (vla-put-freeze vla_layer :vlax-false))
    (if (= (vla-get-lock vla_layer) :vlax-true)
    (vla-put-lock vla_layer :vlax-false))
    (if (/= (vla-get-layerOn vla_layer) :vlax-true)
    (vla-put-layerOn vla_layer :vlax-true)))
    
    (defun open-dwg	 (fullfilename)
    (setvar "cmdecho" 0)
    (vl-cmdf "._vbastmt"
    (strcat "AcadApplication.Documents.Open \""
    fullfilename
    "\""))
    (setvar "cmdecho" 1)
    (princ))
    
    (defun rcmd-active-dwg	(fName / docs)
    (vlax-for doc	 (vla-get-documents (vlax-get-acad-object))
    (setq docs (cons doc docs)))
    (not
    (vl-catch-all-error-p
    (vl-catch-all-apply
    'vla-put-activeDocument
    (list
    (vlax-get-acad-object)
    (vl-some
    (function (lambda (item)
    (if (eq (vla-get-fullName item) fName)
    item)))
    docs))))))
    
    (defun file-open  (file / fd)
    (if (setq fd (open (findFile file) "a"))
    (close fd)
    T))
    
    (defun layer-exist?  (layer_name / return_obj)
    (if (not
    (vl-catch-all-error-p
    (setq	return_obj
    (vl-catch-all-apply
    'vla-item
    (list (vla-get-layers (thisDwg))
    layer_name)))))
    return_obj
    nil))
    
    (defun add-layer  (layer_name / return_obj)
    (cond
    ;; add the layer
    ((and (not (layer-exist? layer_name))
    (not
    (vl-catch-all-error-p
    (setq
    return_obj
    (vl-catch-all-apply
    'vla-add
    (list (vla-get-layers (thisDwg))
    layer_name))))))
    ;; make accessible the layer
    (thaw-unLock-turnOn return_obj)
    return_obj)
    ;; the layer exist
    ((progn
    ;; make accessible the layer
    (thaw-unLock-turnOn (layer-exist? layer_name))
    ;; return the layer object
    (layer-exist? layer_name)))))
    
    (defun C:OXREF	(/ ent obj fName status)
    (if
    (and (setq ent (car (entSel "\nOpen xref block: ")))
    (setq obj (vlax-ename->vla-object ent))
    (eq (type obj) 'VLA-OBJECT)
    (vlax-property-available-p obj 'Path)
    (setq fName (findFile (vlax-get-property obj 'Path)))
    (/= fName "")
    (not (setq status (file-open fName)))
    (zerop (getVar "SDI")))
    (progn
    
    (thaw-unLock-turnOn (add-layer (vla-get-layer obj)))
    
    ;; propagate the variable to all the possible documents
    (vl-bb-set
    ':rcm_previous_dwg
    (strcat (getVar "dwgprefix") (getVar "dwgname")))
    
    ;; open the drawing
    (open-dwg fName))
    
    (prompt "\nNot an xref, Try again. \n"))
    
    (if (and status fName (zerop (getVar "SDI")))
    (progn
    
    (vl-bb-set
    ':rcm_previous_dwg
    (strcat (getVar "dwgprefix") (getVar "dwgname")))
    
    ;; if is already open then activated
    (rcmd-active-dwg fName)))
    (princ))
    
    
    ;;; go back to previous drawing
    (defun C:PDWG  (/ previous_dwg)
    (if (setq previous_dwg (vl-bb-ref ':rcm_previous_dwg))
    (progn
    
    ;; make the drawing variable nil in all the possible documents
    (vl-bb-set ':rcm_previous_dwg nil)
    (vl-bb-set ':rcm_no_glass_hour t)
    
    (prompt "\nNow, Returning to previous drawing. ")
    
    (rcmd-active-dwg previous_dwg))
    (prompt "\nThis is the previous drawing. "))
    (princ))
    
     
    Luis Esquivel, Feb 18, 2005
    #7
  8. Rudy Tovar

    Rudy Tovar Guest

    I'll give it a wirl....
     
    Rudy Tovar, Feb 18, 2005
    #8
  9. Rudy Tovar

    Rudy Tovar Guest

    I'll take a look...
     
    Rudy Tovar, Feb 18, 2005
    #9
  10. Rudy Tovar

    Rudy Tovar Guest

    Thanks Luis, I'm assuming it's part of another utility, and I'll chop up to
    do what I need...

    But, I believe T.Willey addressed it...


     
    Rudy Tovar, Feb 18, 2005
    #10
  11. Rudy Tovar

    Gary Fowler Guest

    This one is the best....uses the drawings preview image.
    Works with 2005.

    Gary

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    + CADwerx DocBar 1.1 (build 66) LOADED
    +
    + Copyright © 2003 CADwerx (http://www.cadwerx.net)
    +
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    + Registered commands :
    +
    + DOCBAR - Toggles DocBar drawing selection toolbar
    +
    + DOCBARON - Shows DocBar drawing selection toolbar
    +
    + DOCBAROFF - Hides DocBar drawing selection toolbar
    +
    + DBCENTER - Floats and centers the toolbar on screen
    +
    + DBABOUT - Displays the DocBar 'About' Dialog
    +
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     
    Gary Fowler, Feb 18, 2005
    #11
  12. Rudy Tovar

    Gary Fowler Guest

    Sorry, I should have read your post better.
    Here is what I use at the command line:

    Gary

    ;;;The NEXT.LSP function that opens the next drawing in a directory.
    ;;;http://www.cad-code.com/archive.htm
    ;;;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-E "MsgBox \"Error: You are in the last\nDrawing in this
    Directory!\"")
    )
    (prin1)
    (if objDwg
    (progn
    (setq acadObject (vlax-get-acad-object))
    (vlax-put-property acadObject 'Activedocument objDWG)
    )
    )
    )
    (defun C:NEXT ()
    (NEXT-IT)
    )
    (defun C:NEXT2 ()
    (ARCH:Close_All)
    (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)))
    )
    (if (< CNT (length FILELIST))
    (progn
    (setq NEXTDWG (strcat (getvar "dwgprefix") (nth (- CNT 2) FILELIST)))
    (if (IsItOpen NEXTDWG)
    (princ)
    (command "vbastmt" (strcat "AcadApplication.Documents.Open \"" NEXTDWG
    "\""))
    )
    )
    (ARCH:ALERT-E "MsgBox \"Error: You are in the last\nDrawing in this
    Directory!\"")
    )
    (prin1)
    (if objDwg
    (progn
    (setq acadObject (vlax-get-acad-object))
    (vlax-put-property acadObject 'Activedocument objDWG)
    )
    )
    )

    (defun C:pREV ()
    (PREV-IT)
    )
    (defun C:pREV2 ()
    (ARCH:Close_All)
    (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
    )
    ;;;Here is another one that will close all open documents except the current
    one.
    ;;;Peter Jamtgaard
    (defun ARCH:Close_All (/ CLOSE1 FULL)
    (vl-load-com)
    (vlax-for
    DOCOBJ (vla-get-documents (vlax-get-acad-object))
    (setq FULL (strcat (vla-get-path DOCOBJ) "\\" (vla-get-name DOCOBJ)))
    (if (= (vla-get-active DOCOBJ) :vlax-false)
    (if (vl-catch-all-error-p
    (vl-catch-all-apply
    '(lambda (X) (vla-close X :vlax-true FULL))
    (list DOCOBJ)))
    (princ (strcat "\nCan not close drawing "
    FULL
    " with active command in progress:")))))
    (princ))
     
    Gary Fowler, Feb 18, 2005
    #12
  13. Rudy Tovar

    Rudy Tovar Guest

    Seems a bit of an overkill...

    Can be condensed...just the same, thank you for your direction also...
     
    Rudy Tovar, Feb 18, 2005
    #13
  14. Rudy Tovar

    Anne Brown Guest

    Gary -

    The lisp below is copyright. Do you have permission to post it?
    If not, I'll remove. Please reply either way.
     
    Anne Brown, Feb 18, 2005
    #14
  15. Rudy Tovar

    Gary Fowler Guest

    I was not posting the lisp, just their web site

    Gary
     
    Gary Fowler, Feb 21, 2005
    #15
  16. Rudy Tovar

    Anne Brown Guest

    My apologies! I was reading too fast.
    ---
    Anne Brown
    Discussion Groups Administrator
    Autodesk, Inc.


    Anne
     
    Anne Brown, Feb 21, 2005
    #16
  17. Rudy Tovar

    T.Willey Guest

    The code posted is what I came up with. It works fine except for one thing. When the next drawing is opened, it switches to it, but then the original drawing is still waiting for something. I have this code to close drawings without going into them to do it, but it won't work on the drawings that I run my code in when the next drawing is open.

    Anyone have any ideas why? because I have no clue.

    Thanks.
    Tim

    (defun c:Next (/ AcadObj DocCol DirPath DwgList Pos Dwg DwgFile ErrChk Opt)
    ; Opens/Makes-active next drawing in the directory.

    (setq AcadObj (vlax-get-Acad-Object))
    (setq DocCol (vla-get-Documents AcadObj))
    (setq DirPath (getvar "dwgprefix"))
    (setq DwgList (vl-directory-files DirPath "*.dwg"))
    (setq DwgList (vl-sort DwgList '<))
    (setq Pos (vl-position (getvar "dwgname") DwgList))
    (if (setq Dwg (nth (1+ Pos) DwgList))
    (progn
    (setq DwgFile (strcat DirPath Dwg))
    (setq ErrChk (vl-catch-all-apply 'vla-Item (list DocCol Dwg)))
    (if (vl-catch-all-error-p ErrChk)
    (progn
    (if
    (and
    (= (getvar "sdi") 1)
    (/= (getvar "dbmod") 0)
    )
    (progn
    (initget "Y N")
    (setq Opt (getkword "\n Drawing has changed. Save changes before exiting drawings? <Y> "))
    (if (not Opt)
    (setq Opt "Y")
    )
    (vl-cmdf "_.vbastmt" (strcat "AcadApplication.Documents.Open \"" DwgFile "\""))
    (command Opt)
    )
    (vl-cmdf "_.vbastmt" (strcat "AcadApplication.Documents.Open \"" DwgFile "\""))
    )
    )
    (vla-Activate ErrChk)
    )
    )
    (alert "\n This is the last drawing in this folder.")
    )
    (princ)
    )
     
    T.Willey, Feb 21, 2005
    #17
  18. LISP is limited to the document it is called from.
    The calling document will have to be set active
    again to allow the code to complete.
     
    Jason Piercey, Feb 22, 2005
    #18
  19. Rudy Tovar

    T.Willey Guest

    So there is not way to switch to a new document that is open already and have the lisp end? Dang. I understand that, but was hoping there was a way.

    Thanks for the clarification.
    Tim
     
    T.Willey, Feb 22, 2005
    #19
  20. I think this is as close as you can get.

    (command "vbastmt" "documents.item(documents.count-1).activate")

    I use that for my drawing setup routine, which adds
    a document to the collection then activates it. The
    drawback is you can't get rid of the focus switching.


    --
    Autodesk Discussion Group Facilitator



    have the lisp end? Dang. I understand that, but was hoping there was a
    way.
     
    Jason Piercey, Feb 22, 2005
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.