Make2D - Maintain source layers


#1

I have a file where blocks are used in multiple different objects, these objects have their own sub-layers and those contain said blocks. Though, the sub-layers naming is slightly different as the block naming.

When using the maintain source layers option in the Make2D function the names are taken from the blocks, instead of the actual layer that is the direct source of the object selected.

While the “source layer” of the selected block should be the layer in which it is located I would reckon?


Example:
With the objects from layer “ObjectA” selected I activate Make2D with maintain source layer option.

ObjectA

  • 01;Tap;5x5x2;steel;2;
  • 02;Body;5x5x100;steel;2;
  • 03;Screw;M2x0.35-L3;steel;4;

[BLOCKS]

  • 01;Tap;5x5x2;steel;1;
  • 01;Body;5x5x100;steel;1;
  • 01;Screw;M2x0.35-L3;steel;1;

Make2D result:

  • 01;Tap;5x5x2;steel;1;
  • 01;Body;5x5x100;steel;1;
  • 01;Screw;M2x0.35-L3;steel;1;

Expected result:

  • 01;Tap;5x5x2;steel;2;
  • 02;Body;5x5x100;steel;2;
  • 03;Screw;M2x0.35-L3;steel;4;

#2

Bump


#3

Hi Peter,
Currently the only way to reach your desired result is to explode the blocks, run Make2D and undo the explode.

hth, Tobias


#4

Hello Tobias,

Thank you for the tip, I’ll give it a shot later today!


#5

@tobias
This does not seem to work. When exploding the blocks all resulting objects are put together in the default layer.


Is there any change on this in the new version of Rhino with the improved make2d??


#6

Hi Peter,

If I understood you correctly you have a block, consisted of many objects - where each of those objects has it’s own layer. Those objects layers, differ from the ones the overall block belongs to?
And what you want is to take all those lines Make2D command creates back to the layer to which the initial block belonged to?
If that is so, then try this Python script (I attached it too, at the bottom of the post):

import rhinoscriptsyntax as rs

def make2D_change_layer():
# identify the object's layer
    selectObj = rs.GetObject("Select the block",0,True,True) 
    if selectObj:
        oldLayer = rs.ObjectLayer(selectObj)
        
        # run Make2d command
        runMake2D = rs.Command("_Make2D")
        if runMake2D:
            # take Make2d command results and send it to initial block's layer
            make2Dresult = rs.GetObjects("",0,True,True)
            changedLayer = []
            for item in make2Dresult:
                changedLayer.append(rs.ObjectLayer(item,oldLayer))
            rs.DeleteLayer("Make2D")
        else:
            print "You did not select the same block for the second time. Script terminated"
            return
    else:
        print "You did not select the block. Script terminated"
        return

make2D_change_layer()

Running this script requires downloading it, and then: Tools -> PythonScript -> Run.


You can also make a button out of this script:
Right click on your Toolbar, and choose “New tab”. This will create a new tab, and one button (with an icon of yellow smiley face) in it:

Click on that button.
Under appearance, choose “Text only” radio button and type the desired name for this command (like “make2d layer” for example).
In the “Left mouse button”'s Command window, paste following code:

-_RunPythonScript (
import rhinoscriptsyntax as rs

def make2D_change_layer():
# identify the object's layer
    selectObj = rs.GetObject("Select the block",0,True,True) 
    if selectObj:
        oldLayer = rs.ObjectLayer(selectObj)
        
        # run Make2d command
        runMake2D = rs.Command("_Make2D")
        if runMake2D:
            # take Make2d command results and send it to initial block's layer
            make2Dresult = rs.GetObjects("",0,True,True)
            changedLayer = []
            for item in make2Dresult:
                changedLayer.append(rs.ObjectLayer(item,oldLayer))
            rs.DeleteLayer("Make2D")
        else:
            print "You did not select the same block for the second time. Script terminated"
            return
    else:
        print "You did not select the block. Script terminated"
        return

make2D_change_layer()
)

Basically it should look like this:

Hit OK.
Now you can run the script by left clicking on that button.
(btw you can also add an icon instead of just having text over the button, but I guess you can figure that out)

Merry Christmas !!

make2d_change_layer.py (885 Bytes)


How to know/ figure out what functions I need (Search & replace names)
#7

Back at work in the new year!

@djordje thank you for your elaborate help!

Here we go, actually it is one file with a lot of blocks. The placed blocks have been moved to other layers, but when using the “Make2D” option, with use source layers, takes the layer names of the blocks.

These are of course the actual source layers, but for our case we need to have the names of the layers that the blocks are placed in rather then the names where they are imported under or the names of the layers in the block itself.


#8

Hi Peter,

It is very difficult to talk about this, without the actual .3dm file.

The way I understood you is following - for example:
You have a block. Let’s say that block belongs to “Layer10”.
Now, this block is consisted of 3 spheres: first sphere belongs to “Layer1”, second sphere belongs to “Layer2”, third one to “Layer3”. When you run “Make2D” command with “Maintain source layers” option checked, it will convert your block of 3 spheres into 3(or 6, does not matter) curves where each of those belongs to their respective layers from the block “Layer1”, “Layer2”, “Layer3”.
What you want is to have these 3(6) new curves set to layer to which the actual block belonged to - “Layer10”.
The attached .py files does that.

Did I get all this wrong?


#9

No it does not have to do with the layers inside of the blocks

the file looks like this:

Model 1
- Layer A
- Layer B
- Layer C
Model 2
- Layer A
- Layer F
- Layer G
BLOCKS
- (imported)Layer A
- (imported)Layer B
- etc.

When the blocks are inserted, they come into the file on the “Blocks” layer since all the current blocks have the following structure.

BLOCKS
- object name;material;amount

After inserting the blocks, they are moved to different sub-layers in several Main layers. So the problem is rather inside the main file rather then inside the blocks. The make 2D takes now the name of the layer where the block originally came into the file or the layers from inside of the specific blocks, rather then the current layer where it resides. And the last functionality is what I am trying to achieve.

Does this make more sense? Otherwise I will make a sample file.


#10

Yes, please attach the file. I am not following, sorry.


#11

Test.rar (108.3 KB)

I’ve build a simple test file, here you can see the original layers “Blocklayer” taken from inside of the blocks automatically, and the self made layers.

Model_A
- Cube;2
- Cone;1
- Cylinder;4
- Ring;1

As you can see in the file, I’ve used “Objectname;Amountofobjects” as layer names. This is the information I would want to have in the Make2D layer names. (this is a simplified version of the full file, the full layers have a lot more data)

Current result of make2d & wanted result of make2d:

Current effect:    
Make2D
    => Blocklayer
    --> CubeBlock
    --> ConeBlock
    --> CylinderBlock
    --> RingBlock

Wanted effect:    
    Make2D
    => Model_A
    --> Cube;2
    --> Cone;1
    --> Cylinder;4
    --> Ring;1

#12

So when you use the term “block” you are actually refering to a list of sub-layers within certain parent layer?
Not the actual Rhino block instances?

Sorry I can’t help you. I do not understand.


#13

Block = A block instance.
Blocklayer = the parent layer within the blocks, and when inserting one of the files as a block this is put into the file also and can not be deleted.

You can check it in the attached files, just look at the layer names and check the block manager.


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

Hello Tobias,

I finally managed to give your approach a shot, sadly this does not seem to work as easy as “ExplodeBlocks” and Make2D, the layers when using the command ExplodeBlocks are given up, and all the resulting objects are put into the “current active layer”