Help: Script that copy's names from one child layer to another

[edit] in code for _ display

Ahh I think I see what it is,

From your example it seems that the script copies the name from the _2D to the _3D layer.

As you can see in the updated test file(s) I've send you it should check what the _3D layer with the same "variable data" has for a name, and copy the entire name of the _3D Layer, and replace the _2D layer with that name.

I've got a feeling we've misunderstood that part.

I am not sure how this part could work.
In your example,

1;TQ-40.8354.010;Aerator;Male M24x1.0 (STD) Honeyc. white;Assembly part;1;[BLOCK]

corresponds to

01;TQ-40.8354.010;Aerator;Male M24x1.0 (STD) Honeyc. white;Assembly part;1;

but

1;TD-52 28.5 1.0;Washer;Ø52xØ28.5x1.0;Stainless steel;1;[BLOCK]

does not have correspondences.
[EDIT]…Or actually… You mean that:

15;TD-52 28.5 1.0;Washer;Ø52xØ28.5x1.0;Stainless steel;1;

is the correspondence, right? If this is the case, I think I know what we can do.

Otherwise, I fear you will have to edit the script yourself or devise another logic if the one I came up with does not work for you. The main isssue I am not sure about is how the script can match (and not just add) layers if they do not have precise correspondences.

Thanks, I hope this helps,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hello Giulio, I do see the corresponding layer, are you sure you don’t see this layer in the file i’ve send you?

_2D item:
1;TD-52 28.5 1.0;Washer;Ø52xØ28.5x1.0;Stainless steel;1;[BLOCK]

_3D item:
15;TD-52 28.5 1.0;Washer;Ø52xØ28.5x1.0;Stainless steel;1;

Also, if a layer does not have any objects does not matter, but as you say if a layer would not exist I would personally just pause the script give feedback what layer causes a problem and choose to continue/abort.

I see. I’ll try to have a look at this in the afternoon.

You sent a file with all linked blocks and those blocks are in an “R:” folder that I don’t have. That being said, I think I understand what you mean now.

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

No rush, I’m already happy everyone here is so helpful! @djordje @piac @Helvetosaur and all others i’m forgetting!

I’m working on manually changing the names at the moment, but there is still a lot to do, and sadly the way make2D works now it will be manually renaming at every new make2D, but hopfully in the new Rhino this will change :slight_smile:

I would be very interested in hearing what change would help you. Please, could you elaborate? The main issue is the difference in layer name that requires matching that puzzles me.

In this topic’s first post you can see an example of what the problem is with the make2D in our case.

The problem arises because the Make2D option with “maintain source layers” takes the layers from the contents of the blocks. Rather then the actual layer the block is put in. This is not necessarily wrong behavior from the software but it causes us to have to go in afterwards and change all the prefix numbers and quantities from “1” to the proper amount, and removing the “[BLOCK]” parts of the names.

The prefix number and quantities we’ve set to 1 in the block as a default because they differ per product they are in. While making the products in 3D we place the blocks and move them to new layers with correct names. After this step we create 2D drawings using the “make2D” option.

Our goal would want to have the “maintain source layers” use the names of the layers the blocks are placed in.

I hope this information + the link to the post will explain our problem. The reason why i’m trying to get a script as this one working, is because I’m expecting that the “maintain source layers” option is working as intended, and this is only a problem for us.

Thanks for the clear explanation. I’ve reported this wish and usability problem. We might be able to tackle this in a next release of Rhino.
http://mcneel.myjetbrains.com/youtrack/issue/RH-23658

For now, I’ve tested this improved version of the script with the file that you sent me in the PM.
Have a look if it helps, and if it does, please let me know (:

It tries to look up the corresponding layer in any layer name that does not end with [BLOCK]. If it does not succeed, it will alert you. Really, you can try to improve this script to fit your purposes better. Having scripting/programming backgrounds in other languages will definitely help you.

layers-Peter-semicolon-lookup.py (2.7 KB)

Thanks,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Super! The searching the corresponding layers is working great! Feedback is wonderful! Only 1 problem, after running the script I checked the layers and they don’t seem to have changed. Or could it just be the layers need a refresh somehow?

[edit] And I just noticed while running the script, it seems to be deleting the curves that where on the _2D layers where it had matches on. Shall I send you one of the actual files to try it on?

Have a look if this helps better.
Thanks,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

layers-Peter-semicolon-lookup-specific.py (2.7 KB)

Perhaps this clears things up from the original post, It is really only the names that need to be changed, no objects/layers need to be moved or deleted, just the names of the _2D layers.

//////////////////////////////////////////////////
//
//Example
//22.003.501_2D
//	1;TB-20 16 5;Washer;Ø20xØ16x2.5;1;[BLOCK]
//	1;BBE-2259393;Body;30x20x60;1;[BLOCK]
//
//22.003.501_3D
//	01;TB-20 16 5;Washer;Ø20xØ16x2.5;4;
//	02;BBE-2259393;Body;30x20x60;2;
//
//Should become:
//
//22.003.501_2D
//	01;TB-20 16 5;Washer;Ø20xØ16x2.5;4;
//	02;BBE-2259393;Body;30x20x60;2;
//
//22.003.501_3D
//	01;TB-20 16 5;Washer;Ø20xØ16x2.5;4;
//	02;BBE-2259393;Body;30x20x60;2;
//
//////////////////////////////////////////////////

You cannot change the name of layer to a name that already exists. What you can do is move all objects and then remove the old layer, for example. Would that work for you?

Following our conversation in PM: here are two alternative actions for the script:
One that moves only curves on the XY plane:
layers-Peter-semicolon-lookup-specific-onlycurves-no-delete.py (2.8 KB)

And one that moves everything and then deletes the layer:
layers-Peter-semicolon-lookup-specific-everything-delete.py (2.7 KB)

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Thinking based on the script provided so far, that I could make a variable out of the layer_parts?

        layer_parts = layer.split("::")
NewName = layer_parts[2]

[edit]

Seem to have gotten it!! Only strange thing is the script forgets the “always” every now and then, and have to choose “always” again

            layer_parts = new_layer.split("::")
        new_name = layer_parts[2]
        print(new_name)
        rs.RenameLayer(layer, new_name)

As long as the layer is not in the same sublayer you can right? At least I believe i’ve got it almost working now :blush:

That’s correct. In reality the layer name is just the whole path to the layer at hand, including all parents, connected with :: . This means that even if just one parent is different, then the layer name is really different. It’s very good to hear that you are making progress! It’s hard to define exactly the whole behaviour, but as you are now on a good path, it should be possible for you to exactly define all remaining details.

Thanks, kind regards,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Yeah going good, Now I just need to put this in to search for the part of the layer, instead of the split/bits part:

layer_2d = "1;pietjepuk;23-23x223-L50;metaal;1;[BLOCK]"
layer_3d = "09;pietjepuk;23-23x223-L50;metaal;6;"

layer_2d_kort = layer_2d.strip('1;' '1;[BLOCK]')

print layer_2d_kort

Which prints out

pietjepuk;23-23x223-L50;metaal

I think I infer from the PM that you mean this change (the attributes part matched till the second-last bit)

Peter_layer_Fixer_1.2.py (2.7 KB)

Yes! :slight_smile: perfect, working great!

Thank you so much! I’m glad we worked it out, together even in the end, I’m getting the hang of python scripting style already.

Hi Peter. I’m reviewing this bug, which was filed a while back based on your request. I can see that you already have the script to do what you need, but I wanted to check with you to see if there are other improvements we can bring to Make2D in V6. Have you tried the new Make2D? Does it solve some of your issues, or do you have suggestions to make it work better in your workflow?