Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Member
JLin631
Posts: 5
Registered: ‎12-19-2011
Message 1 of 8 (542 Views)
Accepted Solution

Attach xref onto specified layer

542 Views, 7 Replies
03-23-2012 04:10 PM

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.


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

*Expert Elite*
pbejse
Posts: 2,496
Registered: ‎11-24-2009
Message 2 of 8 (530 Views)

Re: Attach xref onto specified layer

03-24-2012 12:31 AM 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

 

Member
JLin631
Posts: 5
Registered: ‎12-19-2011
Message 3 of 8 (487 Views)

Re: Attach xref onto specified layer

03-27-2012 10:01 AM 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.

 

*Expert Elite*
pbejse
Posts: 2,496
Registered: ‎11-24-2009
Message 4 of 8 (483 Views)

Re: Attach xref onto specified layer

03-27-2012 10:11 AM 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

Member
JLin631
Posts: 5
Registered: ‎12-19-2011
Message 5 of 8 (460 Views)

Re: Attach xref onto specified layer

03-28-2012 08:31 AM in reply to: pbejse

Program works great. Thanks a million!

*Expert Elite*
dbroad
Posts: 1,568
Registered: ‎08-16-2007
Message 6 of 8 (455 Views)

Re: Attach xref onto specified layer

03-28-2012 10:24 AM 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)
    )
  )
   

 

*Expert Elite*
pbejse
Posts: 2,496
Registered: ‎11-24-2009
Message 7 of 8 (434 Views)

Re: Attach xref onto specified layer

03-28-2012 10:25 PM in reply to: dbroad

dbroad 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

*Expert Elite*
dbroad
Posts: 1,568
Registered: ‎08-16-2007
Message 8 of 8 (426 Views)

Re: Attach xref onto specified layer

03-29-2012 05:56 AM in reply to: pbejse

You're welcome.

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 or visit the Installation and Licensing Forum to get help installing your software.