Create layer and put select objects to the newly created layer.

Create layer and put select objects to the newly created layer.

Christian.mendoza2
Contributor Contributor
1,906 Views
16 Replies
Message 1 of 17

Create layer and put select objects to the newly created layer.

Christian.mendoza2
Contributor
Contributor

Hello,

Does anyone have a lisp routine that creates layer from selected object, using the object's layer name but adding a suffix? Example of object layer name is TREE; created layer will be TREE-TBR. In addition, can the selected object be on the newly created layer? This could help a lot to speed up the topographic base drawing processing, isolate existing entities (to be removed) and put them on a separate layer.

 

The request above might be a bit complicated, maybe a lisp routine to create a layer and put the selected objects to the newly created layer (C-SITE-TBR). If the layer already exists, just put the selected objects to this layer.

 

I hope anyone could help me speed up things a little bit on our process. Thank you in advance.

0 Likes
Accepted solutions (2)
1,907 Views
16 Replies
Replies (16)
Message 2 of 17

AllenJessup
Mentor
Mentor

Until then.create the Layer manually and set it current. Use LAYCUR to select objects to be moved to that layer/

Allen Jessup
CAD Manager - Designer
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 3 of 17

pendean
Community Legend
Community Legend

How would you know if an object is on this new layer *TBR? Should it be a different color, nd if so what would that be?

 

Are all source layers the same color, or will the TBR layer need to change if say you answered RED above but the source layer is also red?

 

Do the TBR need to have a special linetype? usually layers with content scheduled for removal may have a dashed line for example.

Are what you selecting always a block? picking a leaf on a non-block 'tree' will only move the leaf to the new layer, not the entire tree, for example.

 

Are your files created in Civil3D by chance?

0 Likes
Message 4 of 17

Christian.mendoza2
Contributor
Contributor

TBR layers will be on a different color, to identify one from the other. Layer properties can be controlled by the layer state. The important thing is to have the object to that particular layer. Our files topographic drawings utilize civil 3d objects.

0 Likes
Message 5 of 17

Christian.mendoza2
Contributor
Contributor

That's what we are doing at the moment, thank you.

0 Likes
Message 6 of 17

ec-cad
Collaborator
Collaborator
Accepted solution

Here's a little Lisp that will 'move' items to Layername that you input.

Makes the Layer (if not existing or if it exists already).

Selects objects to 'move' - changes properties of those objects to Layer Layername.

 

