Baris
1
Hi everybody,
I want batch convert some files from R7 to R6 in Grasshopper with C#.
The bool from Rhino.FileIO.File.Write returns false and nothing is written.
private void RunScript(string path, string newPath, ref object A)
{
string[] files = Directory.GetFiles(path);
Rhino.FileIO.File3dm file = Rhino.FileIO.File3dm.Read(files[0]);
A = file.Write(newPath, 0);
}
Could somebody shed some light?
File:
20220708_ConvertFromR7ToR6.gh (7.9 KB)
Thanks in advance and have a nice weekend !
HI @Baris ,
Your code works when I tested it. Maybe something wrong with the inputs
1 Like
Baris
3
Thanks for your answer @Darryl_Menezes,
strangely, it does not work on my side:
I also tried it running Rhino as administrator- without success.
@Baris what values did you set to the “path” and the “newPath”?
1 Like
Baris
5
Thanks again @Darryl_Menezes, that was the problem.
Here the code, if someone needs it in future (without any exception handling):
private void RunScript(bool write, string path, string newPath, ref object A)
{
string[] files = Directory.GetFiles(path);//Get all files
for (int i = 0; i < files.Length; i++)
{
Rhino.FileIO.File3dm file = Rhino.FileIO.File3dm.Read(files[i]);
string[] chunks = files[i].Split('\\');
string name = chunks[chunks.Length - 1];
string fileName = string.Format("{0}\\{1}." + "3dm", newPath, name + "_R6");
if(write)
file.Write(fileName, new Rhino.FileIO.File3dmWriteOptions() {Version = 6});
}
}
1 Like
11159
(Masaki)
6
Does your GH file have a button?
11159
(Masaki)
8
I don’t know why it doesn’t work, but your code worked correctly.
I think the folder is set up incorrectly.
Baris
9
My last reply is the working code. The problem was the path.
Anyway thanks for your reply!
1 Like