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

MOVE External references to a NEWLY made layer

56 REPLIES 56
SOLVED
Reply
Message 1 of 57
jahbgd
2340 Views, 56 Replies

MOVE External references to a NEWLY made layer

Hello everyone,

 

I am looking for a lisp that would MAKE NEW LAYER (named x-ref or whatever- color white ie.), SELECT all external references, MOVE them to that layer and LOCK it. 

I have number of files with many x-ref files that are on different layer. Many people worked on them and match properties was vastly used and now I have xrefs placed on defpoints, dimension layer, etc...

 

I am not to familiar with tweaking the codes so although i have found some similar posts I am cant compile what I need.

 

Thanks in advance

 

Cheers

Janko

56 REPLIES 56
Message 21 of 57
hmsilva
in reply to: jahbgd


@jahbgd wrote:

What happens is that if layer whatever exists than it works, but otherwise it fails to do anything...


As I had said earlier "untested"...
My bad!


Try this one, and again untested

 

(defun c:demo (/ ENT I L LAY LAYLST LAYX SS)
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (progn
      (if (and (setq l (tblobjname "layer" "whatever"))
	       (setq layx (entget l))
	       )
	(if (/= 4 (logand 4 (cdr (assoc 70 layx))))
	  (setq laylst (cons (cons layx 4) laylst))
	)
	)
	(entmake (list (cons 0 "LAYER")
		       (cons 100 "AcDbSymbolTableRecord")
		       (cons 100 "AcDbLayerTableRecord")
		       (cons 2 "whatever")
		       (cons 70 4)
		 )
      )
      (repeat (setq i (sslength ss))
	(setq ent (entget (ssname ss (setq i (1- i)))))
	(if
	  (= 4
	     (logand 4
		     (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent)))))
	     )
	  )
	   (progn
	     (setq lay (entget (tblobjname "layer" (cdr (assoc 8 ent)))))
	     (if (= 4 (logand 4 (cdr (assoc 70 lay))))
	       (progn
		 (setq laylst (cons (cons lay (cdr (assoc 70 lay))) laylst))
		 (entmod (subst (cons 70 0) (assoc 70 lay) lay))
	       )
	     )
	     (entmod (subst (cons 8 "whatever") (assoc 8 ent) ent))
	   )
	)
      )
      (if laylst
	(foreach lay laylst
	  (entmod (subst (cons 70 (cdr lay)) (assoc 70 (car lay)) (car lay)))
	)
      )
    )
  )
  (princ)
)

 

HTH

Henrique

EESignature

Message 22 of 57
jahbgd
in reply to: braudpat

@ PAT,

Same here... You have previous post with option where new layer named "whatever" is made automatically. Later one is assigning all xrefs into already existing layer

 

 

Message 23 of 57
jahbgd
in reply to: jahbgd

Henrique, 

It works!

 

Great

j

Message 24 of 57
hmsilva
in reply to: jahbgd


@jahbgd wrote:

Henrique, 

It works!

 

Great

j


j,

I'm glad it works!

Henrique

 

EESignature

Message 25 of 57
hmsilva
in reply to: braudpat

Patrice,

 

this demo will change all model xrefs to layer "Xrefs_Model" and all layout xrefs to layer "Xrefs_Layout"...

 

(defun c:demo ( / ent i lay laylst ss)

(defun test_layer (name / l layx)
  (if (and (setq l (tblobjname "layer" name))
	   (setq layx (entget l))
	   )
    (if (/= 4 (logand 4 (cdr (assoc 70 layx))))
      (setq laylst (cons (cons layx 4) laylst))
      )
    (entmake (list (cons 0 "LAYER")
		   (cons 100 "AcDbSymbolTableRecord")
		   (cons 100 "AcDbLayerTableRecord")
		   (cons 2 name)
		   (cons 70 4)
		   )
	     )
    )
  )

  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (progn
      (test_layer "Xrefs_Model");; change layer name
      (test_layer "Xrefs_Layout");; change layer name
      (repeat (setq i (sslength ss))
	(setq ent (entget (ssname ss (setq i (1- i)))))
	(if
	  (= 4
	     (logand 4
		     (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent)))))
	     )
	  )
	   (progn
	     (setq lay (entget (tblobjname "layer" (cdr (assoc 8 ent)))))
	     (if (= 4 (logand 4 (cdr (assoc 70 lay))))
	       (progn
		 (setq laylst (cons (cons lay (cdr (assoc 70 lay))) laylst))
		 (entmod (subst (cons 70 0) (assoc 70 lay) lay))
	       )
	     )
	     (if (= (cdr (assoc 410 ent)) "Model")
	       (entmod (subst (cons 8 "Xrefs_Model") (assoc 8 ent) ent));; change layer name
	       (entmod (subst (cons 8 "Xrefs_Layout") (assoc 8 ent) ent));; change layer name
	       )
	   )
	)
      )
      (if laylst
	(foreach lay laylst
	  (entmod (subst (cons 70 (cdr lay)) (assoc 70 (car lay)) (car lay)))
	)
      )
    )
  )
  (princ)
)

 

hope that helps

Henrique

EESignature

Message 26 of 57
braudpat
in reply to: hmsilva

 

Hello Henrique

 

SUPERB Routine , Thank you very much !

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 27 of 57
hmsilva
in reply to: braudpat

You're welcome, Patrice

Henrique

EESignature

Message 28 of 57
Kent1Cooper
in reply to: braudpat


@braudpat wrote:

.... 

But please (if possible) I will appreciate 2 versions (or ONE upgraded version, as you wish)

- "Demo_Model" will move ALL Model Space XREFs (only) to a specific Layer

- "Demo_Layout" will move ALL Layout Space XREFs (only) to an OTHER specific Layer

....


Here's a variant on my earlier one that does both of those at once.  It's shorter because it takes advantage of the LAYERP command to avoid the need to check, for each individual Xref, whether it's on a locked Layer -- it just unlocks all Layers, and LAYERP re-locks any that were locked before.  It also uses the fact that you can apply most Layer-command options [here, New and LOck] to more than one Layer at once with a comma-delimited string of names.

 

