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

Attach xref onto specified layer

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
JLin631
1420 Views, 7 Replies

Attach xref onto specified layer

I'm looking a program that will put a xref attachment onto a specified layer. One layer for Modelspace xrefs and another layer for Paperspace xrefs. I'v seen some post here that uses a command reactor to specify the layer once the xref command executes, But, can this be done with (2) layer references?

 

Thank you in advance.

7 REPLIES 7
Message 2 of 8
pbejse
in reply to: JLin631


@JLin631 wrote:

I'm looking a program that will put a xref attachment onto a specified layer. One layer for Modelspace xrefs and another layer for Paperspace xrefs. I'v seen some post here that uses a command reactor to specify the layer once the xref command executes, But, can this be done with (2) layer references?

 

Thank you in advance.


Go grab that reactor routine you found and stick this in there in the part where layer name is assigned to the xref object..

 

Something klike this:

 

(setq XrefLayer
           (if (zerop (getvar 'Tilemode))
                 "PSLayer" "MLayer"));<--- whatever the name of your layer

or

(setvar 'clayer
           (if (zerop (getvar 'Tilemode))
                 "PSLayer" "MLayer"))

 

Also depending on your approach you may need to check if the layer exist..

 

HTH

 

Message 3 of 8
JLin631
in reply to: pbejse

pbejse,

I've added the lines you've suggested to the area where the commands and layers are defined. But the program doesn't work after the modification. I think you've given me a direction in which I need to go. Thanks.

 

Message 4 of 8
pbejse
in reply to: JLin631


@JLin631 wrote:

pbejse,

I've added the lines you've suggested to the area where the commands and layers are defined. But the program doesn't work after the modification. I think you've given me a direction in which I need to go. Thanks.

 


I see, hang on, i'll write a quick one for you.

 

EDIT:

Try this

(vl-load-com)
(if xrf (vlr-remove xrf))

(setq xrf 
(vlr-command-reactor nil '((:vlr-commandWillStart . SetLayer))))
(defun SetLayer (cr ec / ln)
  		(if (and (member (nth 0 ec) '("XREF" "-XREF"))
  			 (entmake (list (cons 0 "LAYER")
			 (cons 100 "AcDbSymbolTableRecord")
			 (cons 100 "AcDbLayerTableRecord")
			 (cons 2 (setq ln (if (zerop (getvar 'Tilemode))
                 		        "PSLayer" "MLayer")))
			 (cons 70 0)))
                        )
                    (setvar 'Clayer ln)
                       )
                      (princ)
	  )

 

Change the layer name of the layers , of course you already know that.

 

HTH

Message 5 of 8
JLin631
in reply to: pbejse

Program works great. Thanks a million!

Message 6 of 8
dbroad
in reply to: JLin631

One disadvantage of an incomplete reactor based solution is that things might not be resolved after the command.  This is more complete but may not be fully complete.  It accomodates restoration at the end and the possibility that the command will be cancelled.  I have also tested it with "undo" and it seems to have no problems.

;;Command Reactor for Xref layer
;;D.C. Broad 2012
(if (null myxr-react)
  (setq myxr-react (vlr-command-reactor nil '((:vlr-commandwillstart . myxr-swaplayer)
					      (:vlr-commandended . myxr-restorelayer)
					      (:vlr-commandcancelled . myxr-restorelayer))))
  )

(defun setormakelayer (layn doc)
    (if	(null (tblsearch "layer" layn))
      (vla-add (vla-get-layers doc) layn))
    (setvar "clayer" layn)
)

;;commandwillstart callback (reactor commandlist)
(defun myxr-swaplayer (r cl / doc)
  (if (member (car cl) '("XATTACH"));allowance for other commands
    (progn
      (setq doc (vlr-document r))
      (vlr-data-set r (getvar "clayer"))
    (if
      (= 1 (vla-get-activespace doc))
      (setormakelayer "ms_xrlayer" doc)
      (setormakelayer "ps_xrlayer" doc)
      ))))

;;commandended callback (reactor commandlist)
(defun myxr-restorelayer (r cl)
  (if (and (member (car cl) '("XREF" "XATTACH"))
	   (vlr-data r))
    (setvar "clayer" (vlr-data r))
    (vlr-data-set r nil)
    )
  )
   

 

Architect, Registered NC, VA, SC, & GA.
Message 7 of 8
pbejse
in reply to: dbroad


@dbroad3 wrote:

One disadvantage of an incomplete reactor based solution is that things might not be resolved after the command.  This is more complete but may not be fully complete.  It accomodates restoration at the end and the possibility that the command will be cancelled.  I have also tested it with "undo" and it seems to have no problems.

 


Good thinking, I like it. 

 

Thanks dbroad

 

Cheers

Message 8 of 8
dbroad
in reply to: pbejse

You're welcome.

Architect, Registered NC, VA, SC, & GA.

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

Post to forums  

Autodesk Design & Make Report

”Boost