How to modify a model

Hi guys,

I use “Ext under Curve” to extend a curve. After extending the curve, I have found that the extended curve and the original curve are same. Basically the extended curve has replaced the original curve. This is the exactly function I want. How could I do this in my grasshopper componenet? I have a model. I want to write my own grasshopper component to modified the model and replace the original model.

Thank you very much.
Regards
John

Hello
you can use a method like this one
RhinoDoc.ActiveDoc.Objects.Replace(…

Hi Laurent Delrieu,

Thank you for your reply. Now how could I block the “recomputer” action? Basically, there should be no parameter feature in this case.

Regards
John

I am not sure to understand what is really the question.
What I can say is :
This type of tool leads to infinite recursion that must be stopped by a way or another. You can use a button and execute the transformation at each TRUE. Button is false by default.
You can (MUST) have a stop condition, you can keep somewhere in your tool the guid of transformed objects and do the transformation just one time

I have a tool like that in my Nautilus plugin it transform all the circles of a given domain radius to circles to another domain radius.
If domain from and domain to overlap no calculation are done.

Hi Laurent Delrieu,

Sorry, I am not that familiar with grasshopper in rhino. I learn it by doing. Thank you for your reply.

The scenario is like that.

  1. my component take a brep as input, the brep is actually a solid with many faces.
  2. I modify the brep via SDK operation, now I have a new brep.
  3. Now I need to find the guid of my input brep and then replace the brep in rhino with my new brep.

I think this way, it is actually a baking process in grasshopper term, so now my component lost the parametric feature. Is it right? In this case, then if user select “recomputer”, nothing will happens.

Now, my question is how to find RhinoObject guid from my input brep?

Regards
John

For my tool I use this Grasshopper Component

Or GH_xxx contains a referenceID

Technically the new content component would work too. Just change the geometry and data in the model object data type then send it down the wire with the same id:

The cache will handle the replace.

The new Grasshopper data types do have both geometry and Attributes. These attributes may contain an ID also.

RhinoObject has id and attributes, but Brep doesn’t have. So far I didn’t find the solution.

Can I get your current component? We will take a look.

Hi Scott Davidson,

Hope we are on the same page.
What I want now is to find the RhinoObject Id from input Brep inside my component.
Here is the codes I use:

        Brep brep = null;
        if (!DA.GetData(0, ref brep))
        {
            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Sheet base model!!");
            return;
        }

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

        // Iterate through all the objects in the document
        Guid select_object_id = Guid.Empty;
        bool found = false;
        foreach (RhinoObject obj in doc.Objects)
        {
            // Check if the object contains a Brep geometry
            if (obj.Geometry is Brep brep_inRhino)
			{
			     if(brep == brep_inRhino)
				 {
				 // sadly, it never comes to this point.
				 }
			}
		}

Regards
John

Hello
you don’t use the good type of object as input, it seems that all input objects are wrapped in a sort of container GH_xxx something so using that is sometime more effective (there is somewhere a discussion for fast treatment of points or curve using GH_point or GH_curve) . So you can surely use GH_Brep instead of brep and get the ID
Here in some of my code I use GH_Point
image.

It is a bit the same for datatree, it is better to use GH_structure than Datatree.

In rhino 8 using grasshopper component and content cache a lot of the replace and tracking is taken care of.

Using the Query objects component in Grasshopper the result in ModelObjects that include the ID. If there was a change made to the objects in the C# component . The they were run through a Content Cache the objects would update the exiting objects.

image

Using code is another thread on Replace and Rhino.Object vs Objref the @menno may be able to help:

In Python here is a thread on converting a Obj > RefObj > GH_ModelObject.

Thank you very much. I need time to digest all these stuffs and do my testing & coding.

Regards
John

I think the content cache will do what you want. If you do have questions regarding RhinoObject vs. ObjRef let me know.

Hi Menno Deij,

Thank you very much for your reply.

Do you have any docs or sample codes using content cache?

Regards
John

Here is how to find all the breps in the model and operate on them, then replace the objects back in Rhino:

What is the operation you would like to do on the objects?

The input to the C# component will be Model Objects that contain the attributes.

Here is a bit of a mind bender. Take the original object and run it thru a C# component and output the modified geometry. But run it then thru a Model Object Component and it will replace the geometry in the object, but keep the ID and Attributes from the Original. This way it is not so critical to hold on the ID within the C# component.

Hi Scott Davidson,

Thank you for your reply.

Slowly I think I know how I could build my own component.
What I want is the following simple scenario:
a. take a solid brep from user.
b. modify it based on the selected edge or face, now I have a brep as output of the component.
c. use the output brep and repeat the step b.

Now I have a solid model I want at the end. The issue I have now is that every instance of my grasshopper component will have its own solid brep. But I think I have to live with it, this is the nature of the grasshopper. The user should just bake the last instance of my component, he will get what he wants.

Hope it works.

Regards
John