HI all,
I am using (trying to use) the DataTree input in Visual studio the first time.
Probably the problem has to do with that I need to convert from the IGH-Goo tree to a geometrybase.
Inside Gh I have a working code but translating it into VS is the problem now.
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddBooleanParameter("Execution", "E", "Executes the export process", GH_ParamAccess.item);
pManager.AddGeometryParameter("Geo", "G", "Geometry to export", GH_ParamAccess.tree);
pManager.AddTextParameter("Path", "P", "Path to destination folder", GH_ParamAccess.item);
pManager.AddTextParameter("Format", "F", "Format to export", GH_ParamAccess.item);
pManager.AddTextParameter("Filename", "F", "Name of the exportfiles", GH_ParamAccess.item);
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object can be used to retrieve data from input parameters and
/// to store data in output parameters.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
//get Data
Boolean execute = false;
if (!DA.GetData(0, ref execute )) return;
GH_Structure<IGH_Goo> tree = new GH_Structure<IGH_Goo>();
if ((!DA.GetDataTree(1, out tree))) return;
String path = null;
if (!DA.GetData(2, ref path)) return;
String fileType = null;
if (!DA.GetData(3, ref fileType)) return;
String name = null;
if (!DA.GetData(4, ref name)) return;
//Export
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
//create filetype
if (!fileType.StartsWith("."))
{
fileType = "." + fileType;
}
//declare attributes
var doc = Rhino.RhinoDoc.ActiveDoc;
if (doc == null) return;
var attr = Rhino.RhinoDoc.ActiveDoc.CreateDefaultAttributes();
if (execute)
{
for (int i = 0; i < tree.PathCount; i++)
{
for (int j = 0; j < tree.get_Branch(i).Count;j++)
{
var geos = doc.Objects.Add(tree.get_Branch(i)[j], attr);
doc.Objects.Select(geos);
}
Rhino.RhinoApp.RunScript("-_Export \n\"" + path + "\\" + name + (i).ToString() + fileType + "\"\n _Enter", false);
doc.Objects.UnselectAll();
}
System.Windows.Forms.MessageBox.Show("There were" + tree.PathCount.ToString() + "geometries exported", "Export result", MessageBoxButtons.OK);
}
}
Any help is much apreciated.
Thanks