TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CADaver 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:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
What is your idea of more elegant?
-
What is your idea of more elegant?
Seriously.
I would say it's elegant in its simplicity.
-
If you wanted to get it to eliminate the echos to the command line then converting it to use ActiveX is quite simple:
;;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......
-
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.
-
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.
-
I do not see any control of knowing if the selected item is an xref, or I missing something?
-
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.
-
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 }
-
If you wanted to get it to eliminate the echos to the command line then converting it to use ActiveX is quite simple:
;;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.
-
I can't believe that no one caught this:
;(command ".undo" "END")...change to:
(vla-startundomark doc)
:oops: should be
(vla-endundomark doc)
Joe, that's an excellent point!
-
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.
-
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 (http://www.theswamp.org/index.php?topic=23.0) ....
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
-
Recently I barrowed <cough> a piece code from Daron that he posted a while back REQ: XREF Reload/Open (http://www.theswamp.org/index.php?topic=23.0) ....
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.
-
Recently I barrowed <cough> a piece code from Daron that he posted a while back REQ: XREF Reload/Open (http://www.theswamp.org/index.php?topic=23.0) ....
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> :-)
-
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.
(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)
)
-
Something different but similar, courtesy of MP:
(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, 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: