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

Panel User Text Python Gh


Mesh invalid after adding vertices

$
0
0

@Moonpick wrote:

Hello,

I am writing a c# component where I cut some mesh faces and I have a difficulties keep the mesh valid during the process.
I have a polyline lying on a triangle mesh and I split every face it crosses. So I go throught all faces and for each crossed face, I do:
1- create new vertices at intersections edges/polyline (if not already created processing the neighbour face)
2- for each created vertex, create new TextureCoordinates (average of neighbour vertices respectiv TextureCoordinates)
3- add the new vertices resp. TextureCoordinates to Mesh.Vertices resp. Mesh.TextureCoordinates
4- create 2 new faces using the new vertices (so I get a triangle face and a quad face)

At the end of the loop I remove the orginal “crossed faces” and recompute the normals.

The new mesh looks all right, but it is invalid, disturbing the further process. Using the Mesh.IsValidWithLog methode, I get following feedback:
ON_Mesh.m_S.Count() = 25741 (should be 0 or 26942=vertex_count).

And here am I. I had a look in the Rhino C++ API, but couldn’t get what m_S actually is / how I can solve the problem, so any help from the forum welcome!

Thank you.

Pierre

Posts: 1

Participants: 1

Read full topic

Creating custom component with variable number of inputs and outputs

$
0
0

@aleksanderdynarek wrote:

How to create a custom component with variable number of inputs and outputs? Please for a newbie guide, i have no idea where to start

Posts: 4

Participants: 2

Read full topic

GH_GeometricGoo - Constructor Advice Needed

$
0
0

@Big_G wrote:

Hi C# guru’s,

I have created a GeometricGoo wrapper class based on examples found on this forum for a special beam class I have. All compiles well and the component works as intended.

I have the following question?

After running a Visual Studio Code Analysis on my Solution, it highlights the following warning.

It’s not breaking my application, but in my attempt to better my programming skill, I would like to know how to resolve it.

Part Code extract.

public class GH_Beam : GH_GeometricGoo<Beam>, IGH_PreviewData
    {
        #region constructors
        public GH_Beam()
        {
            this.Value = new Beam();
        }
        public GH_Beam(Beam beam)
        {
            if (beam == null)
                beam = new Beam();
            this.Value = beam;
        }
        .
        .
        .
        .
}

MicroSoft Docs Issue Link

Any advice or work around will be appreciated.

Posts: 8

Participants: 4

Read full topic

Data Tree Matching in ghPython -- Trees of Differing Depths

$
0
0

@bushdylanj wrote:

I’ve made a function in Python that makes a negative curve parameter “wrap” the curve (so, basically, if t is negative, subtract t from max of curve domain).

For context, I have a working knowledge of Python, but I’m not very experienced, and this is my first attempt at using the Grasshopper library in Python. (I’m also open to solutions using C# if it would be better suited to solving my issue)

The Python script works just fine with item access when the input is a single curve with a number of curve parameter inputs, or with multiple curves when the lists of curves and parameters are made to align before going into the python component.

I’m struggling to get the function to work with tree access for the tree structure I would like to be able to input and would appreciate any help / advice / examples that may be helpful.

Here is my goal data matching, with the colored x’s being items, the left side being the input curves and the right being the parameter values:

The GH definition I’m working in is using this python component to cull points from a curve when they result in an angle that doesn’t meet a set tolerance – the file has three iterations inside it:

The first is taking in one curve and a basic tree of parameters, using item access, getting a working result.

The second is taking in a grafted list of curves, and a more complex tree of parameters, using item access the data does not match in Python as intended.

The third uses a workaround in GH that duplicates data in the list of curves to match the list of parameters before going into Python, so that the Python script will work with item access. This is working fine for what I need it to do, but it would be great to figure out how to solve this problem in Python.

I’ve also left in my attempt at getting the script to work with tree access. It makes sense in my head but I’ve hit a point where I’m struggling to make sense of the errors I’m getting and some alternative opinions could really help.

Thanks
EVAL CURVE WRAP TEST.gh (90.9 KB)

Posts: 6

Participants: 2

Read full topic

Text alternative to binary .ghcluster files

$
0
0

@olvdct wrote:

.ghcluster file are binary. Is there a text alternative?
Basically what .ghx is to .gh, but for clusters.

Posts: 1

Participants: 1

Read full topic

How to flag component param as grafted or flattened?

$
0
0

@Chuck_Driesler wrote:

What is the best strategy for flagging a component’s input/output param as grafted or flattened through the api? Similar to if I had right clicked it and selected the option?

I’ve found that you can set Reverse and Simplify, but it looks like graft and flatten only exist on the IGH_Structure class. Is there something I can set ahead of time that would guarantee the data is modified correctly when CollectData() or ComputeData() are called some time later?

It looks like it might be the StateTags, but I can’t figure out which property to set.

Posts: 1

Participants: 1

Read full topic

How to transfer from Rhino.Geometry.Brep to GH type brep

$
0
0

@lmnoc1 wrote:

Might be a stupid question here. But I have been researching for hours and still can’t make it work. Thank you.

I want to use offset brep (Brep.CreateOffsetBrep) from RhinoCommon to offset a brep
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_CreateOffsetBrep.htm

I tried to use the component in Parakeet but it doesn’t support negative number (offset inwards)
So when I used the python code below it outputs a Rhino.Geometry.Brep type how can i change it to the grasshopper brep type?
I tired Grasshopper.Kernel.Types.GH_Brep(b) but not really working
Maybe not the correct command. Not really a coder here. Thanks for any help.

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext
import Grasshopper

brep = rs.coercebrep(x)
a=Rhino.Geometry.Brep.CreateOffsetBrep(brep, 0.2, True, True, 0.01)
#a=Grasshopper.Kernel.Types.GH_Brep(b)

Also is this code correct for using offset brep? Thanks

Posts: 7

Participants: 4

Read full topic


Displaying a Vector using C# and GH_PreviewUtil....?

$
0
0

@mlewis wrote:

Hi,

im trying to write a component that will take a line and show the line as is its a vector (line start point as the anchor point and line end point as the vector). ive found that i can do this using GH_Preview Utility. (see attached images)

the issue im having is that once in Rhino, after ive created a line and plugged it into my component, if i try to adjust the original line (move one of its endpoints for example) the original vector preview (and every following one) is persistent regardless of if i clear the component, freeze, etc.

my assumption is that it has something to do with how the code is handled in the solver instance? any ideas of how to fix this?

Posts: 1

Participants: 1

Read full topic

How can I make my python type visible in rhino viewport?

$
0
0

@grasshoppertrainer wrote:

Hello y’all fellow trainers.
I’ve been craving for the answer and got into the point where the only thing left is to ask directly.
What I’m trying to do is to make grasshopper display preview geometry for my(written inside a ‘Pyton script’ component) python type(class).
So, Inside the component, I’ll produce an instance which includes a grasshopper geometry(ex. mesh) as an parameter with bunch of other class-specific parameters(ex. self.the_mesh = x, self.index = 0…).
I can return this instance and use it inside another custom component.
But the thing it doesn’t do is to draw preview on rhino viewport like returning simple grasshopper mesh object would do.

I’ve read various topics about custom previewing regarding GH_Goo or IGH_PreviewObject, IGH_PreviewData but still can’t understand it. Most of them where about VB and I think that’s why.

Thinking of render pipeline I can imagine of two aproaches;

  1. Grasshopper reads components property to render preview so I need to pass Myclass().geo to MyComponent.some_assigned_parameter.
  2. Grasshopper reads every output of a component so Myclass need to inherit grasshopper built-in class as a protocol and some of its parameter or method has to be overriden to coop with Myclass().geo.

I do understand intermediate python syntax like inheritence, overriding parent’s method etc.
Please give me an insite.

Thank you.

—following is my script—

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

class MyComponent(component):     
    def RunScript(self, x):
        # input x is as list including a grasshopper geometry object
    
        class Myclass:
            def __init__(self, data):
                # 'geo' is a representative parameter of an instance
                self.geo = None
                for i,d in enumerate(data):
                    if isinstance(d, System.Guid):
                        self.geo = rs.coercegeometry(d)
                        data[i] = self.geo 
                self.data = data
                
        b = Myclass(x)
        return b
        # want to make this 'MyComponent' draw self.geo on rhino viewport

Posts: 2

Participants: 2

Read full topic

ErrorMessage: Rhino.Geometry.Brep.CreatePlanarBreps(Rhino.Geometry.Curve) is outdated

$
0
0

@oliver_1992 wrote:

Hello.
I’m a beginner in developing grasshopper components in Visual Studio and I have quite a hard time getting the syntax of the RhinoCommon library right.

I’m trying to use:

////https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_CreatePlanarBreps_1.htm
public static Brep CreatePlanarBreps(Curve inputLoop)

Using the method, I’ getting the error message:

  1. Warning (CS0618): ‘Rhino.Geometry.Brep.CreatePlanarBreps(Rhino.Geometry.Curve)’ ist veraltet: ‘Use version that takes tolerance as input’ (line 57)

(veraltet means outdated)

191228_00_c#-code-samples_create-planar-breps.gh (6.0 KB)

Sometimes the method works, but I get this error message anyway.
It seems the method I´m using is outdated, but I took the method out of the RhinoCommon library.
I have attached the gh file, including my code definition in C#.
Does anybody know, what I´m doing wrong?
Best wishes,
Oliver

Posts: 3

Participants: 2

Read full topic

Curve.GetNextDiscontinuity Method

$
0
0

@oliver_1992 wrote:

Hello.
It’s me again.
I am confused by the Syntax of the Curve.GetNextDiscontinuity Method.
https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Curve_GetNextDiscontinuity.htm
I understand the concept of continuity of curves, as well as the out keyword. I know that the return type is a boolean.
But I must miss something because I can’t make it work.
Could someone help me typing in the method?
I’ve attached an example gh script with one of my attempts.
As well as a screenshot of it.

191228_00_c#-code-samples_curve-get-next-discontinuity.gh (6.5 KB)

Thank you very much for reading.
Best wishes,
Oliver

Posts: 2

Participants: 2

Read full topic

Looking for the professional grasshopper coder for 3d printing integrated program

$
0
0

@yuuuukan wrote:

The project is to make grasshopper code optimize and modification to make 3d printing object.

The fee is 500 dollars and have to finish in 2 weeks(Until mid of Jan) for the first step and adding salary in next step
C## and python is must.

text me to the email↓ someone interested in it.
yuuuukan@gmail.com

Posts: 1

Participants: 1

Read full topic

Using Arrays in C#

$
0
0

@duanemclemore wrote:

Hi All,

I am developing a component, but am still new to C#. We can get in to the specific code of my question a little later, but let me explain my purpose first and there may be a general answer.

I am trying to generate lattices of 3d points. The eventual goal is to generate very large lattices, so I am trying to use the fastest calculation methods I can. One of my requirements is to be able to select or describe the position of any single item within this lattice as minimally as possible. A one-dimensional array with three elements for each point would be ideal, with an element for the x, y, and z position within the lattice.

I have had no problems using simple nested for loops to generate the x,y, and z indices as separate lists. However, I’ve tried everything I possibly could to get an array out, to no avail.

The VS build is always successful, but when I get to the Grasshopper canvas, there’s usually an error that it could not convert from int32[] to GH_Integer.

I’ve also tried to build Data Trees using the same loops, unsuccessfully.

I’ve gotten output that Grasshopper will actually recognize from using a one-dimensional Rhino.Geometry.Matrix. However, it never recognizes the looping and only outputs one matrix with the largest index in each direction in that column. And I’m also afraid that since that’s a “geometry” type, it will increase the calculation time once I’m up into the very, very many lattice points.

And on the note of a matrix, a single 3d matrix would be a swell way to describe the lattice point positions, but I fear that it would be the most time consuming addressing method possible.

Anyway - that’s the whole background. If anyone has a way to solve my int32[] to GH_Integer problem, that would solve it in a way I could move on with. But if you all need more code to understand what’s actually going wrong, we can get into that.

Thanks in advance for any help!

Duane

Posts: 15

Participants: 3

Read full topic

Referencing Rhino Geometry in Grasshopper C#

$
0
0

@m.khalili9093 wrote:

Hi everyone

I want to create a component for grasshopper in C#. the component has to be able to select a curve from rhino (as you know there is a Curve parameter in grasshopper that we can select set one curve /set multiple curves and then we are able to select a curve from rhino i showed in the image below) .I want to know If in my component I need to select a curve from rhino what should I write for that in C# ?

Thanks a lot in advance!

Posts: 7

Participants: 3

Read full topic


REALLY Stupid C# Question

$
0
0

@duanemclemore wrote:

I’m writing a component which creates some new geometry. Right now it’s written based only on the WorldXY plane but I want the user to be able to input the initial base plane. So I’m trying to create a Transform to apply. But I always get the same error. And this is a dumb and simple C# error, but I can’t find any solution. I have tried both ChangeBasis and PlaneToPlane, but either way I get an error in the form of

Type name ‘ChangeBasis’ does not exist in the type ‘Transform’

or

Type name ‘PlaneToPlane’ does not exist in the type ‘Transform’

When I go to the Definition in VS, both ChangeBasis and PlaneToPlane are clearly listed. I am using Rhino.Geometry. and when I don’t add the “type,” but input the base and target planes it tells me that Transform doesn’t contain any methods with two overloads.

This is really a dumb, noob question. But I seem to be missing something fundamental - and I’ve gotten pretty far in C# without having run into this before. Thanks in advance for any help.

Posts: 9

Participants: 3

Read full topic

C# output with unwanted sublist

$
0
0

@SumYu wrote:

Hi Everyone,
I’m trying to create a plugin to cutting the building model by named CPlanes using C# Visual Studio. I can filter and get the name of CPlanes as expected. Once i added the code to output Planes, the output contains more items than i need. I just begin to learn C#. Please advise how to achieve the result. Thanks.
Get CPlanes.3dm (55.8 KB)

Code for Get Names of CPlanes
pManager.AddBooleanParameter(“Update”, “Update”, “Update CPlanes info”, GH_ParamAccess.item);
pManager.AddTextParameter(“Name”, “N”, “Cplanes Names”, GH_ParamAccess.list);
protected override void SolveInstance(IGH_DataAccess DA)
{
bool iUpdate = false;
DA.GetData(“Update”, ref iUpdate);

        List<Plane> oPlanes = new List<Plane>();
        List<string> cPlaneName = new List<string>();
        List<string> oName = new List<string>();
        var doc = RhinoDoc.ActiveDoc;
        var cPlanes = doc.NamedConstructionPlanes;
        if (iUpdate)
        {
            for (int i = 0; i < cPlanes.Count; i++)
            {
                cPlaneName.Add(cPlanes[i].Name);
            }
            foreach (string mylist in cPlaneName.Where(a => a.Contains("mPD")))
                oName.Add(mylist);
                DA.SetDataList("Name", oName);
        }
    }

Code for Get Planes

    {
        bool iUpdate = false;
        DA.GetData("Update", ref iUpdate);

        List<Plane> oPlanes = new List<Plane>();
        List<string> cPlaneName = new List<string>();

        var doc = RhinoDoc.ActiveDoc;
        var cPlanes = doc.NamedConstructionPlanes;

        if (iUpdate)
        {
            for (int i = 0; i < cPlanes.Count; i++)
            {
                cPlaneName.Add(cPlanes[i].Name);
            }
            foreach (string mylist in cPlaneName.Where(a => a.Contains("mPD")))
            {
                int CPindex = RhinoDoc.ActiveDoc.NamedConstructionPlanes.Find(mylist);
                Plane getPlanes = RhinoDoc.ActiveDoc.NamedConstructionPlanes[CPindex].Plane;
                oPlanes.Add(getPlanes);
                DA.SetDataList("Plane", oPlanes);
            }
        }
    }

Posts: 4

Participants: 2

Read full topic

Using scripting in gh

$
0
0

@bhattprathmesh.89 wrote:

Namaste All,
I am using a python package called decode in grasshopper and was trying to display the outcome in the rhino window but the following error is displayed :

" Runtime error (MissingMemberException): ‘GrasshopperDocument’ object has no attribute ‘CreateDefaultAttributes’ "

This is the code that I am trying to run :

import decodes
from decodes.core import *
outie = decodes.make_out(decodes.Outies.Rhino)
outie.put(Point(1,2))
outie.draw()

Here, I am able to run first and second line successfully.
“outie” is a translation object which we use to display and transport geometry to traditional CAD. but am unable to run it. Kindly help. Thanks :slight_smile:

Posts: 1

Participants: 1

Read full topic

Offset Surface Discrepancy

$
0
0

@gruedisueli wrote:

Hi,
I am finding a discrepancy in the behavior of the built-in offset surface grasshopper component and Surface.Offset as found here: https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Surface_Offset.htm .

Both should in theory be identical, however I am finding that the API version of offset surface is disregarding the normal direction of the surface and always offsetting the same direction.

I’ve attached a rhino file and script. You’ll see that with one direction of the surface, both operations are identical, while when I flip the surface, the two return different results.

NOTE: I’ve found this behavior seems to also occur with offsetting a curve normal to a surface. (https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Curve_OffsetNormalToSurface.htm).

Thoughts?

bug_offsetSrfNormal.gh (17.1 KB) bug_offsetSrfNormal.3dm (25.7 KB)

Posts: 1

Participants: 1

Read full topic

Nuget grasshopper version discrepancy

Viewing all 3630 articles
Browse latest View live


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