Author Topic: Xref Path  (Read 4322 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Xref Path
« on: December 19, 2005, 12:15:26 PM »
according to the AutoCAD help file the dxf code for xref path name is 1.

But when I try the following code with an Xref attached i get nil, what's wrong with my code?

Code: [Select]
(setq @ss (ssget "x" '((1 . "insert"))))
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

LE

  • Guest
Re: Xref Path
« Reply #1 on: December 19, 2005, 12:32:53 PM »
according to the AutoCAD help file the dxf code for xref path name is 1.

But when I try the following code with an Xref attached i get nil, what's wrong with my code?

Code: [Select]
(setq @ss (ssget "x" '((1 . "insert"))))

Are you trying to make a selection base on the path, directly from the ssget?.... as far as I know is not possible...

To extract the value of the path, one way is by:

Code: [Select]
(assoc 1 (tblsearch "block" (cdr (assoc 2 (entget ename)))))

Where ename is the insert entity.

hudster

  • Gator
  • Posts: 2848
Re: Xref Path
« Reply #2 on: December 21, 2005, 01:06:40 PM »
I'm still trying to get to grips with entity extraction, so how would I get the associated xref path as a string from the drawing.

I've tried a few things and all I get is errors.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

LE

  • Guest
Re: Xref Path
« Reply #3 on: December 21, 2005, 01:13:21 PM »
I'm still trying to get to grips with entity extraction, so how would I get the associated xref path as a string from the drawing.

I've tried a few things and all I get is errors.

One way is to make a test command ie:

Code: [Select]
(defun C:TEST()
(if (setq ename (car (entsel "\nSelect an xref: ")))
(assoc 1 (tblsearch "block" (cdr (assoc 2 (entget ename)))))))

nivuahc

  • Guest
Re: Xref Path
« Reply #4 on: December 21, 2005, 01:35:12 PM »
Not what (I think) you're looking for but maybe it is

Code: [Select]
;; 2005 by Michael Puckett

(defun GetXrefPath ( ename / object )
    (cond
        (   (and
                (eq 'ename (type ename))
                (eq "AcDbBlockReference"
                    (vla-get-objectname
                        (setq object
                            (vlax-ename->vla-object
                                ename
                            )
                        )
                    )   
                )
                (vlax-property-available-p object 'path)
            )
            (vla-get-path object)
        )   
    )
)

nivuahc

  • Guest
Re: Xref Path
« Reply #5 on: December 21, 2005, 01:44:35 PM »
Also not what you're looking for but, with your abilities, I'm certain you can take something from both of these to get what you're after

Code: [Select]
;*********************************************************************************
; Function to build a list of available blocks
;*********************************************************************************
(defun BuildBlockList (/ BlockItem)
  (setq BlockList nil)
  (setq BlockItem (tblnext "BLOCK" T))

  (while (/= BlockItem nil)
    (setq BlockList
   (append BlockList
   (list (cdr (assoc 2 BlockItem))
;; Name
   ) ;_end list
   ) ;_end append
    ) ;_end setq BlockList
    (setq BlockItem (tblnext "BLOCK"))
  ) ;_end while
  (princ)
) ;_end defun BuildBlockList

LE

  • Guest
Re: Xref Path
« Reply #6 on: December 21, 2005, 02:07:48 PM »
I'm still trying to get to grips with entity extraction, so how would I get the associated xref path as a string from the drawing.

I've tried a few things and all I get is errors.

Hudster;

Here is one of my old commands way before they come up with XOPEN .... anyways, hope it will served as an example:

Code: [Select]
(vl-load-com)

(defun thisDwg ()
  (vla-get-activeDocument (vlax-get-acad-object)))

(defun file-open  (file / fd)
  (if (setq fd (open (findFile file) "a"))
    (close fd)
    T))

(defun thaw-unLock-turnOn  (vla_layer)
  ;; thaw
  (if (/= (vla-get-freeze vla_layer) :vlax-false)
    (vla-put-freeze vla_layer :vlax-false))
  ;; unlock
  (if (= (vla-get-lock vla_layer) :vlax-true)
    (vla-put-lock vla_layer :vlax-false))
  ;; turn on
  (if (/= (vla-get-layerOn vla_layer) :vlax-true)
    (vla-put-layerOn vla_layer :vlax-true)))

(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 open-dwg (fullfilename)
  (setvar "cmdecho" 0)
  (vl-cmdf
    "._vbastmt"
    (strcat "AcadApplication.Documents.Open \""
    fullfilename
    "\""))
  (setvar "cmdecho" 1)
  (princ))

(defun 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 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
       ;; unlock the layer the block is on
       (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 xref 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
      (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. ")
      ;; set active the previous drawing
      (active-dwg previous_dwg))
    (prompt "\nThis is the previous drawing. "))
  (princ))

(princ)

Have fun !

nivuahc

  • Guest
Re: Xref Path
« Reply #7 on: December 21, 2005, 02:26:05 PM »
Hudster,

I *think* what you are asking is how to get the path of an Xref without selecting it. Or how to get all of the Xrefs in a drawing along with the path of each.

The two bits of code I posted do two different things. The first bit of code (Thanks MP!) returns the path of an Xref. The second bit creates a list of all of the blocks in a drawing.

Neither one requires you to select anything though the first one does require an entity to check. So, in my mind, what you want to do is flip through all of the blocks in a drawing and see which ones are Xrefs and find out the path of each.

There's probably a much more efficient way but that's the first thing I thought of when I read this thread. Anyway, normal blocks in a drawing don't have a path. So a little conditional test of each block in the drawing should give you the results you're looking for.

hudster

  • Gator
  • Posts: 2848
Re: Xref Path
« Reply #8 on: December 23, 2005, 06:59:30 AM »
What I'm trying, (very badly),  to do is extract the xref path and filename as a string and have it printed at 0,0 in model space.

the code by LE does what I need it to, all I need to to refine it to auto get the paths, but that shouldn't be too difficult.

I still think it would be easier if I could get my head round entity extractions, it's getting easier, just very slowly.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

whdjr

  • Guest
Re: Xref Path
« Reply #9 on: December 23, 2005, 09:12:29 AM »
Hudster,

Have you tried a field for this?  Also the 'eattext' command has a nice Wizard that really is pretty cool.  Check it out and see if it will help you.

hudster

  • Gator
  • Posts: 2848
Re: Xref Path
« Reply #10 on: January 10, 2006, 11:20:48 AM »
I can't use fields for this as we have pre 2004 versions of autoCAD in use, so It has to be by lisp.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

GDF

  • Water Moccasin
  • Posts: 2081
Re: Xref Path
« Reply #11 on: January 10, 2006, 07:45:20 PM »
Here is some code you might find usefull. It is not a standalone routine at this time.

I use it to list and tabulate and control xrefs.

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Xref Path
« Reply #12 on: January 11, 2006, 11:27:30 AM »
Here is one I wrote.
Code: [Select]
(defun Testing (/ Doc LayoutCol EndList)
; Returns a list of list of all the Xrefs and Images with their paths within a drawing.

(setq Doc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq LayoutCol (vla-get-Layouts Doc))
(vlax-for i LayoutCol
 (vlax-for Obj (vla-get-Block i)
(cond
((= (vla-get-ObjectName Obj) "AcDbRasterImage")
(if (not (assoc (vla-get-Name Obj) EndList))
(setq EndList (cons (cons (vla-get-Name Obj) (vla-get-ImageFile Obj)) EndList))
)
)
((and (= (vla-get-ObjectName Obj) "AcDbBlockReference") (vlax-property-available-p Obj 'Path))
(if (not (assoc (vla-get-Name Obj) EndList))
(setq EndList (cons (cons (vla-get-Name Obj) (vla-get-Path Obj)) EndList))
)
)
)
 )
)
EndList
)
Tim

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

Please think about donating if this post helped you.

KewlToyZ

  • Guest
Re: Xref Path
« Reply #13 on: May 02, 2006, 04:54:49 PM »
Thanks Gary!
This may have the answer I've been looking for. Thank you for the share!
Here is some code you might find usefull. It is not a standalone routine at this time.

I use it to list and tabulate and control xrefs.

Gary