algorithmic modeling for Rhino
Hi Guys,
The following code compiles with no errors and loads on Rhino5. However no value is stored in the output at all: The S should give a warning when no file is loaded and show the file path if the file is loaded (the m_settings variable should store that path). What am I doing wrong?
public class SettingsComponentAttributes : GH_ComponentAttributes
{
public SettingsComponentAttributes(IGH_Component SettingsComponent) : base(SettingsComponent) {}
public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
{
((SettingsComponent)Owner).ShowSettingsGui();
return GH_ObjectResponse.Handled;
}
}
public class SettingsComponent : GH_Component
{
public SettingsComponent(): base("LoadSettings", "LoadSettings", "Loading ini", "Extra", "") { }
public override void CreateAttributes()
{
m_attributes = new SettingsComponentAttributes(this);
}
private string m_settings;
public void ShowSettingsGui()
{
System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
ofd.Multiselect = true;
ofd.Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*";
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] filePath = ofd.FileNames;
string[] safeFilePath = ofd.SafeFileNames;
}
m_settings = Path.GetDirectoryName(ofd.FileName);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.Register_StringParam("DataPath", "S", "SettingsFile");
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{ }
protected override void SolveInstance(IGH_DataAccess DA)
{
if (m_settings == null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You must declare some valid settings");
return;
}
DA.SetData(0, m_settings);
}
Tags:
When you change the state of your component, you have to start a new solution. After:
m_settings = Path.GetDirectoryName(ofd.FileName);
add a call to ExpireSolution(true);
Also, if you press F5 without adding that code, does it add the settings then?
--
David Rutten
david@mcneel.com
Poprad, Slovakia
I meant F5 in Grasshopper. Which starts a new solution for all components, not just the ones that were tagged as expired.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by