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

Distributing GHA components commercially

$
0
0

@Dmitriy wrote:

Hi,

Have not seen this topic discussed here, so would like to have an exchange of opinions.

Currently I observe the following situation: within commercial side products developed to work in Rhino (plugins, GHA components and maybe others) plugin is the most common product being offered commercially and only few GHA components are distributed on the commercial basis.

At the beginning I was also thinking about Plugin as consolidated product development but some time ago I decided to switch to custom GH components.

For me I see the following benefits:

  • still possible to use all Custom classes
  • components are independent and are very flexible to use in combination with standard Gh components as well as other components
  • no routine in writing many of event handling functions

Definitely there are also disadvantages.

What I am worried about is the security, as I guess GHA component is rather easy to “crack”.
Are there any ways to protect it properly?

I encourage everybody to give an opinion/comments. Maybe also persons already distributing GHA components commercially can comment here.

Thanks,
Dmitriy

Posts: 4

Participants: 2

Read full topic


Simplify a tree which contains a single item, component not working

$
0
0

@Xavier_Ayme wrote:

Hey there,

Is there any reason why the “Simplify Tree” native component doesn’t work on a single item tree whereas the SDK command DataTree.SimplifyPaths does? Is it an intended behavior?

Cheers

– Xavier

Posts: 4

Participants: 2

Read full topic

Adding/importing Python modules

$
0
0

@raniat123 wrote:

I searched for this question for a while and I still can’t get this to work. I would like to import a python module called Paramiko and here is what I tried so far
I typed this in a python component

 import sys
 for p in sys.path:
        print p 

Then I copied the Paramiko folder into the resulted path.
This method didn’t work.
Could someone guide me on how to do this?

Posts: 4

Participants: 3

Read full topic

The only safe way of Updating Slider in Python

$
0
0

@piac wrote:

Over the years, there have been lots of threads here and on the old Grasshopper forum that deal with setting slider values in Grasshopper. They all have some advantages and disadvantages, but they have something in common: they too often end up breaking the Grasshopper SDK rule “never edit values while the definition is running”.

This thread shows a way of fixing that. This is a Rhino-6-only possibility, because this feature is new in Rhino 6. By overriding the Component Context menu, we can set the values outside of the solution, in a very Grasshopper-classic way.

This uses the same logic as this definition by Anders Holden Deleuran on the old Grasshopper forum.

image

Here is the code:

"""
Reset named sliders.
Right-click on the component and choose "Update Sliders!" to update their values.
    Inputs:
        Sliders: (strings) A list with names of sliders
        Values: (numbers) A list with values of sliders
    Remarks: This component does not retuns any values.
 """

from ghpythonlib.componentbase import executingcomponent as component
import Grasshopper, GhPython
import System
import Rhino
import rhinoscriptsyntax as rs

class UpdateSliders(component):
    
    def RunScript(self, Sliders, Values):
        if not Sliders or not Values:
            Sliders = None
            Values = None
            return
        self.Sliders = Sliders
        self.Values = Values
        if len(Sliders) != len(Values):
            raise Exception("Different lenghts of sliders and values")
        self.Component = ghenv.Component
        self.GhDef = None
        if self.Component: self.GhDef = self.Component.OnPingDocument()
        
        
    def AppendAdditionalComponentMenuItems(self, menu):
        item = Grasshopper.Kernel.GH_Component.Menu_AppendGenericMenuItem(
            menu, "Update Sliders!", self.OnClicked, self.Icon_24x24, None, True, False);
        item.ToolTipText = "Update the sliders now";
        
        
    def OnClicked(self, obj, args):
        try:
            self.UpdateValues(obj, args)
        except Exception, ex:
            System.Windows.Forms.MessageBox.Show(str(ex))
            
    def UpdateValues(self, obj, args):
        if not self.GhDef: return
        if not self.Sliders or not self.Values: return
        
        ghObjects = self.GhDef.Objects # Get to the GH objects
        
        # Iterate the GH objects
        for obj in ghObjects:
            # Set the named slider values
            if type(obj) is Grasshopper.Kernel.Special.GH_NumberSlider and \
                obj.NickName in self.Sliders:
                
                # Set min/max
                #obj.Slider.Minimum = 0
                #obj.Slider.Maximum = 10
                
                # Set value
                obj.Slider.Value = self.Values[self.Sliders.index(obj.NickName)]
                
                # Update slider
                obj.ExpireSolution(True)

Have a look and see if it helps!
Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Posts: 1

Participants: 1

Read full topic

Find discontinuities C#

$
0
0

@Baris wrote:

HI,

I saw this topic C# explode curve like Rhino explode & GH explode component(with recursive true)
It seems not to replicate the gh Component behaviour:


I tried It too but without luck. I couldnt find the C1 tangency in the rhinocommon, as the gh component uses por default.
 private void RunScript(Curve crv, ref object A)
  {

    double t0 = crv.Domain.Min; double t1 = crv.Domain.Max; double t;

    var tParams = new List<Double>();


    bool disc = crv.GetNextDiscontinuity(Continuity.C1_locus_continuous, t0, t1, out t);

    while (disc == true)
    {


      tParams.Add(t);

    }

    A = tParams;
  }

Maybe someone could help.

Thanks!

disc.gh (4.9 KB)

Posts: 6

Participants: 2

Read full topic

C# Displaying filled circle

$
0
0

@11194 wrote:

Hi

I’m trying to show axial force with circle which depends on each element value.

In DrawViewportMeshes(IGH_PreviewArgs args),
args.Display.DrawCircle doesn’t have filled circle.
So instead of this, I’m using DrawMeshShaded method.

Here is the .gif that shows how my component works.


It works correctly but It’s little bit slow I think.

Is there other solution to display filled circle?

Best,
Shimpei

Posts: 5

Participants: 3

Read full topic

Format Numbers with , 1000's. ie: 100,000,000

Conditional branch merging based on data values (using VB script)

$
0
0

@kguard wrote:

Hi everyone,

I’m a total newbie to grasshopper and VB (started less than a week ago), so please bear with me if I’m being dumb.