(vl-load-com)
(defun C:XLL ; = Xrefs to Locked Layer
  (/ Xrefs Xref Xrdata)
  (command "_.layer" "_new" "XrefModel,XrefPaper" "_unlock" "*" "")
  (if (setq Xrefs (ssget "_X" '((0 . "INSERT"))))
    (repeat (setq inc (sslength Xrefs))
      (setq
        Xref (ssname Xrefs (setq inc (1- inc)))
        Xrdata (entget Xref)
      ); setq
      (if (assoc 1 (tblsearch "block" (cdr (assoc 2 Xrdata)))); is it an Xref?
        (vla-put-Layer (vlax-ename->vla-object Xref); move it
          (strcat "Xref" (if (= (cdr (assoc 410 Xrdata)) "Model") "Model" "Paper"))
        ); vla-put-Layer
      ); if
    ); repeat
  ); if
  (command
    "_.layerp" ; will re-lock any Layers that were locked before
    "_.layer" "_lock" "XrefModel,XrefPaper" ""
  ); command
); defun

Kent Cooper, AIA
Message 29 of 57
braudpat
in reply to: Kent1Cooper

 

Hello Kent

 

Whaouh ! Your Routine is SUPER-SUPERB and very short !!

 

Thank you very much everybody

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 30 of 57
jahbgd
in reply to: hmsilva

Guys, 

I was trying to figure out my self how to modify this routine, but havend managed. 

 

I would like to change routine in the way the it selects vieports instead of external references. I know how to change the name of the layer 🙂

 

Thanks

Jan

Message 31 of 57
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:

... 

I would like to change routine in the way the it selects vieports instead of external references. I know how to change the name of the layer 🙂

...


Since I believe Viewport entities exist only in Paper Space [Viewports in Model Space are just subdivisions of the viewing area, and not objects that are on a Layer or can be selected], it can be a lot simpler [untested]:

 

(vl-load-com)
(defun C:VLL ; = Viewports to Locked Layer
  (/ Vprts Vprt)
  (command "_.layer" "_new" "VportPaper" "_unlock" "*" "")
  (if (setq Vprts (ssget "_X" '((0 . "VIEWPORT"))))
    (repeat (setq inc (sslength Vprts))
      (setq Vprt (ssname Vprts (setq inc (1- inc))))
      (vla-put-Layer (vlax-ename->vla-object Xref) "VportPaper"); move it
    ); repeat
  ); if
  (command
    "_.layerp" ; will re-lock any Layers that were locked before
    "_.layer" "_lock" "VportPaper" ""
  ); command
); defun

Kent Cooper, AIA
Message 32 of 57
jahbgd
in reply to: Kent1Cooper

Kent,
it reports an error...

" Enter name list of layer(s) to unlock or <select objects>: * Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
Command: ; error: bad argument type: lentityp nil
"

Please tel me, is it possible to move viewports to defpoints layer.I always keep them in defpoints as the dont print.

Thank you for your help.
Message 33 of 57
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:
Kent,
it reports an error...

" Enter name list of layer(s) to unlock or <select objects>: * Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
Command: ; error: bad argument type: lentityp nil
"

Please tel me, is it possible to move viewports to defpoints layer.I always keep them in defpoints as the dont print.
.....

Oops -- I missed one variable name in editing from the Xref version.

 

Yes, you can put them on the Defpoints Layer, by substituting that for the Layer name in the above, but I don't recommend it.  Viewports are not Dimension definition points, which is what Defpoints is for.  Better to make a non-plotting Layer for the purpose of Viewports, for various reasons that have been discussed here before.

 

(vl-load-com)
(defun C:VLL ; = Viewports to Locked Layer
  (/ Vprts Vprt)
  (command "_.layer" "_new" "VportPaper" "_plot" "_no" "VportPaper" "_unlock" "*" "")
  (if (setq Vprts (ssget "_X" '((0 . "VIEWPORT"))))
    (repeat (setq inc (sslength Vprts))
      (setq Vprt (ssname Vprts (setq inc (1- inc))))
      (vla-put-Layer (vlax-ename->vla-object Vprt) "VportPaper"); move it
    ); repeat
  ); if
  (command
    "_.layerp" ; will re-lock any Layers that were locked before
    "_.layer" "_lock" "VportPaper" ""
  ); command
); defun

 

Kent Cooper, AIA
Message 34 of 57
jahbgd
in reply to: Kent1Cooper

Sorry Kent, but it fails to make Vport layer non-plotting.
I see that you have line "VportPaper" "_plot" "_no" "VportPaper" , but layer is there , locked and plotting...

any ideas?

Thanks
Message 35 of 57
Kent1Cooper
in reply to: jahbgd


@jahbgd wrote:
Sorry Kent, but it fails to make Vport layer non-plotting.
I see that you have line "VportPaper" "_plot" "_no" "VportPaper" , but layer is there , locked and plotting...

any ideas?
...

In both 2004 & 2015 it comes out as a non-plotting Layer for me.  If, perhaps, you didn't copy & paste but typed something [such as because you want to use a different Layer name], make sure you spelled the Layer name exactly the same way in both the New option and the No-Plot option.  I don't have any other ideas....

Kent Cooper, AIA
Message 36 of 57
CivilSamurai
in reply to: hmsilva

Henrique,

 

Your routine from message 21 works great for me as I'm reaping the benefits of this thread!  I'd actually like to modify your routine to do the OPPOSITE function - take all xrefs and put them onto a specific layer (different from the locked xref layer) and UNLOCK them.  Is this an easy switch?

 

I like to have two xref layers, one "--XR-LOCKED" and "--XR-UNLOCKED" depending on what I want to visually pop out on the screen.  I like the blanket functionality your routine has where it just takes ALL xrefs but this time I'd want to send them to the unlocked layer.  Any help is appreciated!

 

Thank you,

*Mike
*Civil3D*Revit*Navisworks*ArcMAP*
Message 37 of 57
hmsilva
in reply to: CivilSamurai


@Imblueflies wrote:

Henrique,

 

Your routine from message 21 works great for me as I'm reaping the benefits of this thread!  I'd actually like to modify your routine to do the OPPOSITE function - take all xrefs and put them onto a specific layer (different from the locked xref layer) and UNLOCK them.  Is this an easy switch?

 

I like to have two xref layers, one "--XR-LOCKED" and "--XR-UNLOCKED" depending on what I want to visually pop out on the screen.  I like the blanket functionality your routine has where it just takes ALL xrefs but this time I'd want to send them to the unlocked layer.  Any help is appreciated!

 

Thank you,


Hi Mike,

a quick and dirty mod, I hope that works as expected, untested...

 

(defun c:demo (/ ENT I L LAY LAYLST LAYX SS)
  (if (setq ss (ssget "_X" '((0 . "INSERT"))))
    (progn
      (if (and (setq l (tblobjname "layer" "--XR-UNLOCKED"))
	       (setq layx (entget l))
	       )
	(if (/= 4 (logand 4 (cdr (assoc 70 layx))))
	  (setq laylst (cons (cons layx 4) laylst))
	)
	)
	(entmake (list (cons 0 "LAYER")
		       (cons 100 "AcDbSymbolTableRecord")
		       (cons 100 "AcDbLayerTableRecord")
		       (cons 2 "--XR-UNLOCKED")
		       (cons 70 0)
		 )
      )
      (repeat (setq i (sslength ss))
	(setq ent (entget (ssname ss (setq i (1- i)))))
	(if
	  (= 4
	     (logand 4
		     (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent)))))
	     )
	  )
	   (progn
	     (setq lay (entget (tblobjname "layer" (cdr (assoc 8 ent)))))
	     (if (= 4 (logand 4 (cdr (assoc 70 lay))))
	       (progn
		 (setq laylst (cons (cons lay (cdr (assoc 70 lay))) laylst))
		 (entmod (subst (cons 70 0) (assoc 70 lay) lay))
	       )
	     )
	     (entmod (subst (cons 8 "--XR-UNLOCKED") (assoc 8 ent) ent))
	   )
	)
      )
      (if laylst
	(foreach lay laylst
	  (if (not (wcmatch (car lay) "--XR-UNLOCKED"))
	    (entmod (subst (cons 70 (cdr lay)) (assoc 70 (car lay)) (car lay)))
	  )
	)
      )
    )
  )
  (princ)
)

 

Henrique

EESignature

Message 38 of 57
CivilSamurai
in reply to: hmsilva

Henrique, this worked perfectly - thank you!
*Mike
*Civil3D*Revit*Navisworks*ArcMAP*
Message 39 of 57
CivilSamurai
in reply to: hmsilva

Actually, I spoke too soon.  It seems to do everything that it's supposed to do, but it ends with this on the command line:

 

Command: XRUL ; error: bad argument type: stringp ((-1 . <Entity name: 7ffff58a1f0>) (0 . "LAYER") (330 . <Entity name: 7ffff9df820>) (5 . "195EAF") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "--XR-LOCKED") (70 . 4) (62 . 7) (6 . "Continuous") (290 . 1) (370 . -3) (390 . <Entity name: 7ffff9df8f0>) (347 . <Entity name: 7ffff9dfd80>) (348 . <Entity name: 0>))

 

Like I said, it does the job, not sure if that error really matters?

 

Thanks again,

*Mike
*Civil3D*Revit*Navisworks*ArcMAP*
Message 40 of 57
hmsilva
in reply to: CivilSamurai

I don't have AutoCAD at the moment, later on I'll see what is giving that error...

Henrique

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost