Skript 'ExportLayerObjects' with Rhino2 file format


#1

Hello Guys,

hopefully you can help me. I use Rhino4.
As I said in the Topic I want to save my Layers as single files, therefore I use the Script ‘ExportLayerObjects’ from RhinoScripts.

Option Explicit

Sub ExportLayerObjects

’ Declare local variables
   Dim strPath, strFile
   Dim arrLayers, strLayer
   Dim arrSelected

’ Get the path to and name of the current document.
   ’ Surround with double-quotes in case path includes spaces.
   strPath = Chr(34) & Rhino.DocumentPath & Rhino.DocumentName & Chr(34)

’ Get names of all layers
   arrLayers = Rhino.LayerNames

’ Disable redrawing
   Rhino.EnableRedraw False

’ Process each layer
   For Each strLayer In arrLayers

’ Unselect all   
     Rhino.Command “_-SelNone”, 0

’ Select all objects on layer. Surround layer name
     ’ with double-quotes in case it includes spaces.
     Rhino.Command "_-SelLayer " & Chr(34) & strLayer & Chr(34), 0

’ Make sure some objects were selected
     arrSelected = Rhino.SelectedObjects
     If IsArray(arrSelected) Then

’ Generate a modified path string
       ’ that includes the layer name
       strFile = strPath
       strFile = Replace(strFile, “.3dm”, “_” & strLayer & “.3dm”)

’ Export the selected objects
       Rhino.Command "_-Export " & strFile, 0

End If
   Next

’ Unselect all
   Rhino.Command “_-SelNone”, 0

’ Enable redrawing
   Rhino.EnableRedraw True

End Sub

It works properly, I can change the filetype to .STEP or .IGES. Also the default .3DM works fine.
My problem is that I want to open the newly created files in MOI, but MOI can only handle the Rhino2 .3DM file format.

Now my question, is it possible to change the .3dm output from Rhino4 to Rhino2:

’ Generate a modified path string
        ’ that includes the layer name
        strFile = strPath
        strFile = Replace(strFile, “.3dm”, “_” & strLayer & “.3dm”)

And if it’s not possible:
I can also use .step but I need to choose the STEP-Option scheme for each Layer, can i skip that?

Thanks for your help!
Cheers
Thomas


#2

I think you just need to change the following line:

Rhino.Command "_-Export " & strFile, 0

to

Rhino.Command "_-Export _Version=2 " & strFile, 0

–Mitch


#3

Hi Mitch,

thx for your answer.
I tried your solution and it seems to go into the right direction because i can open the file with MOI.
But instead of saving all layers I need to choose a layer which gets saved with the name ‘_-LayerManagerSelLayer’.

Thomas


#4

OK, I’m not understanding here - you want to just export a single layer’s objects from your list?

–Mitch


#5

Ok.
I updated the script line Rhino.Command "_-Export _Version=2 " & strFile, 0 as you said.
For example:

I’ve one sphere, a square and one pipe, each on it’s own layer called like it’s object.

When I start the script without your enhancement _Version=2, I get three .3dm files called like the layers and just the layer-assigned objects.
But its Rhino 4 .3dm and I can’t use them with MOI (“Rhino 2 .3dm” required).

After updating the script with Version=2 I get only one file with the last selected object in it and this file has also a wrong name, but it’s “Rhino 2 .3dm”, therefore it seems to be the step into the right direction.

Maybe i forget something in the script?
Hopefully it’s clearer now.

//Thomas


#6

Erm sorry Mitch,
found my fault… >-<

I had no “space” between “_Version=2” and the last Quote.
"_-Export _Version=2" instead of "_-Export _Version=2 "

Thx for your help!

//Thomas