Quantcast
Channel: Grasshopper Developer - McNeel Forum
Viewing all 3634 articles
Browse latest View live

Data conversion failed from Goo to MeshParameters

$
0
0

@Camille wrote:

Hello, I’m working on a python script, and I want to use a brep as an input and to create a mesh with MeshBrep inside the script. I initialize the parameters with SettingsCustom and when I create the mesh, it returns the error: Data conversion failed from Goo to MeshParameters.
I thank you in advance if you can help me to understand the problem.

meshbreppython.gh (5.7 KB)

Posts: 1

Participants: 1

Read full topic


C# Component - RunCounter needed

$
0
0

@siadebisi wrote:

Hi everyone,
I´m a little stuck right now. I need an intenger which stays alive while going through different lists. It is my goal to change the path in the following itereation without the need of going into the tree structure (don´t like it very much, because input trees can change).

This is my current “TestCode” to get an int of the currentRun, but the script always runs through every peace of inputItem:

  private void RunScript(bool reset, bool run, List<int> inputList, int listLength, ref object A)
  {
    if (reset)
    {
      n = 0;
      collection.Clear();
    }
    else if(run){

      collection.AddRange(inputList);

      if(n < listLength)
      {
        Component.ExpireSolution(true);
      }

      n++;
    }
    A = collection;
  }

  // <Custom additional code> 

  List<int> collection = new List<int>();
  int n = 0;
  // </Custom additional code> 
}

When the index is working I want to bring objects from a list into a new Structure depending on a group dependency:

for(int x = 0; x < curves.Count ; x++)
    {
      curveList.Add(curves[x], new GH_Path(0, groupDictionary[x]));
    }

Thanks for your help :slight_smile:

Posts: 2

Participants: 2

Read full topic

Flip make2d parallel view

$
0
0

@johann wrote:

Is it possible to flip the “make2d parallel view” direction?

I have tried flipping the surface it is based on but, that does not result in flipped “view plane”.

My workaround for the moment is rotating the input surface 180 degrees before plugging it into the “parallel view” module, it works but a flip function would be cleaner and easier.

Posts: 1

Participants: 1

Read full topic

Operating on inputs before list matching to prevent duplicate calculations in C#

$
0
0

@sc_o wrote:

Hi,

I am working on a component in C# in Visual Studio and am running to a bit of an optimization problem I don’t quite know how to approach. The component runs an operation on a brep input with item access - the subtractFrom input in the code snippet below - with a set of breps with list access - the subtractWith input. I am trying to improve compute times when working with very large data sets, specifically when the breps with list access stay the same but I feed in more than one brep into the subtractFrom input with item access, which I believe causes grasshopper’s automatic list matching to duplicate some calculations unnecessarily.

Specifically what I am trying to improve is when I am converting the list of subtractWith breps to my custom class BrepBB in the solve instance in the code below. The constructor that I am using calculates a bounding box for the brep and holds it alongside the brep so that I don’t have to compute it over and over later in the script. That in itself isn’t a problem, but the problem is that when I am inputting a list into subtractFrom which I’ve only given item access, the BrepBB constructor that is being fed the data from subtractWith is being duplicated for every item in the subtractFrom list. If the subtractFrom input has 1000 items in it, I beileive the constructor is being run 999 more times than necessary due to longest list data matching or similar.

What I would like to do instead is have the breps converted to my BrepBB class immediately on input and before any longest list matching or the like is done in the component so that the constructor can just run a single time per data input. I considered giving the subtractFrom data list access, but I am running the code multi-threaded and that would put all of the calculations onto a single thread with how it is currenlty opperating.

I hope all of that made sense. If anyone know how this is done, It would be greatly appreciated!

    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
    {
        pManager.AddBrepParameter("Subtract From", "A", "Set to subtract from.", GH_ParamAccess.item);
        pManager.AddBrepParameter("Subtract With", "B", "Set to subtract with.", GH_ParamAccess.list);
        pManager.AddNumberParameter("Tolerance", "T", "Subtraction tolerance", GH_ParamAccess.item, DocumentTolerance());
        pManager.AddBooleanParameter("Strict", "S", "True to check for true interesection, false to only check bounding boxes", GH_ParamAccess.item, false);
        pManager.AddBooleanParameter("Accurate Bounding", "C", "true to compute accurate bounding boxes", GH_ParamAccess.item, false);
    }

    /// <summary>
    /// Registers all the output parameters for this component.
    /// </summary>
    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
    {
        pManager.AddBrepParameter("Result", "R", "Subtraction result.", GH_ParamAccess.list);
    }

    protected override void SolveInstance(IGH_DataAccess DA)
    {

        if (InPreSolve)
        {
            //Fist Pass; collect input data
            Brep subtractFromTemp = new Brep();
            DA.GetData(0, ref subtractFromTemp);

            List<Brep> subtractWithTemp = new List<Brep>();
            DA.GetDataList(1, subtractWithTemp);

            double tol = DocumentTolerance();
            DA.GetData(2, ref tol);

            bool strict = new bool();
            DA.GetData(3, ref strict);

            bool accurate = new bool();
            DA.GetData(4, ref accurate);

            BrepBB subtractFrom = new BrepBB(subtractFromTemp, accurate);

            List<BrepBB> subtractWith = new List<BrepBB>();
            {
                foreach (Brep b in subtractWithTemp)
                {
                    subtractWith.Add(new BrepBB(b, accurate));  //this code runs more than necessary
                }
            }

            //Queue up the task
            Task<SolveResults> task = Task.Run(() => ComputeDifference(subtractFrom, subtractWith, tol, strict, accurate), CancelToken);
            TaskList.Add(task);
            return;
        }

        if (!GetSolveResults(DA, out SolveResults result))
        {
            //Compute right here; collect input data
            Brep subtractFromTemp = new Brep();
            DA.GetData(0, ref subtractFromTemp);

            List<Brep> subtractWithTemp = new List<Brep>();
            DA.GetDataList(1, subtractWithTemp);
            
            double tol = DocumentTolerance();
            DA.GetData(2, ref tol);

            bool strict = new bool();
            DA.GetData(3, ref strict);

            bool accurate = new bool();
            DA.GetData(4, ref accurate);

            BrepBB subtractFrom = new BrepBB(subtractFromTemp, accurate);

            List<BrepBB> subtractWith = new List<BrepBB>();
            {
                foreach (Brep b in subtractWithTemp)
                {
                    subtractWith.Add(new BrepBB(b, accurate)); //this code runs more than necessary
                }
            }

            //Compute results on given data
            result = ComputeDifference(subtractFrom, subtractWith, tol, strict, accurate);
        }

        //Set output data
        if (result != null)
        {
            List<Brep> brepResults = new List<Brep>();
            foreach(BrepBB brepResult in result.Subtracted)
            {
                brepResults.Add(brepResult.Brep);
            }
            DA.SetDataList("Result", brepResults);
        }
    }

Posts: 1

Participants: 1

Read full topic

Generating Value Lists in Visual Studio (C#)

$
0
0

@marcio.sartorelli.so wrote:

Hello All,

I’m developing a project in C# on design and analysis of timber conections and would like to organize screws and nails inputs using value lists. I already looked into some tutorials (http://james-ramsden.com/grasshopper-automatically-create-a-value-list-in-c/) but i’m still facing two major issues:

-The tutorial is about automatically generate a value list, but what I really want is that when you plug a generic value list as a input the list would change to the relevant information. (In a simillar way Elefront operates with Keys and Values when you reference a object)

-I would also like to this in subsections, as a example: I can have as first input the conection indentification, as nail or screw. With that value selected I would like to have acess of another value list about its specifications. (In the example of screws, I’m interested in adding the rhotoblass catalogue as selection, choosing the screw class and then the type). In top of all that it would be important that the output of the value list is the string itself (I already have tested and I only receive a integer on the sequence of the list), so I can correspond the screw/nail ID in a excel file and retreive all the information I need.

Do anyone have clues on that? It would help me a lot to develop a clean and robust plug-in for structural timber design.

Thanks in advance,
Márcio Sartorelli

Posts: 1

Participants: 1

Read full topic

V5 Plugin in running in V6

$
0
0

@cidelab wrote:

Good afternoon all,

My plugin runs fast and smoothly in GH for Rhino5. Nevertheless runs slower (without errors) in GH for Rhino6.
There is a reason for that?

thanks in advance
Carlos.

Posts: 1

Participants: 1

Read full topic

Input Lists in in VB getting cross referenced

$
0
0

@joy.architect wrote:


I am using this logic in VB
if <condition = true > output = L1
else output = L2
Since the data structure of L1 and L2 are dissimilar, output is getting cross-referenced.
Is there any way to avoid this cross reference?

Posts: 1

Participants: 1

Read full topic

"Cannot marshal" error affecting multiple plugins. Please, help!

$
0
0

@scook2 wrote:

I’m completely stuck. I’m getting the following error:

  1. Solution exception:Cannot marshal ‘parameter #5’: Invalid managed/unmanaged type combination (Arrays can only be marshaled as LPArray, ByValArray, or SafeArray).

when using Cocoon’s refine function and Yellow’s smooth function. I found this post at the old grasshopper forum and, following @DanielPiker 's advice, I updated my .NET framework and made sure plankton was up to date and operational. None of this worked. Does anyone have any suggestions?

I’m running Rhino 5 on Windows 7. I do have Rhino 6 installed but am using 5 for the moment because my computer is garbage.

Posts: 1

Participants: 1

Read full topic


Passing value to custom additional code

$
0
0

@evo85210 wrote:

I’m using an C# component someone else wrote, and there’s a varible that needs to be set to match my current ip.
I’ll annoying to change this value because every time i have to click into the component to change it.
this value is under Custom additional code and i’m having trouble creating an input for this value

This is the C# script


the one that I need to set is public string hostIP = "10.97.80.205"
So i tried something like this

but it doesn’t work

just wondering what’s the proper way of passing an input value to hostIP?

Posts: 3

Participants: 3

Read full topic

Dynamic Disable/Enable based on boolean in ghPython?

$
0
0

@efestwin wrote:

Hey Folks,
First off, I have a kind of hacky problem: I want to dynamically disable/enable certain clusters based on a boolean value from a toggle. I know this has been discussed extensively but I haven’t found a working solution in Python and I am quite lost and frustrated by now.

My code looks like this at the moment:

thisDoc = ghenv.Component.OnPingDocument()

# define callback function
def toggleLocked(owner, state):
    owner.Locked = state

# reverse the input boolean
E = not E
print(">>> Enable is set to " + str(E))

paramsources = ghenv.Component.Params.Input[1].Sources
if paramsources and len(paramsources) > 0:
    owner = paramsources[0].Attributes.Parent.DocObject

if owner and owner.Locked != E:
    thisDoc.ScheduleSolution(1, toggleLocked(owner, E))

I have read lots about ExpireSolution(True), why it should not be used to expire components during a solution et cetera. So I tried to “do it right” by scheduling a new solution via a callback function. Still, I get lots of “Component Expired during a Solution” errors. I would like to fix this and I am hoping for your input :slight_smile:

PS: I know this exists in MetaHopper but it’s not possible for me to implement any AddOns so I would like to come up with a working ghPython-only implementation.

Posts: 1

Participants: 1

Read full topic

Cast IList to List

$
0
0

@a.ai wrote:

I am trying to access a list of type GH_Number stored in a GH_Structure with tree.getBranch() method, like so:

List<GH_Number> buildingParams1 = (IList<IGH_Goo>)tree.get_Branch(new GH_Path(rndBl, rndPa, 0));

I get an invalid cast ('cannot implicitly convert type 'System.Collections.Generic.IList<Grasshopper.Kernel.Types.IGH_Goo> to ‘System.Collections.Generic.List<Grasshopper.Kernel.Types.GH_Number>’. An explicit conversion exists (are you missing a cast?)

What am I doing wrong?

Thanks! :slight_smile:

Posts: 2

Participants: 2

Read full topic

UndoStateChange Eventhandler custom callback hang

$
0
0

@verina_cristie wrote:

Hi, I wrote custom component to try to ‘catch’ user activities by getting the undo stack. So what I’m trying to do now is to attach custom callback to record it.

In the main SolveInstance:
GH_Document ghDoc = this.OnPingDocument();
ghDoc.UndoStateChanged += CustomCallback;

void CustomCallback(Object sender, GH_DocUndoEventArgs e)
_ {_
_ Rhino.RhinoApp.WriteLine(“SENDER: " + sender.ToString());_
_ Rhino.RhinoApp.WriteLine(” name: " + e.Record.Name);_
_ Rhino.RhinoApp.WriteLine(" guid: " + e.Record.Guid.ToString());_
_ Rhino.RhinoApp.WriteLine(" time: " + e.Record.Time.ToString());_
_ Rhino.RhinoApp.WriteLine(" state: " + e.Record.State.ToString());_

_ this.OnPingDocument().UndoServer.PushUndoRecord(e.Record);_
}

However, this causes hang when any action is done on the canvas. If I try to move any object, it cannot be dropped (seems like it’s attached to mouse click). Adding ExpireSolution doesnt help either (I think it shouldn’t expire anyway?).

I feel that I might have to add more lines in the custom callback to ‘emulate’ normal procedure, however I am not too familiar with the workflow.

Kindly advice, and thanks in advance!

Posts: 2

Participants: 2

Read full topic

How to make a customize component"old"

$
0
0

@andrealu2012 wrote:

sometime ,when we open a gh file,we can see some compnent marked"old".
these days,i am updating myself customized component but i am perfer to keep the old one when making a new same name component.so how can i do that?perfer in C#
Thank you!

Posts: 3

Participants: 2

Read full topic

How to make{0:0} to {0} in code?

How to use of lunchbox enneper surface components


How to clear the display cache in GH_component

$
0
0

@milad.showkatbakhsh wrote:

Hello all,

it seems like a very simple question, but I have had problems to clear the display cache of my GH_component. I know i need to override the clearData method but honestly, I don’t know where to invoke it and what method? base.ExpirePreview(true);
base.OnDisplayExpired(true);
base.ClearData();
I invoked these three methods in SolveInstane() at the beginning of everything, doesn’t work, I did it in BeforeSolveInstance() it does not work either. I really appreciate it if any of you could direct me to a right direction.

best,
Milad

Posts: 6

Participants: 3

Read full topic

Angular Dimension / Grasshopper C# ScriptComponent

$
0
0

@udoribbe wrote:

Hi There,

I am working on a custom component generating dimension and in this case angular dimensions.

note:
The Elefront PlugIn works fine for me so far, but is lacking the extension lines, so is the grasshopper native angular dimension.

I can create the angular dimension fine so far, but it isn´t visible in grasshopper, hence failing the conversion from goo to geometry, see picture.

Thanx for you help.

Udo

test_angularDim_181010.gh (11.0 KB)

Posts: 1

Participants: 1

Read full topic

C# CIrcle Fractal

Why I cannot move a custom component?

$
0
0

@andrealu2012 wrote:

I am doing a custom component with custom attribute
I add a mouse down method to handle mouse down event(just change the text and color of the button):

but when i try this component in grasshopper,I found that it cannot be drag and move…
do some one know where is the problem,
Thank you!

this is all code:

    using System;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Forms;
    using Rhino;
    using Grasshopper.Kernel;
    using Rhino.Geometry;
    using System.Drawing;
    using Grasshopper.Kernel.Attributes;
    using Grasshopper.GUI.Canvas;


    namespace FabUnionRobot
    {
    public class AttributesCustom1 : GH_ComponentAttributes

    {


        public AttributesCustom1(GH_Component owner) : base(owner)
        {
        }

        protected override void Layout()
        {
            base.Layout();
            //  Bounds = new RectangleF(100, 200, 30, 60);

            Rectangle r = GH_Convert.ToRectangle(this.Bounds);
            r.Height += 40;
            // this.Bounds = new RectangleF(Pivot, new SizeF(100, 50));
            this.Bounds = r;
        }
        //public override void ExpireLayout()
        //{
        //    base.ExpireLayout();
        //}
        private RectangleF rec2 { get; set; }
        public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e)
        {

            if (this.rec2.Contains(e.CanvasLocation))
            {
                System.Windows.Forms.MessageBox.Show("hello");
            }
            Owner.ExpireSolution(true);
            return Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled;

        }
        public override Grasshopper.GUI.Canvas.GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, Grasshopper.GUI.GH_CanvasMouseEvent e)
        {
            if(((e.Button == MouseButtons.Left) && this.rec2.Contains(e.CanvasLocation)) && (this.Owner != null))
            // if (this.rec2.Contains(e.CanvasLocation))
            {
                (Owner as ComponentTest1).IsBtnDown = true;
                Owner.ExpireSolution(true);
                return GH_ObjectResponse.Capture;
            }
            return Grasshopper.GUI.Canvas.GH_ObjectResponse.Handled;
        }
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            rec2 = new RectangleF(Pivot.X - ((this.Bounds.Width - 4) / 2)+2, Pivot.Y+25, this.Bounds.Width - 4, 25);
            //var rec3 = new RectangleF();
            base.Render(canvas, graphics, channel);
            SolidBrush brush = new SolidBrush(Color.Pink);
            Pen pen = new Pen(brush, 1);
            Font font = new Font("MS UI Gothic", 3, FontStyle.Italic);
            if (channel == GH_CanvasChannel.Objects)
            {
                bool isbd = (Owner as ComponentTest1).IsBtnDown;
                GH_Capsule gH_Capsule;
                if (isbd)
                {
                    gH_Capsule = GH_Capsule.CreateTextCapsule(rec2, rec2, GH_Palette.Black, "btndown", 2, 0);
                    gH_Capsule.Render(graphics, this.Selected, base.Owner.Locked, false);
                    
                }
                else
                {
                    gH_Capsule = GH_Capsule.CreateTextCapsule(rec2, rec2, GH_Palette.Grey, "button", 2, 0);
                    gH_Capsule.Render(graphics, this.Selected, base.Owner.Locked, false);
                    
                }
                gH_Capsule.Dispose();
            }
        }
    }
    public class ComponentTest1 : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the ComponentTest class.
        /// </summary>
        /// 
        public int V { get; set; }
        public bool IsBtnDown { get; set; }

        public ComponentTest1()
          : base("ComponentTest", "CT",
              "This is the Description",
              CommonValues.Test, CommonValues.subCatalogOthers)
        {
            V = 0;
        }
        public override void CreateAttributes()
        {
            base.m_attributes = new AttributesCustom1(this);
        }


        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
        {
            pManager.AddNumberParameter("input", "v", "adfadf", GH_ParamAccess.item);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {
            pManager.AddNumberParameter("output", "v", "adfadf", GH_ParamAccess.item);
        }

        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            
            //int n =  this.Params.Input[0].SourceCount;

            //Message = $"{n}";
            //DA.SetData("output",n);

        }

        /// <summary>
        /// Provides an Icon for the component.
        /// </summary>
        protected override System.Drawing.Bitmap Icon
        {
            get
            {
                //You can add image files to your project resources and access them like this:
                // return Resources.IconForThisComponent;
                return Resource1.CustomCmd;
            }
        }

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid
        {
            get { return new Guid("8412de8e-6d7b-4ac7-a1e9-1235320f71a2"); }
        }
    }
}

Posts: 5

Participants: 3

Read full topic

Duplicate Borders of trimmed surfaces in C#

$
0
0

@Gustav_Good wrote:

Hi there,

I’m doing i C# script component in grasshopper and I am having trouble duplicating surface borders. I have tried the following:

srf.ToBrep().DuplicateEdgeCurves();

This gives me the untrimmed edges as illustrated in the picture below:

What method should I use to retrieve trimmed edges?

Posts: 3

Participants: 2

Read full topic

Viewing all 3634 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>