McNeel Wiki
Importing Text from a File
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

中文(简体)

 
.
DeveloperRhinoScript
Version4.0
SummaryHow to import text from a file.

Question

Is there a RhinoScript method to import text from a file, similar to "Import Text" button found in the "Create Text" dialog box displayed by Rhino's Text command?

Answer

No, there is no method in RhinoScript that will import text from a file and then create a text object. But, it does not take much to write your own. The following example code demonstrates just how you might go about doing this.

  Sub ImportText


    Const ForReading = 1
    Dim strFile, strText
    Dim objFSO, objFile
    Dim arrOrigin


    strFile = Rhino.OpenFileName("Open", "Text Files (*.txt)|*.txt||")
    If IsNull(strFile) Then Exit Sub


    arrOrigin = Rhino.GetPoint("Start point")
    If Not IsArray(arrOrigin) Then Exit Sub


    Set objFSO = CreateObject("Scripting.FileSystemObject")


    On Error Resume Next
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)
    If Err Then
      MsgBox Err.Description
      Exit Sub
    End If


    While Not objFile.AtEndOfStream
      strText = strText & objFile.ReadLine
      If Not objFile.AtEndOfStream Then
        strText = strText & VbCrLf
      End If
    Wend


    objFile.Close


    Set objFile = Nothing
    Set objFSO = Nothing


    If Len(strText) > 0 Then
      Rhino.AddText strText, arrOrigin
    End If


  End Sub
rename · changes · history · subscriptions · lost and found · references · file upload