Perl script detach_all.pl for Modo takes a multi-part object and splits all the contiguous geometry into their own layers. Good for vehicle models, architectural models or physics simulations preparation or anything that you don’t want to copy and paste into new layers hundreds of times.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# perl script for Modo: split mesh into layers

$layerID = lxq("query layerservice layer.ID ? main");
$sceneID = lxq("query sceneservice selection ? locator");

if ($layerID eq $sceneID) {

    # lxmonInit(100); #add zeros to increase bar accuracy.  Match $barstep.

    $origName = lxq("query layerservice layer.name ? main");

    lx("layer.setVisibility "$origName" false");
    lx("item.duplicate");
    lx("select.type polygon");

    $tempIndex = lxq("query layerservice layer.index ? main");
    $tempPolysAll = lxq("query layerservice poly.N ? all");
    $tempPolys = $tempPolysAll;

    lx("item.create groupLocator "detach all $origName"");
    $groupID = lxq("query sceneservice selection ? locator");

    while ($tempPolys != 0) {
   
        lx("select.drop item");
        lx("select.layer $tempIndex");
        lx("select.element $tempIndex polygon add 1");
        lx("select.polygonConnect");
       
        lxq("query layerservice layer.index ? main");
        $PolysSelected = lxq("query layerservice poly.N ? selected");
       
        lx("select.cut");
       
        lxq("query layerservice layer.index ? main");
        $tempPolys = lxq("query layerservice poly.N ? all");
       
        lx("item.create mesh "$origName part"");
        lx("select.paste");

        $childID = lxq("query layerservice layer.ID ? main");

        lx(qq(item.parent "$childID" "$groupID"));
       
        # comment out here through dialog for math check for script to work without loading bar.  Also comment out lxmoninit
        # currently a bug in Modo causes the loading bar to crash the software.
       
        # $barStep = $PolysSelected / $tempPolysAll * 100; #add zeros to increase bar accuracy.  Match lxmonInit
        # $barStepAdd = $barStepAdd + $barStep; #temporary checking math goes with dialog below
       
        # lxmonStep($barStep);
       
        # if( !lxmonStep ) {
            # die( "User Abort" );
        # }
       
        #math check dialog, remove after testing.  Do not run large objects without commenting out.
        # lx("dialog.setup info");
        # lx("dialog.title "Detach All"");
        # lx("dialog.msg "Step: $barStep Percent: $barStepAdd"");
        # lx("dialog.open");       
    }
   
    lx("select.layer $tempIndex");
    lx("delete");  
   
}

else {
   
        lx("dialog.setup info");
    lx("dialog.title "Detach All"");
    lx("dialog.msg "Select mesh layer"");
    lx("dialog.open"); 

}  
   
# lxmonInit(100);
# lxmonStep();