Author Topic: Nested Xrefs  (Read 7159 times)

0 Members and 1 Guest are viewing this topic.

Robert_s

  • Guest
Nested Xrefs
« on: September 29, 2008, 02:34:37 PM »
Hello,

We receive drawings from clients & consultants that are xref "happy".
Drawings that have nested upon nested upon nested xrefs. Xrefs are
reused, borrowed, & copied all over the place. You have a parent
xref, a child, a grandfather & a cousin xref. And then lets not forget
about the missing & unresoled xrefs.

Can somebody please write a program that will
1. Get all the xrefs & their insertions points in the open drawing.
    (Even the xrefs that are nested).
2. Detached all the xrefs. Then reassembly the drawing by attaching
   the xrefs one by one using the same insertion point.

Any help would be appreciated....Thank you.



T.Willey

  • Needs a day job
  • Posts: 5251
Re: Nested Xrefs
« Reply #1 on: September 29, 2008, 02:56:09 PM »
Not a simple project.  Nested xrefs need to be changed in the drawing which they are first xref'ed into, so you have to check there, then change them to overlay instead of attach, and I don't think anyone has found a simple way through code yet, so this one is far from simple.
Tim

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

Please think about donating if this post helped you.

Robert_s

  • Guest
Re: Nested Xrefs
« Reply #2 on: September 29, 2008, 03:04:57 PM »
Hi Tim,

I had the feeling it was going to be difficult. Thank you
for replying to my post.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Nested Xrefs
« Reply #3 on: September 29, 2008, 08:31:14 PM »
Hello,

We receive drawings from clients & consultants that are ...

Attack this problem at the source. Specify up front with your clients and consultants how you expect the drawings to be assembled.

Hedgehog

  • Guest
Re: Nested Xrefs
« Reply #4 on: September 30, 2008, 05:15:29 AM »
Attack this problem at the source. Specify up front with your clients and consultants how you expect the drawings to be assembled.
Unfortunately if they had a clue what you were talking about when you try to explain why their drawings are so difficult to work with they'd probably not do it in the first place... all too frequently they haven't a clue & are even less inclined to comply.

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Nested Xrefs
« Reply #5 on: September 30, 2008, 08:34:14 AM »
That doesn't mean you can't specify your requirements up front and expect for them to be met. Our consultants do what we say or we find new ones.

Joe Burke

  • Guest
Re: Nested Xrefs
« Reply #6 on: September 30, 2008, 08:57:28 AM »
Robert,

I agree with what Tim said.

I also think you'd need to determine whether the nested xrefs actually serve a uesful purpose. If they don't then what you are asking for may be possible.

Hedgehog

  • Guest
Re: Nested Xrefs
« Reply #7 on: September 30, 2008, 09:15:15 AM »
That doesn't mean you can't specify your requirements up front and expect for them to be met. Our consultants do what we say or we find new ones.
That's great when you're that end of the food chain... but when the consultants are employed by your clients (or are your clients) it's not so easy trying to explain the benefits of improved working practices... & of course by the time we get to see drawings it's too late to include any extra time for sorting their drawings out so it goes to our QS's & generally makes life hell.

Robert_s

  • Guest
Re: Nested Xrefs
« Reply #8 on: September 30, 2008, 10:08:14 AM »
We get most of our work from our clients . So I dont bite the hands
that feed us.

When they send us drawings you would know if it was a from different
person that prepared the drawings that day as opposed to the last
time they sent it. But thats another story.

Once I tried talking to them but they felt a little insulted. Its hard
for a big client to be tutored by an small consultant about autocad.
After all they think autocad was written for them.

Usually the nested xrefs serves a useful purpose. But its the way
it was nested. Its sometimes ridiculous. Why xref in a nested xref
when all they need to do is get just one component/drawing out
of that super nested drawing. What they end up doing is just freezing
all the layers that are not needed.

Then I have to do some investigation of the components thats only required
and make sure I capture the layers settings....Then the nest day you get an
update of one nested component with all the layers thawed with different
components....I gotta stop here. I'm getting too excited.

And thats my take to that.

FengK

  • Guest
Re: Nested Xrefs
« Reply #9 on: September 30, 2008, 01:26:46 PM »
Not a simple project.  Nested xrefs need to be changed in the drawing which they are first xref'ed into, so you have to check there, then change them to overlay instead of attach, and I don't think anyone has found a simple way through code yet, so this one is far from simple.

Tim, did you once write something in C# that list all the xref showing their nested structure in a drawing?

rkmcswain

  • Swamp Rat
  • Posts: 978
Re: Nested Xrefs
« Reply #10 on: September 30, 2008, 01:59:11 PM »
Well, I was not talking about after you have the drawings. Negotiate this up front, long before drawings change hands.

If you were consulted to build a steel widget and your client agreed to supply the parts, but all they sent you was plastic parts. You would either go back and fix this problem at the source, or learn to make steel out of plastic.

I know this isn't addressing your original request. Sorry.

What you want to do can be done, but you'll need a recursive function to iterate the blocks collection down to the bottom xref in each tree of parent xrefs. Nested.lsp (available at http://www.hyperpics.com/customization/autolisp/autolisp_downloads.asp , © Lee Ambrosius) looks like a good starting point. I was able to take this code and extract the INS PT for a series of nested Xrefs. From there, just save this list, detach them all, and reattach.


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Nested Xrefs
« Reply #11 on: September 30, 2008, 02:09:56 PM »
Not a simple project.  Nested xrefs need to be changed in the drawing which they are first xref'ed into, so you have to check there, then change them to overlay instead of attach, and I don't think anyone has found a simple way through code yet, so this one is far from simple.

Tim, did you once write something in C# that list all the xref showing their nested structure in a drawing?
Do you mean this one?
Tim

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

Please think about donating if this post helped you.

FengK

  • Guest
Re: Nested Xrefs
« Reply #12 on: September 30, 2008, 06:32:20 PM »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Nested Xrefs
« Reply #13 on: October 01, 2008, 05:29:26 AM »
Hi,

I wrote something similar to catch nested block entities insertion points (here)

This is an adaptation for Xrefs insertion points.

The XrefsInsertionPoints routine prints in the textscreen the 'nesting tree' of xrefs in the drawing and returns a list of sublists which type is :
((XrefName1 X1 Y1 Z1) (XrefName2 X2 Y2 Z2) ...)

Code: [Select]
;; RefGeom
;; Returns a list which first item is the 3X3 tranformation matrix and second item is
;; the insertion point of a ) reference (block, xref) in its owner (space or block definition)
(defun RefGeom (ename / elst ang norm)
  (setq elst (entget ename)
ang  (cdr (assoc 50 elst))
norm (cdr (assoc 210 elst))
  )
  (list
    (mxm
      (mapcar (function (lambda (v) (trans v 0 norm T)))
      '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0))
      )
      (mxm
(list (list (cos ang) (- (sin ang)) 0.0)
      (list (sin ang) (cos ang) 0.0)
      '(0.0 0.0 1.0)
)
(list (list (cdr (assoc 41 elst)) 0.0 0.0)
      (list 0.0 (cdr (assoc 42 elst)) 0.0)
      (list 0.0 0.0 (cdr (assoc 43 elst)))
)
      )
    )
    (trans (cdr (assoc 10 elst)) norm 0)
  )
)

;; nested-xrefs
;; Returns a list of a xref coordinates
(defun nested-xrefs (ref mat ins tab / name blk ent elst typ lst)
  (setq name (cdr (assoc 2 (entget ref)))
blk  (tblsearch "BLOCK" name)
ent  (cdr (assoc -2 blk))
  )
  (princ (strcat tab "\"" name "\"\n"))
  (setq tab (strcat "   " tab))
  (while ent
    (setq elst (entget ent)
  typ  (cdr (assoc 0 elst))
  name (cdr (assoc 2 elst))
    )
    (if (and
  (= "INSERT" typ)
  (isXref ent)
)
      (progn
(setq lst  (cons (cons name (mapcar '+ ins (mxv mat (cdr (assoc 10 elst))))) lst)
      nent (RefGeom ent)
      lst  (append
     (nested-xrefs
       ent
       (mxm mat (car nent))
       (mapcar '+ ins (mxv mat (cadr nent)))
       tab
     )
     lst
   )
)
      )
    )
    (setq ent (entnext ent))
  )
  lst
)


;; Determine if an insert is a xref
(defun isXref (ref / def)
  (and
    (setq def (tblsearch "BLOCK" (cdr (assoc 2 (entget ref)))))
    (= 4 (logand 4 (cdr (assoc 70 def))))
  )
)

;; Transpose a matrix -Doug Wilson-
(defun trp (m)
  (apply 'mapcar (cons 'list m))
)

;; Apply a transformation matrix to a vector -Vladimir Nesterovsky-
(defun mxv (m v)
  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v))))
  m
  )
)

;; Multiply two matrices -Vladimir Nesterovsky-
(defun mxm (m q)
  (mapcar (function (lambda (r) (mxv (trp q) r))) m)
)

;; XrefsInsertionPoints
;; print the nesting tree in the text screen
;; Return : a list of sublists ((XrefName Xins Yins Zins) ...)

(defun XrefsInsertionPoints (/ ss n ent mtx lst)
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (repeat (setq n (sslength ss))
      (if (isXref (setq ent (ssname ss (setq n (1- n)))))
(progn
  (terpri)
  (setq mtx (RefGeom ent)
lst (append
      (list (cons (cdr (assoc 2 (entget ent))) (cadr mtx)))
      (nested-xrefs ent (car mtx) (cadr mtx) "- ")
    lst
      )
  )
)
      )
    )
  )
  (print lst)
)
Speaking English as a French Frog

Joe Burke

  • Guest
Re: Nested Xrefs
« Reply #14 on: October 01, 2008, 07:41:26 AM »
Just another idea, though it may be lame.

Express Tools has a command named "BLOCKTOXREF". It fails to do what it should when I try it in 2008 for no apparent resaon. No surprise there. But the idea behind it seems possible. IOW, gather data about the xref inserts in a drawing. Bind the xrefs, then convert them back to xrefs using overlay.

The upside of this idea is it may be possible to achieve the goal, at least in a limited sense, without looking at parent files.