Oh yes, I have seen that the code returns null for e.g. sliders. I reduced the problem to a simple slider.
I made it work (very simple, I wasn’t able to quickly rebuild your building solution) by using this code from this post from rolf:
// Checking the first Input param (at index = 0)
var param = Component.Params.Input[0];
if (param.Sources.Count < 1)
{
return; // No source was connected to inport
}
A = param.Sources[0].InstanceGuid; // Output the Guid
which will give you the correct GUID id
I guess you need to loop through them as you set the inputs yourself.
update:
here a working code that groupes all the inputs like sliders etc (not nodes though) as soon as they are connected. this is in the solveInstance:
private void RunScript(Brep B, string M, ref object A, ref object C)
{
if(B == null) return;
//get volume in metric volume
double volcm = B.GetVolume() / 1000;
//Component.Params.Input[1].Optional = true;
//populate val list
if(M == "1")
{
var input = Component.Params.Input[1].Sources[0]; //get the first thing connected to the first input of this component
var valList = input as Grasshopper.Kernel.Special.GH_ValueList;
valList.ListItems.Clear();
List <Grasshopper.Kernel.Special.GH_ValueListItem> materials = new List<Grasshopper.Kernel.Special.GH_ValueListItem>()
{
new Grasshopper.Kernel.Special.GH_ValueListItem("silver ag 999", "10.49"),
new Grasshopper.Kernel.Special.GH_ValueListItem("silver ag 925", "10.40"),
new Grasshopper.Kernel.Special.GH_ValueListItem("white gold Au750Pd130", "15.80"),
new Grasshopper.Kernel.Special.GH_ValueListItem("white gold Au750Pd150", " 15.90"),
new Grasshopper.Kernel.Special.GH_ValueListItem("white gold Au750Pd210", " 16.30"),
new Grasshopper.Kernel.Special.GH_ValueListItem("pale gold 2N Au750Ag160", " 15.60"),
new Grasshopper.Kernel.Special.GH_ValueListItem("yellow gold 3N Au750Ag125", " 15.40"),
new Grasshopper.Kernel.Special.GH_ValueListItem("rosé gold 4N Au750Ag90", "15.30"),
new Grasshopper.Kernel.Special.GH_ValueListItem("red gold 5N Au750Ag45", "15.10"),
new Grasshopper.Kernel.Special.GH_ValueListItem("most red gold 6N Au750Ag5Pt4", "15.10"),
new Grasshopper.Kernel.Special.GH_ValueListItem("platine 950", "20.40"),
new Grasshopper.Kernel.Special.GH_ValueListItem("palladium 950", "11.80")
};
valList.ListItems.AddRange(materials);
Component.Params.Output[1].VolatileData.Clear();
valList.ExpireSolution(true);
}
if(M == null) A = "please connect a item list node to M and select a material";
else
{
A = string.Format("{0}g", Math.Round(volcm * Convert.ToDouble(M), 2));
}
List<Guid> guids = new List<Guid>();
foreach(IGH_Param param in Component.Params.Input)
{
foreach(IGH_Param source in param.Sources)
{
guids.Add(source.InstanceGuid);
}
}
Grasshopper.Kernel.Special.GH_Group g = new Grasshopper.Kernel.Special.GH_Group();
g.NickName = "hhh";
g.Colour = System.Drawing.Color.FromArgb(150, 150, 0, 0);
GrasshopperDocument.AddObject(g, false, GrasshopperDocument.ObjectCount);
for(int i = 0;i < guids.Count;i++) g.AddObject(guids[i]);
g.ExpireCaches();