Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
weedseed85
Posts: 33
Registered: ‎02-05-2013
Message 1 of 8 (273 Views)

Multiple Actions Xref

273 Views, 7 Replies
02-05-2013 02:03 AM

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 

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 2 of 8 (255 Views)

Re: Multiple Actions Xref

02-05-2013 05:20 AM in reply to: weedseed85

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
Active Contributor
weedseed85
Posts: 33
Registered: ‎02-05-2013
Message 3 of 8 (229 Views)

Re: Multiple Actions Xref

02-05-2013 11:51 PM 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.

 

 

 

Valued Contributor
dicra
Posts: 63
Registered: ‎02-20-2011
Message 4 of 8 (214 Views)

Re: Multiple Actions Xref

02-06-2013 03:18 AM in reply to: weedseed85
					; 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...

Active Contributor
weedseed85
Posts: 33
Registered: ‎02-05-2013
Message 5 of 8 (212 Views)

Re: Multiple Actions Xref

02-06-2013 03:24 AM 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

*Expert Elite*
hmsilva
Posts: 2,644
Registered: ‎12-17-2004
Message 6 of 8 (204 Views)

Re: Multiple Actions Xref

02-06-2013 03:47 AM in reply to: weedseed85

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

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 7 of 8 (192 Views)

Re: Multiple Actions Xref

02-06-2013 05:58 AM in reply to: weedseed85

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
Active Contributor
weedseed85
Posts: 33
Registered: ‎02-05-2013
Message 8 of 8 (170 Views)

Re: Multiple Actions Xref

02-07-2013 06:43 AM in reply to: weedseed85

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!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community