I have a tree with different values of data within it (see image attached). All I want to do using the VB script is to create a new tree structure which has branches based on data values (for the mentioned example, I would like to two branches with data going to branch 1 if the values are 123000 ± 1000 and branch 2 if values are 120000 ± 1000!

P.S. I’ve been having trouble accessing the values from the data trees and manipulating, and I haven’t found the best source for related literature yet. The grasshopper primer has very limited information. If someone could point me to a better resource (if you can think of one), that would be super helpful.

Thanks!

Branching

Posts: 5

Participants: 2

Read full topic


geometryBase to Polyline/Mesh overload error in vs, c#

$
0
0

@Baris wrote:

HI,

I tried to convert from geometryBase to Curve/Mesh in vs.
I am getting an error message :Overload has some invalid arguments.
Someone could tell me what I am doing wrong?

Thanks in advance!

Posts: 7

Participants: 3

Read full topic

C# - hacking geometry-pipeline to temporarly filter specific objects

$
0
0

@mark_ortler wrote:

Hey people,

I have kind of a special question. Its about hacking the geometry-pipeline.

I developed a component which is used to draw geometry within Rhino (like it would be baked) to select one/some of them, to go on with them in grasshopper.

The problem is, if there is a geometry pipeline within the definition the drawn/baked stuff may interfer somehow with it and produce unpredictable results… l

Is there a possibility to temporarly lock all pipelines in the definition OR exclude them from collection?
ocking the solver is not an option, while I want to have live-updates.
I draw the objects on a specific layer with custom-attributes.

The described component can be found in this plugin (qeds > 06_Preview) and looks like this:

selectable

Any help would be great
Thanks in advance

greets Mark

Posts: 1

Participants: 1

Read full topic

Joining Mesh in c#(Mesh.Append method)

$
0
0

@Baris wrote:

Hello,

I am doing a mesh window component, when I use a mesh as Input it joines well, but with polylines as input it gives me single faces instead of a joined mesh.

  protected override void SolveInstance(IGH_DataAccess DA)
        {
            
            //Get geo an initialize 
                     GeometryBase geometryBase =null;   
                     if ((!DA.GetData(0,ref geometryBase)))
                        return;

                  object someGeometry = geometryBase;                        
                  double factor = double.NaN;
                  DA.GetData(1, ref factor);
                  Mesh outMsh = new Mesh();
                  var curves = new List<Polyline>();



            //get Plines from mesh if mesh is the input
                  if (someGeometry is Mesh)
                  {                    
                      Mesh msh = someGeometry as Mesh;                                           

                        for (int f = 0; f < msh.Faces.Count; f++)
                        {
                          if(msh.Faces[f].IsTriangle)
                          {
                            var pts = new List<Point3d>(3);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);
                            pts.Add(msh.Vertices[msh.Faces[f].B]);
                            pts.Add(msh.Vertices[msh.Faces[f].C]);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);

                            Polyline polyline = new Polyline(pts);
                            curves.Add(polyline);

                          }

                          if(msh.Faces[f].IsQuad)
                          {
                            var pts = new List<Point3d>(3);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);
                            pts.Add(msh.Vertices[msh.Faces[f].B]);
                            pts.Add(msh.Vertices[msh.Faces[f].C]);
                            pts.Add(msh.Vertices[msh.Faces[f].D]);
                            pts.Add(msh.Vertices[msh.Faces[f].A]);

                            Polyline polyline = new Polyline(pts);
                            curves.Add(polyline);
                          }
                        }                      
                     }

                      

                //put Polylines in list

                  else if (someGeometry is Curve)
                  {
                      Polyline polyline;
                      Curve curve = (Curve)someGeometry;
                      if (!curve.TryGetPolyline(out polyline))
                          throw new ArgumentException("Only polylines and meshes are allowed as inputs");
                      curves.Add(polyline);
                      
                  }


            
            //Make mesh window
                  for (int i = 0; i < curves.Count; i++)
                  {                                            
                      var ptsO = curves[i];
                      Polyline polylineCopy = new Polyline(curves[i]);
                      Point3d center = curves[i].CenterPoint();
                      Transform xform = Transform.Scale(center, factor);
                      polylineCopy.Transform(xform);

                      var ptsS = polylineCopy;
                      
                      Mesh m = new Mesh();
                      for (int j = 0; j < ptsO.Count - 1; j++)
                      {                          
                          var pts = new List<Point3d>();
                          pts.Add(ptsO[j]);
                          pts.Add(ptsO[j + 1]);
                          pts.Add(ptsS[j + 1]);
                          pts.Add(ptsS[j]);
                          m.Vertices.AddVertices(pts);
                          m.Faces.AddFace(new MeshFace(j * 4, j * 4 + 1, j * 4 + 2, j * 4 + 3));                                          
                       }
                      
                      outMsh.Append(m);
                     
                  }

            //assign joined mesh
            
                      Message = "Mesh";
                      outMsh.Vertices.CombineIdentical(true, true);
                      outMsh.Vertices.CullUnused();
                      outMsh.UnifyNormals();
                      outMsh.FaceNormals.ComputeFaceNormals();
                      outMsh.Normals.ComputeNormals();

                      DA.SetData(0, outMsh);
        }

I have a list of Polylines, once it is generated from the vertices of a mesh and once I import it from Curves, so the error just can come from the las part of the code I think:

wut

Thanks for anybody looking at it!

Posts: 1

Participants: 1

Read full topic

C#: creating mesh, invalid vertex indices

$
0
0

@lukert.david wrote:

Hey there,

I’m trying to create a C# component, where you input two curves and divide them x times.
The Points on the curves should be the vertices for a quadrangular mesh.
Although the preview doesn’t look that bad i get an invalid mesh as output.

The exact statement is:
Mesh: ON_Mesh.m_F [4] .vi[ ] has invalid vertex indices.

Thanks for your help!

Lukertplugintest4.gh (5.6 KB)

The Code:

private void RunScript(Curve iCurve1, Curve iCurve2, int iSegments, ref object Mesh, ref object Vertices, ref object Validity)
{

List<Point3d> ptsCurve1 = new List<Point3d>();
List<Point3d> ptsCurve2 = new List<Point3d>();

Point3d ptCurve1 = new Point3d();
Point3d ptCurve2 = new Point3d();

double spacing = 1.0 / iSegments;
double t;

// divide curves
for (int i = 0; i < iSegments; i++)
{
  t = i * spacing;
  ptCurve1 = iCurve1.PointAtNormalizedLength(t);
  ptsCurve1.Add(ptCurve1);
  ptCurve2 = iCurve2.PointAtNormalizedLength(t);
  ptsCurve2.Add(ptCurve2);
}

// reverse list if indices are on the wrong side
if (ptsCurve1[0].DistanceTo(ptsCurve2[0]) >                                                                                           ptsCurve1[0].DistanceTo(ptsCurve2[iSegments - 1]))
{
  ptsCurve2.Reverse();
}

Mesh mesh = new Mesh();

for (int i = 0; i < iSegments; i++)
{
  mesh.Vertices.Add(ptsCurve1[i]);
  mesh.Vertices.Add(ptsCurve2[i]);
}

for (int i = 0; i < mesh.Vertices.Count; i += 2)
{
  mesh.Faces.AddFace(i, i + 1, i + 3, i + 2);
}

Mesh = mesh;
Vertices = mesh.Vertices;
Validity = GH_Format.FormatMeshValidity(mesh);

}

Posts: 4

Participants: 3

Read full topic

[Video Recordings 2018] C# Scripting and Plugin Development for Grasshopper

$
0
0

@LongNguyen wrote:

I am very happy to share the video recordings of the 2018 workshop on C# Scripting and Plugin Development for Grasshopper

Video recordings, handouts and software requirements:
http://bit.ly/CSharpWorkshop2018

Enjoy!

If you already watched the 2017 workshop last year, you will find new content in this year 2018 workshop, specifically tailored for Rhino 6. In addition, the Flocking Simulation case study from 2017 is now replaced with Mesh Growth, where we covered several new topics such as half-edge mesh data structure, creating complex mesh surface by adaptive subdivision and self-intersection avoidance using sphere-sphere relaxation

Posts: 1

Participants: 1

Read full topic

Voronoi Problem

GHPyhon access to Grasshopper.GUI

$
0
0

@ivelin.peychev wrote:

Is it possible to instantiate GHpython component and within it to manipulate how it looks graphically on Grasshopper canvas?

For example with python script to access Grasshopper.GUI api and add a slider to the component or adding a button functionality

Posts: 5

Participants: 2

Read full topic


Building a value list based on values in sc.sticky or other non-GH storage space

$
0
0

@Bianchi wrote:

I’ve seen that Ladybug and Honeybee make use of the Value List as a shortcut for calling and loading templates in Grasshopper. How do I go about doing something similar, but where the values in the list are generated from a backend storage space like scriptcontext’s sticky dictionary or something similar?

For example:

The top one is the Value List as used by Honeybee/Ladybug, the lower one is how my customized Values List with theoretically look like. What I’d like to do is that the Values List can load a list of values available from an external storage space like sc.sticky, and that it will immediately change its available values if this storage space is added to or subtracted from. Is it also possible to have outputs other than integer/float values, i.e. strings?

I don’t need to stick to using Value List, the gist is that I’d like to generated a drop-down menu “component” in Grasshopper, using Python. Any hints or alternatives approaches would be much appreciated, thanks!

Posts: 4

Participants: 2

Read full topic

Got invalid PolyLines after compiling in vs which work in the c# component

$
0
0

@Baris wrote:

Hi,

as in the title described the problem is strange.
I copy the code from the c# component and compile it and it outputs invalid polylines when the division number is uneven:

 private void RunScript(Surface S, int U, int V, ref object A)
  {

    var pLines = new List<Polyline>();



    double uStep = 1.0 / U;
    double vStep = 1.0 / V;

    Point3d ptA;
    Point3d ptB;
    Point3d ptC;
    Point3d ptD;




    S.SetDomain(0, new Interval(0, 1));
    S.SetDomain(1, new Interval(0, 1));

    for (int i = 0; i < U + 1; i++)
    {
      for (int j = 0; j < V + 1; j++)
      {



        if ((i + j) % 2 == 1)
        {
          var pts = new List<Point3d>();
          if (i > 0)
          {
            ptA = S.PointAt((i - 1) * uStep, j * vStep);
            pts.Add(ptA);
          }
          else
          {
            ptA = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptA);
          }


          if (j > 0)
          {
            ptB = S.PointAt(i * uStep, (j - 1) * vStep);
            pts.Add(ptB);
          }

          else
          {
            ptB = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptB);
          }


          if (i < U)
          {
            ptC = S.PointAt((i + 1) * uStep, j * vStep);
            pts.Add(ptC);
          }

          else
          {
            ptC = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptC);
          }



          if (j <= V - 1)
          {
            ptD = S.PointAt(i * uStep, (j + 1) * vStep);
            pts.Add(ptD);
          }

          else
          {
            ptD = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptD);
          }

          pts.Add(ptA);


          pLines.Add(new Polyline(pts));

        }

      }

    }
    A = pLines;
  }

here the vs file:CrvDiamondComponent.cs (5.5 KB)
Thanks for aclaration!

Posts: 12

Participants: 4

Read full topic

MathNet.numerics GH_Python implementation Questions

$
0
0

@ivelin.peychev wrote:

Hi,

Can someone elaborate on what is happening inside the defs here:
using-math-net-numerics-in-ghpython

@piac, I understand the result but what is happening inside the defs?

def copy_matrix(m, ctor):
n = ctor(m.RowCount, m.ColumnCount)
for r in range(m.RowCount):
    for c in range(m.ColumnCount):
        n[r,c]=m[r,c]
return n
def to_rh_matrix(dotnet_m):
from Rhino.Geometry import Matrix as rgm
return copy_matrix(dotnet_m,rgm)
def to_dotnet_matrix(rhinocommon_m):
from MathNet.Numerics.LinearAlgebra.Double import Matrix as dnm
dense = dnm.Build.Dense
return copy_matrix(rhinocommon_m,dense)
def copy_vector(m,ctor):
try:
    if m.RowCount==1:
        n=ctor(m.ColumnCount)
        for c in range(m.ColumnCount):
            n[c]=m[0,c]
    elif m.ColumnCount==1:
        n=ctor(m.RowCount)
        for r in range(m.RowCount):
            n[r]=m[r,0]
except:
    n=ctor(m.Count,1)
    for i in range(m.Count):
        n[1,0]=m[i]
return n
def to_rh_vector(dotnet_v):
from Rhino.Geometry import Matrix as rgm
return copy_vector(dotnet_v,rgm)
def to_dotnet_vector(rhinocommon_v):
from MathNet.Numerics.LinearAlgebra.Double import Vector as dnv
dense = dnv.Build.Dense
return copy_vector (rhinocommon_v,dense)

So about this code what is ctor?
If it is a variable how can you use it without defining it?

Another question is,
2018-05-08%2023_04_11-Grasshopper%20Python%20Script%20Editor

I define a matrix and I get output for A:
ANN_

and output for B:
ANN_

However, when I try to convert from output A to GH.matrix I get:

Is there a way to define the matrix as a string from the “panel” component?

EDIT:
I figured out that ctor is a ‘constructor’, not sure what that means but I’ll read about it. You can ignore the first part of this post.

Posts: 2

Participants: 2

Read full topic

Problems creating GHPY files

$
0
0

@Will_Wang wrote:

So I ran into this today.
I had to re-install Rhino because it wasn’t opening correctly. Afterwards, GH could no longer load a previously compiled .ghpy file. Error message comes up at GH splash screen, saying it’s import error. Could a re-install have changed a module that was used? Strange thing is that I’ve sent that .ghpy file to colleagues and it even worked across different machines.

Posts: 3

Participants: 2

Read full topic

Create bitmap from GH canvas via script

$
0
0

@SzaboLaszlo wrote:

Hello Rhino Team,

Has it any option, method to save image from grasshopper canvas?

Such as ScreenCaptureToFile command in rhino?

Thanks,

Laszlo Szabo
QA Test Automation Engineer
GRAPHISOFT SE

Posts: 7

Participants: 3

Read full topic

Viewing all 3652 articles
Browse latest View live


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