Grasshopper

algorithmic modeling for Rhino

I have a working script which was modified from the primer which writes a space separated text file from x y z input. But it makes the file bigger and bigger with any input changes because it uses the appendalltext. What other ways could a text file be written (with string list or on3dpoint lists) so that the entire text file is rewritten once with any input change (deleting the previous)?

Sub RunScript(ByVal path As String, ByVal x As Double, ByVal y As Double, ByVal z As Double, ByVal vx As Double, ByVal vy As Double, ByVal vz As Double)
Dim xround As Double = Math.Round(x, 5)
Dim yround As Double = Math.Round(y, 5)
Dim zround As Double = Math.Round(z, 5)
Dim vxround As Double = Math.Round(vx, 5)
Dim vyround As Double = Math.Round(vy, 5)
Dim vzround As Double = Math.Round(vz, 5)
Dim ptsstring As String = Convert.ToString(xround & " " & yround & " " & zround & " " & vxround & " " & vyround & " " & vzround)
Print(ptsstring)
Dim appendText As String = ptsstring + Environment.NewLine
File.AppendAllText(path, appendText)

' Open the file to read from.
Dim readText As String = File.ReadAllText(path)
Console.WriteLine(readText)


End Sub

Views: 355

Replies to This Discussion

This definition is a rework of a file posted on here somewhere.
Attachments:
Thanks. I modified this with the StreamWriter.WriteLine command for each line and it worked.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service