Make2D - Maintain source layers

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)