PDA

View Full Version : controlling xref without user selection


louis.marroquin
2006-11-10, 12:23 AM
I'm new to autolisp, so if you reply could you try to comment your code and explain what you're doing. I can write VBA well, but autolisp seems harder to pick up.

I want to be able to work with xrefs in autolisp without the user selecting which xref to do something to. For example, I could run a lisp that scans through each of the external references and gives me its status: is it unloaded, is it detached, overlay or attached, etc. Then, I could change the status of any or all of the xrefs based on something I decide. If any xref is unloaded, then it should be detached. The remaining xrefs are then bound.

Another example would be to simply display how many references are attached to a drawing. Or individual autolisp functions that detach all, unload all, reload all, and bind all. Again, I don't want user input, I essentially want the autolisp equivalent of the XREF Manager dialog box.

(If any xref is unloaded, then it should be detached. The remaining xrefs are then bound.) - Is what I was trying to do until I got stuck. I don't want to use eTransmit either, strictly autolisp.

Thanks,
-Louis

rkmcswain
2006-11-10, 01:21 PM
Can you post the code you have so far?

That should make it easier for someone to help you out.

louis.marroquin
2006-11-10, 01:34 PM
I don't have any code so far because I haven't found a good example that works with xrefs without having the user select one of them.

Opie
2006-11-10, 02:19 PM
I don't have any code so far because I haven't found a good example that works with xrefs without having the user select one of them.
What about pseudo code?

louis.marroquin
2006-11-10, 03:06 PM
My attempt at pseudo code...remember I'm very new to autolisp so don't be too harsh, just point me in the right direction.

setq xlist (to an array of all the xrefs)
setq counter (0)
setq xcount (to the number of xrefs in xlist)
while (counter<xcount)
(
If (xlist(counter) is unloaded)
(
xlist(counter) is detached
setq xcount (- 1 xcount)
)
Else xlist(counter) is bound.
setq xcount (- 1 xcount)
)

Attached you will find an autolisp file that I found somewhere that basically handles xrefs with autolisp, I just don't know enough autolisp to try and make sense of what some of the lines of code are actually doing.

ccowgill
2006-11-10, 11:03 PM
A little more along the lines of a pseudo code:

;;This Program is to collect information on water main and annotate the parts in the base
;Get System Var & error handling
;Set System Var
;Select Objects
;Get Pipe Lengths
;Get Pipe Size and Type
;Get Blocks
;Get Block Sizes
;Place text along pipe
;Place text next to blocks
;Restore System Var


In other words, the steps that you want to combine into the lisp routine, it would give others a much clearer idea of what you want to do

louis.marroquin
2006-11-10, 11:31 PM
ccowgill,

;Detach external references that are unloaded
;Bind all remaining external references
;check to make sure there aren't any xrefs still attached
;zoom extents
;save file

rkmcswain
2006-11-11, 12:10 AM
ccowgill,

;Detach external references that are unloaded
;Bind all remaining external references
;check to make sure there aren't any xrefs still attached
;zoom extents
;save file

The following should do steps 1 and 2.


(vl-load-com)
(setq *blks*
(vla-get-Blocks
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)
(vlax-for item *blks*
(if (eq (vla-get-IsXref item) :vlax-true)
(progn
(setq ref (tblsearch "BLOCK" (setq xname (vla-get-Name item))))
(if (eq (logand (cdr (assoc 70 ref)) 32) 32)
(command "-xref" "_B" xname)
(command "-xref" "_D" xname)
)
)
)
)

louis.marroquin
2006-11-11, 01:46 AM
That's exactly what I needed, thanks.

The only problem is that when I have an xref that has a nested xref. If the nested xref is unloaded in the drawing I am in, both xrefs aren't bound. Do I have to reload the nested xref? If so, how would I reload only the nested xref and still detach all other unloaded ones?