Jump to content

Select All on Layer and move to Another Layer


mstg007

Recommended Posts

I was wondering how to select all entities on a layer and then move them to another layer via a dialog box or something.

 

I was starting off with the basic routine that would allow me to select the objects on the layer.

 

(defun c:sellay (/ e )
 (if (setq e (nentsel "Select entity on a layer: "))
   (sssetfirst nil (ssget "_X" (list (cons 8 (cdr (assoc 8 (entget (car e))))))))
  )
 (princ)
)

But I am having trouble figuring out how to link the selection to maybe a command like "Layer Match" and use its dialog or alike.

 

Thank you for any pointers.

Link to comment
Share on other sites

After you get your selection, use MA ( Matchprop ) pick your source object, then use P ( previous ) and it will update your set.

 

FWIW, you can shorten this up a bit by removing the unnecessary (cons 8 (cdr ...

(defun c:sellay	(/ e)
  (if (setq e (nentsel "\nSelect entity on a layer: "))
    (sssetfirst nil (ssget "_X" (list (assoc 8 (entget (car e))))))
  )
  (princ)
)

Here's another to match the layer of a picked item:

(defun c:sellay	(/ a b)
  (if (and (setq a (car (nentsel "\nSelect entity on a layer to change: ")))
	   (setq b (car (nentsel "\nSelect entity to match layer: ")))
	   (setq b (assoc 8 (entget b)))
      )
    (foreach x (mapcar 'cadr (ssnamex (ssget "_X" (list (assoc 8 (entget a))))))
      (entmod (subst b (assoc 8 (entget x)) (entget x)))
    )
  )
  (princ)
)

 

Edited by ronjonp
Link to comment
Share on other sites

What I was trying to do; we get other drawings from other places. We usually have to "breakout" or change there dwg content to our own layers.

Usually I insert our layers and then freeze them off. Use the above routine to select the entities then move them over to the correct layer. And to top that off. we usually get drawings from a lot of different places, so its usually never the same.

 

 

Link to comment
Share on other sites

There is no quick way you can make a text file etc for a company using a csv file oldlayer,newlayer, just process the layers selecting and changing.

 

Its pretty easy to dump all the layers to a text file put in say excel, handy where layer's go on one layer.

 

Do a ssget like above use (cons 8 oldlayer) can use chprop rather than process each entity speed may come into it. (command "Chprop" ss "" "la" "newlay" "")

 

(setq fo (open "D:\\acadtemp\\layers.txt" "w"))
(setq lays (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
(vlax-for lay lays
(write-line (vla-get-name lay) fo)
)
(close fo)

 

Link to comment
Share on other sites

Why don't you make a common list of old layer / new layer and process .. I understand there are different clients but there has to be some similarities in your field?

 

Quick example:

(defun c:foo (/ s)
  (vlax-for a (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for b	a
      (setq s (strcase (vla-get-layer b) t))
      (entmod (append (entget (vlax-vla-object->ename b))
		      (list (cons 8
				  ;; Update the list to what you need
				  (cond	((wcmatch s "*walk*,*street*,*asphalt*") "hardstuff")
					((wcmatch s "*chicken*,*sparrow*,*cockatoo*") "birds")
					("No Match")
				  )
			    )
		      )
	      )
      )
    )
  )
  (princ)
)

 

There is also LAYTRANS which may do a bulk of the work for you:

 

image.png.ad7731b3d58062b08e2a2900edb06e69.png

 

Link to comment
Share on other sites

I think I can use the wildcard catch to get most of the non standard layers to standard layers using your above method. Some of these drawings have a ton of layers. I think this will help to speed things up as going through the non standard drawing. With the remaining that it cannot find, I can manually move it over like I mentioned earlier.

 

Let me play around with this idea. Thank you for the input!

Link to comment
Share on other sites

1 hour ago, mstg007 said:

I think I can use the wildcard catch to get most of the non standard layers to standard layers using your above method. Some of these drawings have a ton of layers. I think this will help to speed things up as going through the non standard drawing. With the remaining that it cannot find, I can manually move it over like I mentioned earlier.

 

Let me play around with this idea. Thank you for the input!

Glad to help. 🍻

Link to comment
Share on other sites

  • 3 years later...
On 1/29/2020 at 10:31 AM, ronjonp said:

Why don't you make a common list of old layer / new layer and process .. I understand there are different clients but there has to be some similarities in your field?

 

Quick example:

(defun c:foo (/ s)
  (vlax-for a (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for b	a
      (setq s (strcase (vla-get-layer b) t))
      (entmod (append (entget (vlax-vla-object->ename b))
		      (list (cons 8
				  ;; Update the list to what you need
				  (cond	((wcmatch s "*walk*,*street*,*asphalt*") "hardstuff")
					((wcmatch s "*chicken*,*sparrow*,*cockatoo*") "birds")
					("No Match")
				  )
			    )
		      )
	      )
      )
    )
  )
  (princ)
)

 

 

Hi Ronjonp,

 

This is exactly what I am trying to do without using the layer translation table.

My command looks like the following:

 

(defun c:HPO (/ s)
  (vlax-for a (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for b    a
      (setq s (strcase (vla-get-layer b) t))
      (entmod (append (entget (vlax-vla-object->ename b))
              (list (cons 8
                  (cond    ((wcmatch s "*Building*") "HPO-Building")
                    ((wcmatch s "*Outdoor*") "HPO-Outdoor")
                    ((wcmatch s "*Setout*,*Offset*") "HPO-Setout")
                    ((wcmatch s "*Bdy*,DP*,CP*,Stage*") "Bdy")
                    ("No Match"
                  )
                )
              )
          )
      )
    )
  )
  (princ)
)

 

Running the command doesn't work. 

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

Wcmatch is case sensitive.

 

This returns all lower case ( t ) : (setq s (strcase (vla-get-layer b) t))

 

And in your check you have a mix of case: (wcmatch s "*Building*") so make them all lower case and it should work.

Edited by ronjonp
Link to comment
Share on other sites

Thanks for getting back to me, I should've been a bit more specific, I can't actually get the command to run. Typing the Defun command does not register, nor does it show in the dynamic input that such a command exists, even after I have loaded the lisp and restarted Acad.

Thanks for your help

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...