Automatic update of all elements of the list when changing object. Problem with parametric generation

28 Views Asked by At

I have a problem regarding the parametric generation script in C# component in Grasshopper. I have created the code for creation of 3D models of cabinets in Grasshopper, based on the x y z xx xy values from the input the Lists are being generated and fed to the geometry tool as outputs (widthList, depthtList, heightList ...)

The problem I encounter is that once I have set the inputs for the values and I change the [w] (number of currently edited cabinet) the values change immediately, whereas I want them to don't change and just be changed separately for each element that is being set.

I tried to add supporting variables for the x y z xx xy but I failed to achieve what I want. Below I put the code without the additional variables. Thank you.

// Grasshopper Script Instance
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

public class Script_Instance : GH_ScriptInstance
{

    public int counter = 0; // to store the number of add cabinet/remove cabinet
    public int cabinetNo = 0; // 
    public bool cabinetChange;
    public int widthIndex;
    public int scriptCounter = 0;
    public int setValueTrigger = 0;


    public class cabinet
    {

        public int width;
        public int depth;
        public int height;
        public int sidePanelLeft;
        public int sidePanelRight;


        //public string width {get;set};

        public cabinet(int width, int depth, int height, int sidePanelLeft, int sidePanelRight)
        {
            this.width = width;
            this.depth = depth;
            this.height = height;
            this.sidePanelLeft = sidePanelLeft;
            this.sidePanelRight = sidePanelRight;

        }

    }

    public List<cabinet> cabinetList = new List<cabinet>(); // creates a list to store the cabinets
    public List<int> widthList = new List<int>();// creates a list for cabinet widths
    public List<int> depthList = new List<int>();// creates a list for cabinet depths
    public List<int> heightList = new List<int>();// creates a list for cabinet heights
    public List<int> leftPanelList = new List<int>();// creates a list for cabinet heights
    public List<int> rightPanelList = new List<int>();// creates a list for cabinet heights



    private void RunScript(
    bool u,
    bool v,
    int w,
    int x,
    int y,
    int z,
    int xx,
    int xy,
    bool s,
    bool t,
    out object b,
    out object c,
    out object a,
    out object d,
    out object e,
    out object f,
    out object aa,
    out object ab,
    out object g,
    out object h,
    out object i,
    out object j,
    out object k,
    out object m,
    out object n,
    out object scriptCounterOut)
    {


        // use a boolean to add a cabinet to the cabinet list
        if (u) //check if new cabinet added
        {
            cabinetList.Add(new cabinet(600, 600, 800, 0, 0));
            widthList.Add(cabinetList[counter].width);// adds the widths to the width list 
            depthList.Add(cabinetList[counter].depth);
            heightList.Add(cabinetList[counter].height);
            leftPanelList.Add(cabinetList[counter].sidePanelLeft);
            rightPanelList.Add(cabinetList[counter].sidePanelRight);

            counter++;
        }

        else if (w < cabinetList.Count) // Check if the specified index is within the valid range
        {
          
            if (x != cabinetList[w].width)
            {
                cabinetList[w].width = x;
                widthList[w] = cabinetList[w].width;
            }
            if (y != cabinetList[w].depth)
            {
                cabinetList[w].depth = y;
                depthList[w] = cabinetList[w].depth;
            }
            if (z != cabinetList[w].height)
            {
                cabinetList[w].height = z;
                heightList[w] = cabinetList[w].height;
            }
            if (xx != cabinetList[w].sidePanelLeft)
            {
                cabinetList[w].sidePanelLeft = xx;
                leftPanelList[w] = cabinetList[w].sidePanelLeft;
            }
            if (xy != cabinetList[w].sidePanelRight)
            {
                cabinetList[w].sidePanelRight = xy;
                rightPanelList[w] = cabinetList[w].sidePanelRight;
            }
            
        }

        // uses a boolean to remove last object in the cabinet list
        if (v)
        {

            cabinetList.RemoveAt(counter - 1);
            widthList.RemoveAt(counter - 1);
            depthList.RemoveAt(counter - 1);
            heightList.RemoveAt(counter - 1);
            leftPanelList.RemoveAt(counter - 1);
            rightPanelList.RemoveAt(counter - 1);
            counter--;
        }

        // Clears the cabinet list
        if (s)
        {
            cabinetList.Clear();
            widthList.Clear();
            depthList.Clear();
            heightList.Clear();
            leftPanelList.Clear();
            rightPanelList.Clear();
            counter = 0;
        }
        b = cabinetList;
        c = counter;
        a = cabinetList[w].height;
        d = widthList;
        e = depthList;
        f = heightList;
        g = w;
        h = cabinetList[w].width;
        i = cabinetList[w].depth;
        aa = leftPanelList;
        ab = rightPanelList;

        k = cabinetChange;

        cabinetNo = w;

        scriptCounter++;
        j = widthIndex;
        m = scriptCounter;
        n = setValueTrigger;

        scriptCounterOut = scriptCounter;

    }
}



0

There are 0 best solutions below