_MoveFace in RhinoCommon

Hi there.

I would like to implement something similar to the _MoveFace under the Solid Tools tab in Grasshopper.
And I would like to illustrate it a bit more. I am seeking for a function that can take two arguments( a Vector3d and a double) to move the certain BrepFace along Vector3d’s direction and with the magnitude equals to the double input. After this function, all other BrepFaces should be changed accordingly as well.
I don’t need to user interact with RhinoActiveView, which means should not need to deal with the click or something related to delegates, I suppose.
I checked the Brep/BrepFace methods in RhinoCommon doc, but it’s a bit hard to know which one fit my request the most. Any suggestion will be helpful. Thanks.

2 Likes

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_TransformComponent.htm

1 Like

Thank you. I tried and it works. That’s exactly what I wanted.

List ci = new List();
ci.Add(x.Faces[0].ComponentIndex());
Transform moveDown = Transform.Translation(new Vector3d(0, y, 0));
x.TransformComponent(ci, moveDown, 0.0001, 0.1, true);
A = x;

1 Like

Hi, can you share the c# script please? I can not make it work


Transform Brep.Faces+.gh (17.3 KB)

hi @dfytz1 here is C# script to transform.Brep.Faces

    private void RunScript(
	Brep brep,
	List<int> index,
	List<Transform> transform,
	ref object a)
    {
      Component.NickName="Transform Brep.Faces+";Component.Name="Transform Brep.Faces+";
List<ComponentIndex> ci = new List<ComponentIndex>();
foreach (var i in index)
{
	var co=brep.Faces[i].ComponentIndex();
ci.Add(co);
}
foreach (var t in transform)
{
	brep.TransformComponent(ci, t, 0.0001, 0.1, true);
}
a = brep;
    }

and for Transform foreach(index)

  private void RunScript(
	Brep brep,
	List<int> index,
	List<Transform> transform,
	ref object a)
    {
      Component.NickName="Transform Brep.Faces+";Component.Name="Transform Brep.Faces+";
List<ComponentIndex> ci = new List<ComponentIndex>();
if(brep!=null && Component.Params.Input[1].VolatileDataCount!=0 && Component.Params.Input[2].VolatileDataCount!=0){
	int j=0;int k=0;
foreach (var i in index)
{j=Math.Min(k,transform.Count-1);
	var co=brep.Faces[i].ComponentIndex();
		 ci = new List<ComponentIndex>(){co};
	 brep.TransformComponent(ci, transform[j], 0.0001, 0.1, true);
	 k++;
//ci.Add(co);
}
a = brep;}

    }

Tranform Brep.face ver2.gh (18.2 KB)

2 Likes

Thank you a lot! Will try this out

That is perfect. Thank you so much it made my life so much easier. I am sure this will help a lot of people in the future.

1 Like