Forgot password?

Create an account!

Forum

« back

RhinoScript – Generate Layers from Filenames

Messages

Please log in to write a message.

  • 3. rubenruckman (Oct 29, 2014 22.54):

    This script prompts you to choose IGS files, then dumps the joined surfaces onto a layer that uses the IGES's filename. Should help your import process:

    Option Explicit
    Call ImportBatchFiles()

    Sub ImportBatchFiles()
           
            Dim arrFileNames, strFileName, strObject, i, newLayer, strPath, arrObjects

            arrFileNames = Rhino.OpenFileNames("Open", "IGS (*.igs)|*.igs|All Files (*.*)|*.*||")

            If IsArray(arrFileNames) Then

                    For Each strFileName In arrFileNames

                            'Import IGS
                            Rhino.Command "_Import """ + strFileName + """"

                            'Retrieve File Path
                            strObject = strFileName
                            strPath = Rhino.DocumentPath
                           
                            'Clean up FileName
                            'Remove parts that we don't want to turn into layers
                            strObject = Replace(strObject, strPath, "")
                            strObject = Replace(strObject, ".igs", "")

                            'Create new Layer
                            newLayer = Rhino.AddLayer(strObject)
                           
                            'Move joined igs objects to the layer created
                            Rhino.ObjectLayer Rhino.JoinSurfaces(Rhino.LastCreatedObjects, True), newLayer

                    Next

            End If


    End Sub
  • 2. Johannes (Oct 16, 2014 13.31):

    Hi, i have an old script that reads filenames from a specific folder...

    Dim objFSO, objFolder
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objStartFolder      : objStartFolder = "C:\TEST"

    Set objFolder = objFSO.GetFolder(objStartFolder)

    Call GenerateLayersFromFilenames(objStartFolder)

    Function GenerateLayersFromFilenames(Folder)
           
            Dim oFile, strFile
           
            For Each oFile In objFSO.GetFolder(Folder).Files
                   
                    strFile = oFile.Name
                    Call Rhino.AddLayer(strFile)
                   
            Next

    End Function

    Johannes

  • 1. jacobgerlach (Oct 14, 2014 18.18):

    Hi,

    I have a tedious IGES import process to deal with, and just discovered RhinoScript. I have no RhinoScript experience!

    I'd like to automate the following sequence:
    Import iges geometry
    'Join' the imported geometry
    Create a new layer containing the joined geometry. Name the layer with the base file name.

    Pseudocode:
    for files in directory
    base=(file - .iges)
    import(file)
    join
    ChangeLayer(selected,base)

    Any pointers on how to approach this would be greatly appreciated!

Recommend

Why are these buttons gray?