Dear Autocad / Lisp user,
Might I please ask for your help.
I’ve tried several times, and failed time after time…
I would like to create or perhaps even write, a lisp for following actions:
Move a present Xref to the layer Xref. If the layer is not present, I would like it to create it first.
After it’s been placed on the Xref layer. I would like the Xref to be put to the back (draworder – back)
Thank you in advance
Greets,
Michel
Is the User going to select the Xref? Or is it one of a particular name that can be built into the code?
The Xref's don't have a standaart name. If it's possible, I would like to have the lisp to automaticly find the
Xref. If this is not possible or is going to take a lot of work, I would also be verry happy with a lisp that
needs the Xref to be selected.
; From Lemac (defun selx (/ blk xrefs) (while (setq blk (tblnext "BLOCK" (not blk))) (if (> (logand 4 (cdr (assoc 70 blk))) 0) (progn (setq name (cdr (assoc 2 blk)) xrefs (if xrefs (strcat xrefs "," name) name ) ) ) ) ) (ssget "X" (list '(0 . "INSERT") (cons 2 xrefs))) ) ; From afralisp ;;;Returns a layer object or nil ;;;on creation failure (defun mLayer (LayerName) (vl-load-com) (setq LayerName (vl-catch-all-apply 'vla-add (list (vla-get-layers (vla-get-activedocument (vlax-get-acad-object) ) ) Layername ) ) ) (if (vl-catch-all-error-p LayerName) nil LayerName ) ) (defun c:xr (/ i sset oldcmd) (setq sset (selx)) (mlayer "Xref") (command "chprop" sset "" "LA" "Xref" "") (progn (setq oldcmd (getvar "cmdecho")) (setvar "cmdecho" 0) (command ".draworder" sset "" "b") (setvar "cmdecho" oldcmd) ) ;progn )
I didn't have time to test this, but I hope that this will help you.
It will work only with xref which are dwg, but won't with images, pdf...
Thank You!
For what I've seen, in the short test, It worked perfect. Excactly what i was looking for.
Thank you verry mucht for your help.
Greets,
Michel
weedseed85,
a different approach, from a pBe's post, and with some modifications,
no need to search for the existence of the layer "XREF" and then create it,
with entmod the layer, if not exist, is automatically created.
(defun c:test (/ ts objs i ent) (setq objs (ssget "_X" '((0 . "INSERT")))) (repeat (setq i (sslength objs)) (setq ent (entget (ssname objs (setq i (1- i))))) (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent))))) ) ) (progn (entmod (subst (cons 8 "XREF") (assoc 8 ent) ent)) (vl-cmdf "_draworder" (cdr (assoc -1 ent)) "" "b") );; progn );; if );; repeat (princ) );; defun
hope that helps
Henrique
@weedseed85 wrote:The Xref's don't have a standaart name. If it's possible, I would like to have the lisp to automaticly find the
Xref. ....
EDIT: It looks like hmsilva beat me to the punch on some of this, but anyway....
[I assume from the fact that you say dicra's routine works perfectly that if there are more than one Xref, you want all of them changed in the same ways. If not, adjustments would have to be made.]
If you're working with a single Xref, the Layer part can be greatly simplified, because interestingly, you don't even need to create the Layer if it doesn't exist, or even check whether it exists, before assigning it to the Xref. If you put the Xref's entity name into a variable 'xr', you can just do this:
(setq
xrdata (entget xr)
xrdata (subst '(8 . "Xref") (assoc 8 xrdata) xrdata)
); setq
(entmod xrdata)
If the Layer doesn't exist, it will create it in the process of assigning it to the Xref! [It will have the default color and linetype and so on, as will dicra's (mLayer) subroutine.] But if there might be more than one Xref to process, you're probably better off using CHPROP and doing them all at once, rather than stepping through each one to do the above.
Still, you can simply create the Layer, like this:
(command "_.layer" "_new" "Xref" "")
If the Layer doesn't exist, it will create it; if it exists, it won't be bothered by that. That (mLayer) subroutine watches for its failing somehow to create the Layer, I've never known the above to fail. If you want that Layer current, you can just do this:
(command "_.layer" "_make" "Xref" "")
Again, if it already exists, it won't care, but in either case it will become current.
Thank you all so much for your help. I really appreciate it.
I’ve come to the point where I have my lisp up and running, thanks to your help.
Thank You All!