Author Topic: XREF-reload, unload, detach  (Read 6934 times)

0 Members and 1 Guest are viewing this topic.

CADaver

  • Guest
XREF-reload, unload, detach
« on: August 22, 2006, 06:19:46 PM »
I have this old code I've been using for years and today one of our new guys wanted to know if there was a more elegant option for these functions.  My first answer was "Surely", when he then asked "What are they?", I said "I dunno". So I thought I just ask you guys.  Each one functions on the selected XREF's to either reload, unload or detach (no error check) tear 'em up, guys:

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:xre ()
(prompt "\N Select Element in XREF to RELOAD  ")
(xref-loader "reload")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:xru ()
(prompt "\N Select Element in XREF to UNLOAD  ")
(xref-loader "unload")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:xrd ()
(prompt "\N Select Element in XREF to DETACH  ")
(xref-loader "detach")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun xref-loader ( xref-action / old setlgth co t2 temp blkname)
(command ".undo" "BEGIN")
   (setvar "cmdecho" 0)
      (setq
        old (ssget)
        setlgth (sslength old)
        co -1
        t2 "t"
      )
  (while (boundp 't2)
     (progn
       (setq
         co (1+ co)
         temp (entget (ssname old co))
         blkname (cdr (assoc 2 temp))
         t2 (ssname old (1+ co))
       )
         (command "-xref" xref-action blkname)
       )      ;; end progn
   )          ;; end while
(setq co (1+ co))
(princ)
(command ".undo" "END")
(princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

T.Willey

  • Needs a day job
  • Posts: 5251
Re: XREF-reload, unload, detach
« Reply #1 on: August 22, 2006, 06:21:56 PM »
What is your idea of more elegant?
Tim

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

Please think about donating if this post helped you.

nivuahc

  • Guest
Re: XREF-reload, unload, detach
« Reply #2 on: August 22, 2006, 06:51:40 PM »
What is your idea of more elegant?

Seriously.

I would say it's elegant in its simplicity.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: XREF-reload, unload, detach
« Reply #3 on: August 22, 2006, 06:57:38 PM »
If you wanted to get it to eliminate the echos to the command line then converting it to use ActiveX is quite simple:

Code: [Select]
;;add near beginning of xref-loader code
(setq doc (vla-get-activedocument
    (vlax-get-acad-object)))

;(command ".undo" "BEGIN")...change to:
(vla-startundomark doc)

;(command "-xref" xref-action blkname)...change to:
(vlax-invoke
  (vla-item
    (vla-get-blocks
      doc)
    blkname)
  xref-action)

;(command ".undo" "END")...change to:
(vla-startundomark doc)

But consider what Chuck said......
« Last Edit: August 22, 2006, 07:16:27 PM by Jeff_M »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: XREF-reload, unload, detach
« Reply #4 on: August 22, 2006, 06:59:25 PM »
The only thing I could think of is the use of command.  Take that out, but you don't really gain anything, since you are only using it in the current drawing.

What is your idea of more elegant?

Seriously.

I would say it's elegant in its simplicity.

Second.

Guess Jeff thought the same before I could post.
Tim

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

Please think about donating if this post helped you.

CADaver

  • Guest
Re: XREF-reload, unload, detach
« Reply #5 on: August 22, 2006, 10:19:19 PM »
I guess I was looking for something along the lines of Jeff's response with the activeX conversion. (Thanks Jeff)  And the reason it's simple is that 'simple" is all I can do.

LE

  • Guest
Re: XREF-reload, unload, detach
« Reply #6 on: August 22, 2006, 10:33:01 PM »
I do not see any control of knowing if the selected item is an xref, or I missing something?

CADaver

  • Guest
Re: XREF-reload, unload, detach
« Reply #7 on: August 23, 2006, 06:01:30 AM »
I do not see any control of knowing if the selected item is an xref, or I missing something?
THere's not, there's very little control of anything.  It'll choke if you get a block in the selection set.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: XREF-reload, unload, detach
« Reply #8 on: August 23, 2006, 06:07:24 AM »
Nothing to do with elegance, but this ;
(prompt "\N Select Element in XREF to RELOAD  ")

will work as anticipated like this ;
(prompt "\n Select Element in XREF to RELOAD  ")

{ie: lowercase \n }
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Joe Burke

  • Guest
Re: XREF-reload, unload, detach
« Reply #9 on: August 23, 2006, 08:55:37 AM »
If you wanted to get it to eliminate the echos to the command line then converting it to use ActiveX is quite simple:

Code: [Select]
;;add near beginning of xref-loader code
(setq doc (vla-get-activedocument
    (vlax-get-acad-object)))

;(command ".undo" "BEGIN")...change to:
(vla-startundomark doc)

;(command "-xref" xref-action blkname)...change to:
(vlax-invoke
  (vla-item
    (vla-get-blocks
      doc)
    blkname)
  xref-action)

;(command ".undo" "END")...change to:
(vla-startundomark doc)

But consider what Chuck said......

Hi Jeff,

I believe there's an additional advantage here. It would allow pre-selection of the xref. Whereas (command ".undo" "BEGIN") would deselect any pre-selection.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: XREF-reload, unload, detach
« Reply #10 on: August 23, 2006, 11:05:28 AM »
I can't believe that no one caught this: 
Code: [Select]
;(command ".undo" "END")...change to:
(vla-startundomark doc)
:oops: should be
Code: [Select]
(vla-endundomark doc)
Joe, that's an excellent point!



CADaver

  • Guest
Re: XREF-reload, unload, detach
« Reply #11 on: August 23, 2006, 01:00:52 PM »
I believe there's an additional advantage here. It would allow pre-selection of the xref. Whereas (command ".undo" "BEGIN") would deselect any pre-selection.
ooooo, excellent point.  We have some new guys that use pickfirst the "other" way, while us older hacks are still doing it the old way.  Thanks.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: XREF-reload, unload, detach
« Reply #12 on: August 23, 2006, 01:05:15 PM »
I have this old code I've been using for years and today one of our new guys wanted to know if there was a more elegant option for these functions.  My first answer was "Surely", when he then asked "What are they?", I said "I dunno". So I thought I just ask you guys.  Each one functions on the selected XREF's to either reload, unload or detach (no error check) tear 'em up, guys:

hello folks
Recently I barrowed <cough> a piece code from Daron that he posted a while back  REQ: XREF Reload/Open ....
dam it wrong button I wasn't done yet
....which a basically copied and added the unload part in place of the reload.  I get a nasty hick up when I select a non-xref.  To me it is a minor nu sinace, so I live with it.  I would say, have the routine filter out non-xrefs so that it keeps going or be intelligent enough to select the xref that is underneath a piece of geometry.  (Yep using draworder over here).

Daron thanks for your routine. I have been using the hell out of it.   :-D
« Last Edit: August 23, 2006, 01:14:54 PM by Krushert »
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CADaver

  • Guest
Re: XREF-reload, unload, detach
« Reply #13 on: August 23, 2006, 01:25:47 PM »
Recently I barrowed <cough> a piece code from Daron that he posted a while back  REQ: XREF Reload/Open ....
hmmm... I don't think I stole the idea from Daron, but I've been known to pinch a bit of code now and then, and if I did, sorry...
... well not really, ... but you know what I mean.... or not.... 
...how about this; If I did, Thanks Daron.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: XREF-reload, unload, detach
« Reply #14 on: August 23, 2006, 01:39:45 PM »
Recently I barrowed <cough> a piece code from Daron that he posted a while back  REQ: XREF Reload/Open ....
hmmm... I don't think I stole the idea from Daron, but I've been known to pinch a bit of code now and then, and if I did, sorry...
... well not really, ... but you know what I mean.... or not.... 
...how about this; If I did, Thanks Daron.
If you pinch a code does it yell.  sorry bad pun.   :-D

CADaver, sorry  I didnt mean to imply that you stole barrow (or whatver) I did and I did thank him.  <I got the proof>   :-)
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: XREF-reload, unload, detach
« Reply #15 on: August 23, 2006, 01:46:20 PM »
Okay, here you go.  Now you can only select blocks, and it will make sure that it is an xref before preforming the opperation to it. Use with the other portions or Randy's code.
Code: [Select]
(defun Xref-Loader (XrefOpp / ActDoc BlkCol ss Ent BlkObj)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-StartUndoMark ActDoc)
(setq BlkCol (vla-get-Blocks ActDoc))
(if (setq ss (ssget '((0 . "INSERT"))))
 (foreach Lst (ssnamex ss)
  (if
   (and
    (= (type (setq Ent (cadr Lst))) 'ENAME)
    (= (vla-get-IsXref (setq BlkObj (vla-Item BlkCol (cdr (assoc 2 (entget Ent)))))) :vlax-true)
   )
   (vlax-invoke BlkObj XrefOpp)
  )
 )
)
(vla-EndUndoMark ActDoc)
(princ)
)
Tim

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

Please think about donating if this post helped you.

nivuahc

  • Guest
Re: XREF-reload, unload, detach
« Reply #16 on: August 23, 2006, 01:52:21 PM »
Something different but similar, courtesy of MP:

Code: [Select]
(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)
        )   
    )
)


(defun c:XOpen ( / path )
    (if (setq path (GetXrefPath (car (entsel))))
        (if (zerop (getvar "sdi"))
            (vla-open
                (vla-get-documents (vlax-get-acad-object))
                path
            )
            (vla-sendcommand
                (vla-get-activedocument (vlax-get-acad-object))
                (strcat ".open " path "\n")
            )
        )
    )   
    (princ)   
)

CADaver

  • Guest
Re: XREF-reload, unload, detach
« Reply #17 on: August 23, 2006, 03:26:21 PM »
CADaver, sorry  I didnt mean to imply that you stole barrow (or whatver) I did and I did thank him.  <I got the proof>   :-)
Oh, I didn't think you did, it's just that the codes are sorta similar, and I have been known to ...ummm... borrow a line or two. :angel: