Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Multiple Actions Xref

7 REPLIES 7
Reply
Message 1 of 8
CAD_user85
530 Views, 7 Replies

Multiple Actions Xref

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 

7 REPLIES 7
Message 2 of 8
Kent1Cooper
in reply to: CAD_user85

Is the User going to select the Xref?  Or is it one of a particular name that can be built into the code?

Kent Cooper, AIA
Message 3 of 8
CAD_user85
in reply to: Kent1Cooper

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.

 

 

 

Message 4 of 8
dicra
in reply to: CAD_user85

					; 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...

Message 5 of 8
CAD_user85
in reply to: dicra

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

Message 6 of 8
hmsilva
in reply to: CAD_user85

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

EESignature

Message 7 of 8
Kent1Cooper
in reply to: CAD_user85


@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.

Kent Cooper, AIA
Message 8 of 8
CAD_user85
in reply to: CAD_user85

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!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost