Grasshopper

algorithmic modeling for Rhino

Hi,

I would like to create a planar surface between two curves.

In Visual Studion I have two lists of brep outlines:

a) Outline Curve

b) Outline Curve offsetted

In Grasshopper I can graft them and place wires into boundary surfaces battery.

Please take a look at printscreen attached.

How could I write a function that grafts these two lists in C# and makes boundary surface?

C#:

//OUTPUT
        protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        {

            pManager.AddBrepParameter("Glass", "G", "Glass surfaces", GH_ParamAccess.list);
            pManager.AddCurveParameter("FramesOutisde", "F", "Glass frames", GH_ParamAccess.list);
            pManager.AddCurveParameter("FramesInside", "F", "Glass frames", GH_ParamAccess.list);

        }

//INPUT

        protected override void SolveInstance(IGH_DataAccess DA)
        {

            Brep glassSrf = new Brep();
            double frameWidth = 1.0;

            // When data cannot be extracted from a parameter, we should abort this method.
            if (!DA.GetData(0, ref glassSrf)) return;
            if (!DA.GetData(1, ref frameWidth)) return;

            List<Brep> glass = CreateGlass(glassSrf, frameWidth);
            List<Curve> glassFrames = CreateGlassFrames(glassSrf, frameWidth);

            for (int i = 0; glass.Count < 1; i++) {
                DA.SetData(0, glass[i]);
            }

//Here are 2 lists for outline curve and outline curve offseted
            for (int i = 0; i < glassFrames.Count; i++)
            {
                DA.SetData(i, glassFrames[i]);
            }

        }

//Function that adds outline curve and outline curve offseted into one wireframeJoinedOffset list.

        private List<Curve> CreateGlassFrames(Brep glassSrf, double frameWidth)
        {
            //Duplicate surface edges and join them
            Curve[] wireframe = glassSrf.DuplicateEdgeCurves(true);
            Curve[] wireframeJoined = Curve.JoinCurves(wireframe);

            //List for offset curves and planar surfaces
            List<Curve> wireframeJoinedOffset = new List<Curve>();
            List<Brep> frames = new List<Brep>();

            //Methods for offseting and planar surfaces
            for (int i = 0; i < wireframeJoined.Length; i++)
            {

                wireframeJoinedOffset.AddRange(wireframeJoined[i].Offset(Plane.WorldXY, frameWidth, 0.1, CurveOffsetCornerStyle.Sharp));
                wireframeJoinedOffset.Add(wireframeJoined[i]);

                for (int j = 0; j < wireframeJoinedOffset.Count; j++)
                {

                    frames.AddRange(Brep.CreatePlanarBreps(wireframeJoinedOffset[i]));
                }
            }

            return wireframeJoinedOffset;
        }

Views: 1614

Attachments:

Replies are closed for this discussion.

Replies to This Discussion

Also, when I try to add 2 curves list into 1. I still get two separate sub lists.

for (int i = 0; i < wireframeJoined.Length; i++) {
                insideOutside.Add(Inside[i]);
                insideOutside.Add(Outside[i]);
            }

Passing this list to output:

             for (int i = 0; i < glassFrames.Count; i++)    {
                DA.SetData(i+1, glassFrames[i]);
            }

Is it possible to flatten the last for loop to have  only one list  DA.SetData(i, glassFrames[i]) to DA.SetData(1, glassFrames[i]) ?

List<Curve> curves = new List<Curve>();
curves.AddRange(wireframeJoined);
curves.AddRange(wireframeJoinedOffset);

Hello Petras,
in your code I see strange things, for example, why use an array (wireframeJoined) if you really just going to get an item? or why you duplicate the curve (wireframe)?
I enclose the script in gh that does what you want. 

Attachments:

Thank you.

One last question about the output of the function.

When I pass brep list to output I get the following error with empyt list:

1. Invalid cast: Brep » List`1

//OUTPUT:

protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) {

pManager.AddBrepParameter("FramesOutisde", "F", "Glass frames", GH_ParamAccess.list);

 }

//INPUT

        protected override void SolveInstance(IGH_DataAccess DA) {

            List <Brep> glassSrf = new List <Brep>();
            double frameWidth = -0.3;

            if (!DA.GetData(0, ref glassSrf)) return;

            List<Brep> glassFrames = CreateGlassFrames(glassSrf, frameWidth);

            DA.SetData(0, glassFrames);

//I do not know how to write this line correctly. Before I was trying to use for loop, but it did not help.
        }

Attachments:

It is possible at register the input parameter, you gave access for items, rather than list? If this is the problem, the fault was mine, that I did the function working with lists, rather than individual items. It should work well if you change to GH_ParamAccess.list in the input register, but as this component not binding on in any way the different elements, it should use item access on the param and use the function as follows :

private void RunScript(Brep B, double F, ref object A)
{

A = GlassFrames(B, F);

}

// <Custom additional code>
public Brep GlassFrames(Brep GlassSrf, double W)
{
Brep Frame = new Brep();
List<Curve> edges = GlassSrf.GetWireframe(-1).ToList(); //Edges.
Curve joinEdges = Curve.JoinCurves(edges)[0]; //Joined edges.
Curve offset = joinEdges.Offset(Plane.WorldXY, W, 0.01, CurveOffsetCornerStyle.Sharp)[0]; //Offset joined edges.
List<Curve> curves = new List<Curve>(); //list of curves.
curves.AddRange(edges);
curves.Add(offset);
Frame = Brep.CreatePlanarBreps(curves)[0]; //Create brep.
return Frame;
}

(Make the function to a single item, but when you enter more than one item, the script is executed once for each element). But first try changing the GH_ParamAccess.list on register input with the code you already have, and if it works, you can leave it. Feel free to ask whatever you want.

Magic... Works. Thanks a lot.

I changed all lists to items in main functions, inputs and outputs. No there are no for loops and they work.

I have question regarding syntax:

In this and similar lines, what does the [0] stand for?

Curve joinEdges = Curve.JoinCurves(edges)[0]

Also do you know any tutorials regarding C# and RhinoCommon?

Kind Regards,

Petras

Cool. Actually, I'm starting to learn C#, I know VB and like they are very similar, I take these consultations to learn to write in C, but no, I do not know tutorials about C# + RhinoCommon.

Curve.JoinCurves (edges) returns an array of curves, because you can join several curves and can not join all of them. But in this case we know that they are going to join, then we collect the first element (and the unique) of the array [0] to reduce statements. It would be like:

Curve() joinEdges = Curve.JoinCurves(edges);

Curve joinededge = joinEdges[0];

but in a one line :]

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service