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

Why is GH_Point not GH_Goo

$
0
0

@Minozheros wrote:

Hi…
I am trying to create Arrays of the underlying DataTypes to use them with Cuda.
The following Code works for the Types i need

GH_Boolean => Boolean
GH_Integer => int
GH_Number => double
GH_Vector => Vector3d
GH_Matrix => Matrix
GH_Surface => Brep

internal NewType[] HandleData<GH_Type, NewType>(GH_Type[] array) where GH_Type : GH_Goo
{
NewType[] newArray = new NewType[array.Length];
for (int i = 0; i < array.Length; i++)
{
Array[i] = (NewType)array[i].Value;
}
return newArray;
}

The only one where it does not work is GH_Point => Point3d. The reason is simple because GH_Point is not GH_Goo or GH_GeometricGoo respectively, but implements the IGH_Geometric interface. I am wondering, why that is the case and if it wouldnt be possible to have GH_Point being consistent with the other types.

Posts: 1

Participants: 1

Read full topic


Update the "Image sampler" component with python

$
0
0

@603419608 wrote:

I want to update the image of the “Image sampler” component using python,.But I have some problems,I updated the image link, but the “Image sampler” component is not updated display.
like this:

I want to ask if there is any function that can update the display of the “Image sampler” component.
Thanks for anyone’s advice,Thanks
This is my code:
from Grasshopper.Kernel.Special import GH_ImageSampler
from Grasshopper.Kernel.Special import GH_ImageSamplerAttributes

ghDoc = ghenv.Component.OnPingDocument()
ghObjects = ghDoc.Objects

for i in ghObjects:
    if type(i) is GH_ImageSampler:
#        print i
        i.ImageFilePath = x
        #i.DisplaySettings()
        a = i.ImageFilePath

my gh file:
Image_sampler_test.gh (354.8 KB)

Posts: 1

Participants: 1

Read full topic

Text Match - multiple pattern input

Non-Manifold to Manifold

Custom component: wait for external process without locking GH UI

$
0
0

@harmatb wrote:

Dear all!

Developing a set of real time or live-link components for a steel FEA software. I was wondering, how to achieve the following component behaviour:

While the component waits for the external software to update it’s own model, give control back to the Grasshopper GUI (eg user can pan, zoom around, mouse over component parameters to get the string overview of the values etc) but without the component lying about being solved. (so other components down the line wait for it to actually really finish).

I found this behaviour working in another component family. (namely the Grasshopper live-link of Tekla, which is a CAD software also part of our production chain)
But I could not find out how to reach this behaviour.

Any pointers would be welcome, what should I look for with this goal in mind?

Best Regards,
Balint

Posts: 1

Participants: 1

Read full topic

Type Box not recognized

$
0
0

@RIL wrote:

Strange, in C# ScriptComponents the following code works fine ("if (obj is Box)") but not in Visual Studio. Why is that? Inspection shows that I have a valid obejct of the right type, but the code doesn’t enter the if-block:

Edit: More of the code:

if (obj is Box)
{
    bbox = (Box)obj;
    ...
}
else if (obj is Brep)
{
    brep = (Brep)obj;
    ...

It seems I cannot read either Box or Brep with the same input (as generic object or Brep) and then cast it to either. But in the ScriptComponent this code was no problem (with input hint set to System.Object). Can you @DavidRutten (or someone else) shed some ligth on this?

// Rolf

Posts: 3

Participants: 2

Read full topic

Build .ghuser .ghcluster with .gha file

$
0
0

@Amir_Habibi wrote:

Hi , any guide for how to bring .ghuser and .ghcluster files to the compiler and build them with a gha file ?

Posts: 7

Participants: 3

Read full topic

Saving data which is specific for Custom component

$
0
0

@Dmitriy wrote:

Hi guys,

Basically main part is stated in the header.
I need to store some data in GH file relevant to Custom component only.
Any example how to do it?

Thanks,
Dmitriy

Posts: 1

Participants: 1

Read full topic


Rectangle Close-Packing

$
0
0

@19navid93 wrote:

Hi

I have written a definition for the optimization of hospital floor plans based on the intensity of interaction between different departments. I have used a close-packing approach, in a discrete solution space and with dynamic sliders (using metahopper). Galapagos is used for optimization, but the problem I have is I very rarely get good outcomes. Usually lots of gap remain between spaces. I would appreciate any help as to:

  1. how to decrease the gaps
  2. how to use Galapagos more efficiently in the case of this problem

hospital code (last version).gh (248.9 KB)
In this uploaded file, the last version of the definition is the one which is active.

Thanks again,
looking forward to hear from you!

Posts: 1

Participants: 1

Read full topic

C# make runscript error on purpose

$
0
0

@loic.pelletier wrote:

Hi,

Not in visual studio but in c sharp editor in grasshopper, I would like to make error on purpose.

Let say

if(i = 0)
ComponentBecomeRed and display a message

How can I make this?

Posts: 5

Participants: 5

Read full topic

Problem with IGH_VariableParameterComponent

$
0
0

@klaus.grosskopff wrote:

Hi, I am trying to get a IGH_VariableParameterComponent to work, but i am experiencing some problems, that i don’t think I can solve on my own.

Everything works fine when i am using the standard parameters, the problem starts when i am trying to use my own parameters with it

I dont have trouble Loading my parameter in a normal control, I can also use the variable parameter control with the build in parameters…
It will look fine when you set it up, and it will work. So far so good…

After saving and reopening the file the parameter will be a “Empty Generic Data parameter” and there are a bunch of errors popping up :

Parameter type is unknown
Input parameter chunk is missing. Archive is corrupt.
Output parameter chunk is missing. Archive is corrupt.

If i register my Parameter in a normal Component using the regular way to instaniate a paramter it will save and load without any problems though i think either i am missing out on something i have to do with my own parameter, or there is something wrong as everything works fine with the standard parameters

This codesnippet shows what will work and what not…

public IGH_Param CreateParameter(GH_ParameterSide side, int index) {
IGH_Param param = default(IGH_Param);
switch (side)
{

// BROKEN

           case GH_ParameterSide.Input:
                param = new MyTestParameter();
                param.Name = "input" + index;
                param.NickName = "input" + index;
                Params.RegisterInputParam(param);
                break;

//WORKING

            case GH_ParameterSide.Output:
                param = new Grasshopper.Kernel.Parameters.Param_Integer();
                param.Name = "output" + index;
                param.NickName = "output" + index;
                Params.RegisterOutputParam(param);
                break;
        }
        return param;
    }

I included some TestComponents and a Testparameter that will demonstrate the problem…
Just add them to a canvas and add a few Paramters, save the file and reopen it…

There is one more thing though which i dont know why it is happening… if i delete a parameter in the list that is not the last parameter it will delete not one but two adjacent parameters…

Regards Klaus

MyTestParameter.zip (3.2 KB)

Posts: 1

Participants: 1

Read full topic

C# Surface.Trim Method

$
0
0

@obhagwat29 wrote:

Hello,
I am trying to split the surface with surface.trim method. I tried got the points on U and V direction and want to trim the surface at that location. result shall be similar to first image.
I am bit confused with surface domain and Interval class relation.

attached script and images

List<Surface> sfs = new List<Surface>();
for(int i = 0; i < U + 1; i++)
{
  //GH_Path gp = new GH_Path(i);
  for(int j = 0; j < V + 1; j++)
  {
   Interval iU = new Interval(x.Domain(0).Length / U * i, x.Domain(1).Length / V * j);
    Interval iV = new Interval(x.Domain(0).Length / V * j, x.Domain(1).Length / U * i);
    //Interval iU = new Interval(????????
    //Interval iV = new Interval(???????
    Surface s = x.Trim(iU, iV);
    sfs.Add(s);
  }
}
A = sfs;

This is desired(surface is splited with gh native component surface split.
trim%201

and this is my scripts outout
trim%202

Posts: 2

Participants: 2

Read full topic

Custom component GUI - component menu item expand on mouse hover

$
0
0

@dgebreiter wrote:

Hi,

on a custom component, I am trying to add an item to the component menu (right-click). I use the Menu_Append… functions as advised in the GH SDK.

Now I am trying to add an item which behaves exactly like the “Runtime warnings” item. I would like it to have a little triangle on the right, and to expand and display a second list when the mouse hovers over it. Like “runtime warnings”, the second list should then have clickable items

Is there a Function akin to the Menu_Append… functions which I can draw on for this behaviour or will I have to engineer it myself using the menu.MouseHover event etc.
However, to replicate the exact functionality and look, maybe this type of element could be exposed in a Menu_Append… function? Or even better, @DavidRutten, would you share a relevant code snippet?

Many thanks!

Daniel

expand
it is the behaviour of “Runtime warnings” I am trying to replicate, except with different content.

Posts: 3

Participants: 2

Read full topic

Compiled .ghpy input tree access error

$
0
0

@Will_Wang wrote:

compiled a component and it gives me this error
it works ok before compilation
input at index 0 is this

image

any help please?

UPDATE: I changed Param_Geometry() to Param_GenericObject() and it seemed ok but the second input now is erroneous.

So does the GH_ParamAccess.tree not work with any other type than Param_GenericObject()???

Posts: 2

Participants: 2

Read full topic

Multiple parallel api web calls in c#

$
0
0

@maje90 wrote:

Hi all,
I’m trying to make a c# script to make multiple url api requests with “async” and “await”, so thousand of request would be done “simultaneously” instead one after the other.

Non-parallel method works.
(I’m sorry but during edit I’ve lost the string-comment giving credit to original author of this fragments of codes… it was someone on the old gh forum…)
But it starts each url api request after the previous one ended (in a for cycle). Not what i want.

Generically, I hope someone could help in this… I’ve lost many hours already and now i’m struggling with…
script editor removing keywords!!!

Usually c# script editor “cleans” up the script by adding or removing spaces in the script, and that’s ok.
Here instead it completely delete the “await” keyword every time you enter the editor!! (see comment inside script)
Is this a bug?

Anyhow, that script works for just “that” slider set at “2”, if I make the lists larger it make the whole rhino environment (or gh, who knows…) to freeze.

Hoping in some of you experts!

web_api_calls_V0.5.gh (16.4 KB)

Posts: 11

Participants: 5

Read full topic


Export Contours per branch C#

$
0
0

@Baris wrote:

Hi,

I want to export curves per branch to dxf via code, so that I have a file for each heightsection.
I got stuck looping through the tree.
Maybe someone can help me out.

private void RunScript(bool export, Brep brep, List plane, string path, string fileType, string filename, ref object A, ref object B)
{

// get contours
var contourTree = new DataTree<Curve>();
for (int i = 0; i < plane.Count; i++)
{
  Curve[] contours = Brep.CreateContourCurves(brep, plane[i]);
  contourTree.AddRange(contours, new GH_Path(i));
}

//get or create directory

if (!System.IO.Directory.Exists(path))
{
  System.IO.Directory.CreateDirectory(path);
}

//create filetype

if (!fileType.StartsWith("."))

{
  fileType = "." + fileType;
}

//declare attributes
ObjectAttributes attr = RhinoDocument.CreateDefaultAttributes();

var doc = Rhino.RhinoDoc.ActiveDoc;
if (doc == null) return;

doc.Objects.UnselectAll();

if (export)
{
  for (int i = 0; i < contourTree.BranchCount; i++)
  {


    var crvs = doc.Objects.AddCurve(contourTree.Branches[i], attr);
    doc.Objects.Select(crvs);
    Rhino.RhinoApp.RunScript("-_Export \n\"" + path + "\\" + filename + fileType + "\"\n _Enter", true);

  }
}


A = contourTree;

}

Thanks

file:
20180925_BakeExport.gh (9.6 KB)

Posts: 4

Participants: 2

Read full topic

Mesh Fill Holes - Best strategy?

$
0
0

@RIL wrote:

I need to find a reliable way to fill small holes in a mesh. Example of what I have is to the left in the picture, and when I run mesh.FillHoles() it… well, it doesn’t look very good (right):

The outer edges can be left as is (probably can’t be fixed(?))

Best strategy? Preferably via RhinoCommon, but any solution that works well for this is welcome

// Rolf

Posts: 15

Participants: 5

Read full topic

Grasshopper C#

$
0
0

@kazujoestar wrote:

Hi guys,I’m studying C# to use Grasshopper C# compornent.

but there is few reference script, so It is hard to study.

How did you study C# ?

I’m just want to use grasshopper C# compornent, not visualStudio.

Let me know if there is a good idea.
Thank you.

Posts: 6

Participants: 4

Read full topic

How to add userobject to gh ToolPanel by C#?

$
0
0

@andrealu2012 wrote:

i am trying to add a userobject component to toolPanel,but failed,this is my try:
this is userobject:
image
i drag it into visualstudio,and it become a byte[]:
image

But I have to stop now,because I donnot know how to add this userobject to toolpanel when the grasshopper is starting with other my custom c# component is loading…
image
(for example:add the userobject(in byte[]) in such a place automaticlly when loading)
do some one have idea about it?
Thank you very much!

Posts: 8

Participants: 2

Read full topic

Mesh rendering issues after adding faces

$
0
0

@abarbar wrote:

Hello,

I am trying to add faces to a terrain mesh to close it into a “solid” object. I am projecting the mesh vertices into the bottom plane and adding the faces based on the edges of the original mesh. Afterward, I add the vertical faces based on the naked edges from the original.

the code of this last step is copied here:

for (int i = 0; i <= mTopologyEdges.Count - 1; i += 1)
{
u[0] = mTopologyVerices.MeshVertexIndices(mTopologyEdges.GetTopologyVertices(i).I)[0];
u[1] = mTopologyVerices.MeshVertexIndices(mTopologyEdges.GetTopologyVertices(i).J)[0];

  if ((mTopologyEdges.GetConnectedFaces(i).GetUpperBound(0)) < 1)
  {
    faces.Add(new MeshFace(u[0], u[1], u[1] + vertexCount, u[0] + vertexCount));
  }
}

The mesh ends up rendering with a gradient across the vertical axis. I am assuming this has to do with vertex normals? but I am not sure. Does anyone have any idea on how to fix this?

I am hoping to get something like the left model here as opposed to the right one

Thanks!

SolidMesh.gh (205.4 KB)

Posts: 4

Participants: 3

Read full topic

Viewing all 3636 articles
Browse latest View live


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