Whats the process for figuring found path of xref when xref has no path?

Discussion in 'AutoCAD' started by James Maeding, Jul 26, 2004.

  1. I have drawings with xrefs that have no paths.
    I am writing routines that need to figure out for each xref what the "found at" path is so I can hardcode that path or
    simply use it to make scripts that purge drawings.
    I plan to do it in this order:

    1) Look in project path (if any)
    2) Look in current drawing's folder
    3) Look in Support Paths
    4) Look in "Start In" Folder (not sure how to get this folder name...)

    Does that look right? Should I change the order on any of this?
    Feel free to point me to another thread if this is an old issue...
    thanks
    James Maeding
    Civil Engineer/Programmer
     
    James Maeding, Jul 26, 2004
    #1
  2. James Maeding

    no.name Guest

    it is buried in here somewhere :



    (DEFUN JM:xreflir
    (lock-mode
    insertion-mode
    rotation-mode
    /
    *acad-object*
    *activedocument*
    JM:acad-object
    JM:activedocument
    JM:get-layers
    JM:get-blocks
    JM:rtd
    JM:layerthaw
    JM:layerunlock
    JM:layeron
    JM:layeradd
    JM:lockmode
    JM:insertionmode
    JM:rotationmode
    sset
    sset-count
    sset-index
    entityname
    xref-obj
    xref-name
    xref-layer
    )
    ;| |;
    (VL-LOAD-COM)
    (SETQ *acad-object* nil)
    (SETQ *activedocument* nil)
    (DEFUN JM:acad-object () (SETQ *acad-object* (VLAX-GET-ACAD-OBJECT)))
    (DEFUN JM:activedocument ()
    (SETQ *activedocument* (VLA-GET-ACTIVEDOCUMENT (JM:acad-object)))
    )
    (DEFUN JM:get-layers () (VLA-GET-LAYERS (JM:activedocument)))
    (DEFUN JM:get-blocks () (VLA-GET-BLOCKS (JM:activedocument)))
    (DEFUN JM:rtd (radian) (* 180 (/ radian PI)))
    (DEFUN JM:layerthaw (layername / layer)
    (SETQ layer (VLA-ITEM (JM:get-layers) layername))
    (IF (= :VLAX-TRUE (VLAX-GET-PROPERTY layer "freeze"))
    (PROGN (VLAX-PUT-PROPERTY layer "freeze" :VLAX-FALSE)
    (VLA-REGEN (JM:activedocument) ACALLVIEWPORTS)
    )
    )
    )
    (DEFUN JM:layerunlock (layername / layer)
    (SETQ layer (VLA-ITEM (JM:get-layers) layername))
    (IF (= :VLAX-TRUE (VLAX-GET-PROPERTY layer "lock"))
    (VLAX-PUT-PROPERTY layer "lock" :VLAX-FALSE)
    )
    )
    (DEFUN JM:layeron (layername / layer)
    (SETQ layer (VLA-ITEM (JM:get-layers) layername))
    (IF (= :VLAX-FALSE (VLAX-GET-PROPERTY layer "layeron"))
    (VLAX-PUT-PROPERTY layer "layeron" :VLAX-TRUE)
    )
    )
    (DEFUN JM:layeradd (layername)
    (IF (NOT (TBLSEARCH "layer" layername))
    (VLA-ADD (JM:get-layers) layername)
    )
    )
    (DEFUN JM:lockmode (layername)
    (IF lock-mode
    (VLAX-PUT-PROPERTY (VLA-ITEM (JM:get-layers) layername) "lock"
    :VLAX-TRUE)
    (VLAX-PUT-PROPERTY (VLA-ITEM (JM:get-layers) layername) "lock"
    :VLAX-FALSE)
    )
    )
    (DEFUN JM:insertionmode (xref / objinsertionpoint variantvalue point
    sa-make sa-fill sa)
    (IF insertion-mode
    (PROGN (SETQ objinsertionpoint (VLAX-GET-PROPERTY xref
    'insertionpoint))
    (SETQ variantvalue (VLAX-VARIANT-VALUE objinsertionpoint))
    (SETQ point (VLAX-SAFEARRAY->LIST variantvalue))
    (IF (NOT (EQ point '(0.0 0.0 0.0)))
    (PROGN (SETQ sa-make (VLAX-MAKE-SAFEARRAY VLAX-VBDOUBLE '(0 .
    2)))
    (SETQ sa-fill (VLAX-SAFEARRAY-FILL sa-make '(0 0 0)))
    (VLAX-SAFEARRAY->LIST sa-fill)
    (SETQ sa (VLAX-MAKE-VARIANT sa-fill))
    (VLAX-PUT-PROPERTY xref 'insertionpoint
    (VLAX-MAKE-VARIANT sa))
    )
    )
    )
    )
    )
    (DEFUN JM:rotationmode (xref / objrotation)
    (IF rotation-mode
    (PROGN (SETQ objrotation (VLAX-GET-PROPERTY xref 'rotation))
    (IF (/= 0 (JM:rtd objrotation))
    (VLAX-PUT-PROPERTY xref 'rotation 0)
    )
    )
    )
    )
    ;| main |;
    (VLA-STARTUNDOMARK (JM:activedocument))
    (VLAX-FOR each (JM:get-blocks) ;| |;
    (IF (= (VLA-GET-ISXREF each) :VLAX-TRUE) ;| |;
    (IF ;| if ssget is successful, xref is not nested |;
    (SETQ sset (SSGET "X" (LIST (CONS 0 "INSERT") (CONS 2 (VLA-GET-NAME
    each))))) ;| get selection set of xref |;
    (PROGN (SETQ sset-count (1- (SSLENGTH sset))) ;| -1 the length
    cause first index in sset is 0 |;
    (SETQ sset-index 0) ;| first in sset |;
    (WHILE (<= sset-index sset-count) ;| while index is <= count
    |;
    (PROGN ;| |;
    (SETQ entityname (SSNAME sset sset-index)) ;| entity
    name |;
    (SETQ xref-obj (VLAX-ENAME->VLA-OBJECT (SSNAME sset
    sset-index))) ;| convert to vla |;
    (SETQ xref-name (STRCASE (VLAX-GET-PROPERTY xref-obj
    'name))) ;| get name of xref |;
    (SETQ xref-layer (STRCASE (VLAX-GET-PROPERTY xref-obj
    'layer))) ;| get xrefs current layername |;
    (IF (/= xref-name xref-layer) ;| if xrefs name does not
    equal layername |;
    (PROGN ;(PRINC " xref name & layer name NOT equal
    \n\n")
    (PRINC)
    ;;; (JM:layerthaw xref-layer) ;| thaw xrefs current
    layer |;
    ;;; (JM:layeron xref-layer) ;| turn on xrefs current
    layer |;
    ;;; (JM:layerunlock xref-layer) ;| unlock xrefs
    current layer |;
    ;;; (JM:layeradd xref-name) ;| add new layer if
    needed |;
    ;;; (JM:layerunlock xref-name) ;| make sure xrefs new
    layer is unlocked |;
    ;;; (VLAX-PUT-PROPERTY xref-obj 'layer xref-name) ;|
    put xref on its new named layer |;
    ;;; (JM:insertionmode xref-obj) ;| check insertion
    point |;
    ;;; (JM:rotationmode xref-obj) ;| check rotation |;
    ;;; (JM:lockmode xref-name) ;| lock/unlock xrefs
    layer |;
    );| end PROGN |;
    (PROGN ;(PRINC " xref name & layer name EQUAL
    \n\n")
    (JM:layerthaw xref-layer) ;| thaw xrefs current
    layer |;
    (JM:layeron xref-layer) ;| turn on xrefs current
    layer |;
    (JM:layerunlock xref-layer) ;| unlock xrefs current
    layer |;
    (JM:insertionmode xref-obj) ;| check insertion point
    |;
    (JM:rotationmode xref-obj) ;| check rotation |;
    (JM:lockmode xref-name) ;| lock/unlock xrefs layer
    |;
    ) ;| end PROGN |;
    ) ;| end IF |;
    ) ;| end PROGN |;
    (SETQ sset-index (1+ sset-index)) ;| increment index |;
    ) ;| end WHILE |;
    ) ;| end PROGN |;
    ;(PRINC (STRCAT (VLA-GET-NAME each) " is NESTED xref \n")) ;| if ssget is
    not successful, xref is nested |;
    );| end IF |;
    ) ;| end IF |;
    ) ;| end VLAX-FOR |;
    (VLA-ENDUNDOMARK (JM:activedocument))
    (PRINC)
    ) ;| end DEFUN |;


    (DEFUN c:xr-layer ()
    (JM:xreflir nil nil nil)
    )
    ;;;(PRINC "\n\n ' XR-LAYER ' xrefs to named layer")

    (DEFUN c:xr-rot ()
    (JM:xreflir nil nil T)
    )
    ;;;(PRINC "\n\n ' XR-ROT ' xrefs to zero rotation")

    (DEFUN c:xr-ins-rot ()
    (JM:xreflir nil T T)
    )
    ;;;(PRINC "\n\n ' XR-INS-ROT ' xrefs to 0,0,0 & zero rotation ")

    (DEFUN c:xr-lock-ins-rot ()
    (JM:xreflir T T T)
    )
    ;;;(PRINC "\n\n ' XR-LOCK-INS-ROT ' xrefs to locked layer, 0,0,0, & zero
    rotation")

    (DEFUN c:xr-lock-ins ()
    (JM:xreflir T T nil)
    )
    ;;;(PRINC "\n\n ' XR-LOCK-INS ' xrefs to locked layer & 0,0,0")

    (DEFUN c:xr-lock ()
    (JM:xreflir T nil nil)
    )
    ;;;(PRINC "\n\n ' XR-LOCK ' xrefs to locked layer")

    (DEFUN c:xr-ins ()
    (JM:xreflir nil T nil)
    )
    ;;;(PRINC "\n\n ' XR-INS ' xrefs to 0,0,0")

    (PRINC)
     
    no.name, Jul 26, 2004
    #2
  3. James Maeding

    Jim Claypool Guest

    (findfile "XREFNAME.dwg") will look through the support path for you. It
    will return the first one it finds, which is also the one it attached.

    "found at" path is so I can hardcode that path or
     
    Jim Claypool, Jul 26, 2004
    #3
  4. James Maeding

    John Uhden Guest

    James:

    If there is no saved path then check the host drawing's folder first <I think>.




    at" path is so I can hardcode that path or
     
    John Uhden, Jul 27, 2004
    #4
  5. James Maeding

    Joe Burke Guest

    James,

    This might be of interest.

    Joe Burke

    ;; If an xref is not found in the saved path AutoCAD searches
    ;; the whole support path. By Stephan Koster 2001
    (defun get-xref-path (blockname / data path saved_path pos)
    (cond ((not (setq data (tblsearch "block" blockname))))
    ;; Does the block exist
    ((/= (logand (cdr (assoc 70 data)) 4) 4))
    ;; Is it an xref
    ((and (setq saved_path (cdr (assoc 1 data)))
    (setq path (findfile saved_path))
    ;; Can it be found on the saved path
    )
    )
    ((not (setq pos (vl-string-position (ascii "\\") saved_path 1 T))))
    (T (setq path (findfile (substr saved_path (+ pos 2)))))
    ;; Can it be found somewhere else in the search path
    )
    path
    )

    path is so I can hardcode that path or
     
    Joe Burke, Jul 27, 2004
    #5
  6. One minor thing is that I am doing the path figuring dbx style. So I have to figure out what the drawings project path
    is, if any, and reconstruct what would have been that drawings search paths.
    This is something I am guessing the Cad FX guys are pro's at (seeing their XFiler program...), maybe they can chime in.
    thanks all

    James Maeding <>
    |>I have drawings with xrefs that have no paths.
    |>I am writing routines that need to figure out for each xref what the "found at" path is so I can hardcode that path or
    |>simply use it to make scripts that purge drawings.
    |>I plan to do it in this order:
    |>
    |>1) Look in project path (if any)
    |>2) Look in current drawing's folder
    |>3) Look in Support Paths
    |>4) Look in "Start In" Folder (not sure how to get this folder name...)
    |>
    |>Does that look right? Should I change the order on any of this?
    |>Feel free to point me to another thread if this is an old issue...
    |>thanks
    |>James Maeding
    |>Civil Engineer/Programmer

    James Maeding
    Civil Engineer/Programmer
     
    James Maeding, Jul 30, 2004
    #6
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.