Forgot password?

Create an account!

Forum

« back

RhinoScript – Rhino.Command save help

Messages

Please log in to write a message.

  • 3. Hanno (Nov 12, 2009 13.58):

    Hi Andrew,

    openFileName and saveFileName only let the user pick the particular file names and returns these as string, nothing else. So your approach of letting the user chose the save filename first, then doing the work and then saving the file is perfectly alright.
    If you want to work on a stack of files you need to let the user pick several files and save them in an array. Then you ask for the same number of save filenames, and then you can let your script work through each pair of filenames exactly as it does now.

    Regards

    Hanno

  • 2. andrewjohn81 (Nov 10, 2009 19.42):

    Well, I fixed it, and it works. I'm sure it still needs some help though.

    What I really want to do now is to be able to queue up several files so they run in a row. Step files take an inordinate time to import and explode.

    I solved the saving issue by saving the file early on, then just simply passing the save command. It's due to poor choice in order on my part. I'm not really sure how vbs works much with the sub routines. The only other scripting I use is ahk, and it remembers everything through each subroutine.

    Sub ExplodeVisibleBlockInstances
           
            Const rhInstanceObject = 4096
            Dim arrBlocks, strBlock


            Do
            arrBlocks = rhino.ObjectsByType(rhInstanceObject)
           
            If IsArray(arrBlocks) Then
                    For Each strBlock In arrBlocks
                                    Rhino.ExplodeBlockInstance(strBlock)
                    Next
            End If
           
            arrBlocks = rhino.ObjectsByType(rhInstanceObject)
           
            If IsNull(arrBlocks) Then Exit Do
            Loop

    End Sub 

    Sub HideAllLayers

            Dim arrLayers, strLayer
           
            arrLayers = Rhino.LayerNames
           
            For Each strLayer In arrLayers
                            If Rhino.LayerVisible(strLayer) = True Then
                                    Rhino.LayerVisible strLayer, False
                            End If
                    Next

    End Sub


    Sub ExplodeEachLayer

            Dim arrLayers, strLayer
           
            arrLayers = Rhino.LayerNames
           
           
            'Now start going through each layer one at a time
            For Each strLayer In arrLayers
                   
                    HideAllLayers
                    'make the current strLayer visible if it's not already
                    If Rhino.LayerVisible(strLayer) = False Then
                            Rhino.LayerVisible strLayer, True
                            Rhino.Print strLayer + " is now visible"
                    End If
                    'make the default layer visible if it's not already
                    If Rhino.LayerVisible("Default") = False Then
                            Rhino.LayerVisible "Default", True
                    End If
                   
                    'Run explode everything visible
                    ExplodeVisibleBlockInstances   
                   
                    'select all objects and move them to the current strLayer
                    Rhino.AllObjects(True)
                    Rhino.CurrentLayer(strLayer)
                   
            Next
           
            Call Rhino.Command("_Purge _BlockDefinitions=Yes Layers=No HatchPatterns=No _Enter", 0)
           
            FileSave
           
    End Sub

    '____________________________________________

    Sub FileSave()

    Call Rhino.Command("_Save ", 0)
    MsgBox "Save completed! Please ensure there are no blocks left. Hit OK, to open Block manager."
    Call Rhino.Command("_BlockManager", 0)
           
    End Sub

    '_____________________________________________

    Sub GetStep()

    Dim strFile
    Dim strFilesavename

    strFile = Rhino.OpenFileName("Open", "Model Files (*.stp)|*.stp|All Files (*.*)|*.*||")
    If IsNull(strFile) Then Exit Sub

    Call Rhino.DocumentModified(False)  'this makes rhino think the doc isn't modified

    strFile = Chr(34) & strFile & Chr(34)  'this fixes the fact that the file may have spaces in the name


    'this section is for saving info

    strFilesavename = Rhino.SaveFileName ("Save", "Rhino 3D Models (*.3dm)|*.3dm||")
    strFilesavename = Chr(34) & strFilesavename & Chr(34)

    If  IsNull(strFilesavename) Then
    MsgBox "The save thing didn't take"
    End If


    'strFilesavename = Rhino.SaveFileName ("Save", "Rhino 3D Models (*.3dm)|*.3dm|All Files (*.*)|*.*||")





    Call Rhino.Command("_-Open " & strFile, 0)  'open the file you selected initially.
    MsgBox strFilesavename
    Call Rhino.Command("_-SaveAs " & strFilesavename, 0)
    ExplodeEachLayer

    End Sub

    GetStep
  • 1. andrewjohn81 (Nov 10, 2009 18.37):

    I'm trying to create a script that opens a user selected step file, allows the user to select where it will be saved (the type should automatically be 3dm) and then continues to open the step file. After it's open the script should also explode the block instances. I took that part, for the most part, from www.rhino3d.com/developer.htm
    Although, that didn't work by default, so I tried to kind of recreate it. That's really hard to do for a noob like me though, because I don't know the purpose of some things in the first place. Anyway, it works most of the time. I need to add a purge command in there, but as you can see, it's pretty messy.

    I'm having troubles finding info for Rhino.Command. I don't understand why I'm using

    Call Rhino.Command("_-Open " & strFile, 0)

    top open the file. I don't understand the '&' there. Isn't that for adding two strings? I thought the syntax was just one command after another separated by commas between the parenthesis. And what's up with the '0' at the end? I don't understand what that's for.
    Can anyone let me know where to find that sort of info? I'd prefer read about it myself so I can find more help later without bugging anyone.

    This script doesn't work yet, but I wanted to share it's progress. I can't get the save name to work. That and I'm missing a purge in there, so the blocks are all exploded, but the last few don't get removed.

    Any help is appreciated:

    Sub ExplodeVisibleBlockInstances
           
            Const rhInstanceObject = 4096
            Dim arrBlocks, strBlock


            Do
            arrBlocks = rhino.ObjectsByType(rhInstanceObject)
           
            If IsArray(arrBlocks) Then
                    For Each strBlock In arrBlocks
                                    Rhino.ExplodeBlockInstance(strBlock)
                    Next
            End If
           
            arrBlocks = rhino.ObjectsByType(rhInstanceObject)
           
            If IsNull(arrBlocks) Then Exit Do
            Loop

    End Sub 

    Sub HideAllLayers

            Dim arrLayers, strLayer
           
            arrLayers = Rhino.LayerNames
           
            For Each strLayer In arrLayers
                            If Rhino.LayerVisible(strLayer) = True Then
                                    Rhino.LayerVisible strLayer, False
                            End If
                    Next

    End Sub


    Sub ExplodeEachLayer

            Dim arrLayers, strLayer
           
            arrLayers = Rhino.LayerNames
           
           
            'Now start going through each layer one at a time
            For Each strLayer In arrLayers
                   
                    HideAllLayers
                    'make the current strLayer visible if it's not already
                    If Rhino.LayerVisible(strLayer) = False Then
                            Rhino.LayerVisible strLayer, True
                            Rhino.Print strLayer + " is now visible"
                    End If
                    'make the default layer visible if it's not already
                    If Rhino.LayerVisible("Default") = False Then
                            Rhino.LayerVisible "Default", True
                    End If
                   
                    'Run explode everything visible
                    ExplodeVisibleBlockInstances   
                   
                    'select all objects and move them to the current strLayer
                    Rhino.AllObjects(True)
                    Rhino.CurrentLayer(strLayer)
                   
            Next
           
            FileSave
           
    End Sub

    '____________________________________________

    Sub FileSave()
    MsgBox strFilesavename
    Call Rhino.Command("_-SaveAs " & strFilesavename, 0)  
           
    End Sub

    '_____________________________________________

    Sub GetStep()

    Dim strFile
    Dim strFilesavename
    file
    strFile = Rhino.OpenFileName("Open", "Model Files (*.stp)|*.stp|All Files (*.*)|*.*||")
    If IsNull(strFile) Then Exit Sub

    Call Rhino.DocumentModified(False)  'this makes rhino think the doc isn't modified

    strFile = Chr(34) & strFile & Chr(34)  'this fixes the fact that the file may have spaces in the name


    'this section is for saving info

    strFilesavename = Rhino.SaveFileName ("Save", "Rhino 3D Models (*.3dm)|*.3dm||")

    If  IsNull(strFilesavename) Then Exit Sub


    'strFilesavename = Rhino.SaveFileName ("Save", "Rhino 3D Models (*.3dm)|*.3dm|All Files (*.*)|*.*||")





    Call Rhino.Command("_-Open " & strFile, 0)  'open the file you selected initially.
    ExplodeEachLayer

    End Sub

    GetStep
Recommend

Why are these buttons gray?