Change layer of xref in all layouts

Change layer of xref in all layouts

Gauzdx
Contributor Contributor
703 Views
9 Replies
Message 1 of 10

Change layer of xref in all layouts

Gauzdx
Contributor
Contributor

New to LISP so I was wondering if I can get some quick help here. Apologies for being lazy and not learning the basics as it could save me some time.  This language is completely new to me.

 

So I have a dwg file with couple layouts defined and has a xref loaded. How can I cycle through all the layouts and change the layer of the xref to something that is defined? 

 

Any links or suggestion is highly appreciated. 

0 Likes
704 Views
9 Replies
Replies (9)
Message 2 of 10

pendean
Community Legend
Community Legend
What exact detailed changes to an xref layer do you wish to make in each layout?
0 Likes
Message 3 of 10

Gauzdx
Contributor
Contributor

@pendean  it should pick a value from the layer drop down menu in the properties pane. 

0 Likes
Message 4 of 10

KPerison
Collaborator
Collaborator

Sounds like you might just want to move the Xref to a defined layer? 

This lisp might work for you. Just modify the Layer prefix as required.

KPerison_0-1689200478963.png

The above wouldn't have anything to do with the layouts.

 

If you are talking about modifying the properties of the xref layers per layout. Use a LayerStates.

0 Likes
Message 5 of 10

Gauzdx
Contributor
Contributor

@KPerison If I want don't want to go with prefix but with exact value, how can I go about it? The example you provided works somewhat where it is choosing the layer but not the exact layer (selected layer contains the prefix). 

0 Likes
Message 6 of 10

KPerison
Collaborator
Collaborator

Appologies, I miss read the post and then further confussed it by sending the wrong .lsp. 🙄

 

The lisp I provided moves the xref to a layer defined by a user prefix + the XREF name.

 

If I understand you just need to have the xref that has been inserted on the wrong layer moved to a different predefined layer?

 

Just Grip the xref and in the Autocad Properties palette set the desired layer.

No lisp req'd. unless you need to do it more than 10x.

 

 

 

Message 7 of 10

Gauzdx
Contributor
Contributor

@KPerison Yeah you got the requirement right now. I know its a easy manual process but I would want a lisp since it needs to be done number of times and has to be done for the xref in all layouts. 

0 Likes
Message 8 of 10

KPerison
Collaborator
Collaborator

Ok. Here is a work around using the original LSP file I gave you.

Cavate - the LSP will move ALL xrefs to individual layers based on the name format (Prefix+Xref name)

 

  1. In the .lsp file change the prefix to something obvious to identify like "_XXX"
  2. In your dwg, load the lsp file and run XR2L.
  3. It will move all your xrefs to individual layers called _XXX-xrefname
  4. run the LAYMRG command
  5. Select the layers to Merge. Enter N for name
  6. In the dialog highlight all the layers with the prefix "_XXX". Select OK.
  7. At next prompt you are selecting the target layer. Enter N for name.
  8. In the dialog highlight the target layer you want the xref to be placed on. Select Ok.
  9. All the xrefs will be moved to the desired layer and all the temporary "_XXX" layers will be purged.

Roundabout way, but it gets ya there.  

 

 

0 Likes
Message 9 of 10

komondormrex
Mentor
Mentor

the code changes layer for all xrefs in all layouts literally. however the layer name should be written manually in line 19.

(defun c:change_all_xref_layer nil
	(vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
		'(lambda (block_definition)
		 	(if (minusp (vlax-get block_definition 'islayout))
			   		(vlax-map-collection block_definition
						'(lambda (object)
						 	(if (and (= "AcDbBlockReference" (vla-get-objectname object))
									 (minusp (vlax-get (vla-item (vla-get-blocks 
									 								(vla-get-activedocument 
																		(vlax-get-acad-object)
																	)
																 )
																 (vla-get-name object)
													   )
									  				  'isxref
											 )
									 )
								)
									(vla-put-layer object "Fill_in_Layer_Here") 
							)
						 )
			  		)
			 )
		)
	)
  	(princ)
)

 

0 Likes
Message 10 of 10

Kent1Cooper
Consultant
Consultant

@Gauzdx wrote:

.... How can I cycle through all the layouts and change the layer of the xref to something that is defined?  .... 


You don't need to cycle through all the layouts.  This will change the Layer of all Xrefs in the drawing to the "YourLayerName" Layer [edit that to suit], in all layouts and/or in model space, without moving to the space each is in:

 

(defun C:X2L (/ ss n blk bdata); = Xref(s) {to} Layer
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (repeat (setq n (sslength ss)); then
      (setq
        blk (ssname ss (setq n (1- n)))
        bdata (entget blk)
      ); setq
      (if (/= (cdr (assoc 1 (entget (tblobjname "block" (cdr (assoc 2 bdata)))))) ""); it's an Xref
        (entmod (subst '(8 . "YourLayerName") (assoc 8 bdata) bdata))
      ); if
    ); repeat
  ); if
  (prin1)
); defun

 

It finds all INSERT objects [which include both regular Blocks and Xrefs, among a few other things], and checks whether each is an Xref [i.e. its name's entity data includes a file path], and if so, changes the Layer entry in the reference's entity data.  If the Layer doesn't exist, it will be created in the process, with default color 7 and continuous linetype.

[EDIT:  Fixed something -- if you copied it before the EDIT, copy it again.]

Kent Cooper, AIA