(defun C:MTL (); Move To Layer
 (setq olay (getvar 'clayer))
 (setq NL (getstring "\nTarget Layer Name ?"))
 (if NL
  (progn
   (princ (strcat "\nPick the Objects to move to " NL " Layer:"))
   (setq ss (ssget))
    (if ss
     (progn
      (command "_layer" "M" NL "")
      (command "_Change" ss "" "P" "LA" NL "")
      (setq Len (sslength ss))
      (prompt (strcat "\nMoved " (itoa Len) " Items to Layer " NL))
     ); progn
    ); if
   ); progn
  ); if
  (Command "_layer" "S" olay "")
  (princ)
 ); function
 (princ); silent load

 

Just appload it, or drag / drop into Acad.

Function call is MTL at command line.

 

ECCAD

Message 7 of 17

Kent1Cooper
Consultant
Consultant

@Christian.mendoza2 wrote:

.... a lisp routine to create a layer and put the selected objects to the newly created layer (C-SITE-TBR). If the layer already exists, just put the selected objects to this layer. ....


Is it to be assumed that you could select multiple objects that may be on different Layers, and you want each one put on a -TBR Layer based on its own current Layer?  That is, in multiple selection you don't want everything selected to go to the same Layer?  [Certainly possible, but it does mean processing the selection one object at a time.]

 

Also, presumably a routine should check that an object is not already on a Layer with that ending, so that you don't end up eventually creating something like a "C-SITE-TBR-TBR-TBR" Layer.

 

[A routine could just create the new Layer and move the object into it, without checking whether it's already in the drawing.  For a Layer command, it won't matter if it is.]

Kent Cooper, AIA
Message 8 of 17

Christian.mendoza2
Contributor
Contributor

I just tried this, and this is what I needed. Thank you very much ec-cad, appreciate it so much!

0 Likes
Message 9 of 17

Christian.mendoza2
Contributor
Contributor

Hello Kent, I see your point regarding multiple replications. I was thinking selecting one object at a time only. I am pretty new with LISP, just starting to learn how it works. Thank you for your input on this.

0 Likes
Message 10 of 17

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this, which lets you select as many as you want [no need to pick them one at a time], but processes each separately as I described above, checking for whether each one is already on such a Layer, and unlike Message 6 does not require you to spell out the Layer name, nor put the entire selection on the same Layer.  Lightly tested.

 

(defun C:MTBRL ; = Move to -TBR Layer
  (/ ss n ent elay)
  (if (setq ss (ssget "_:L")); anything on unlocked Layer(s)
    (repeat (setq n (sslength ss))
      (setq
        ent (ssname ss (setq n (1- n)))
        elay (cdr (assoc 8 (entget ent)))
      ); setq
      (if (not (wcmatch (strcase elay) "*-TBR")); not already on such a Layer
        (command ; then
          "_.layer" "_new" (strcat elay "-TBR") "" ; create it [not made current]; OK if it already exists
          "_.chprop" ent "" "_layer" (strcat elay "-TBR") ""
        ); command
      ); if [no else -- leave alone if already on such a Layer]
    ); repeat
  ); if
  (prin1)
)

 

It could include a color option in the Layer command, if all your -TBR Layers would be of the same different color.

Kent Cooper, AIA
Message 11 of 17

Christian.mendoza2
Contributor
Contributor

Just ran the lisp, twice. Like you said, it did not create the TBR string. Appreciate the way you composed it, with the description; makes it easier to understand for us beginners. Thank you very much Kent!

0 Likes
Message 12 of 17

ec-cad
Collaborator
Collaborator

You are very Welcome !

 

ECCAD

0 Likes
Message 13 of 17

Sea-Haven
Mentor
Mentor

This sounds very much like import points with a tree description, PENZD, so read the description and put the point on correct layer, then can have multiple tree layers with correct block and correct layer. Second part is description has trunk and spread again this is handled by a dynamic block to show tree spread and trunk, 2 objects, visually at correct size.

 

Am I correct ? Has been asked elsewhere here.

0 Likes
Message 14 of 17

Christian.mendoza2
Contributor
Contributor

Sounds a great way to import Cogo points Sea-Haven. Unfortunately, we are referring to the design phase of topo processing, isolating objects to be removed (TBR) to another layer so I can freeze them on the improvement plans. Kent and ECCAD have sent the Lisp routines I needed.

Thank you, everyone for taking a look at this. This forum, definitely, is the best source of tools and information to make designing easy and efficient. Appreciate it very much!

0 Likes
Message 15 of 17

Christian.mendoza2
Contributor
Contributor

Hello Kent. Is there a way to tweak the lisp below to match the old object's linetype but the color will be 9? That way, I still can xref it on my plans and look the same, but faded? Hope you could help me on this, Thank you.

0 Likes
Message 16 of 17

Kent1Cooper
Consultant
Consultant

@Christian.mendoza2 wrote:

.... Is there a way to tweak the lisp below to match the old object's linetype but the color will be 9? ....


If by "the lisp below" you mean the accepted-solution code in Message 10, change line 12 in it to this:

"_.chprop" ent "" "_layer" (strcat elay "-TBR") "_color" 9 ""

But I'm not sure that's what you're after, because there's no "old object" or presumed "new object" to match to it.  It's still the same object, just put on a different Layer.  If I've misunderstood, explain in greater detail.

Kent Cooper, AIA
0 Likes
Message 17 of 17

Christian.mendoza2
Contributor
Contributor

Say I have an object on TREE layer. I want the object to be on TREE-TBR layer. TREE-TBR layer should match the linetype of TREE layer, but the color should be 9. This way, I can use it on polyliines amd lines on my ex. utility linewroks.

0 Likes