I check a face in my brepbody and it is detected as cylinder, after I translate the cylindrical surface, it
return face.IsCylinder as false why?
same here…
RhinoDoc activeDoc = RhinoDoc.ActiveDoc;
IEnumerable<RhinoObject> brepObjects = activeDoc.Objects.GetObjectList(ObjectType.Brep);
RhinoObject object1 = brepObjects.ElementAt(0);
bool hasBrepForm = object1.Geometry.HasBrepForm;
if (hasBrepForm)
{
Brep brepBody = Brep.TryConvertBrep(object1.Geometry);
brepBody.MakeDeformable();
BrepFace face1 = brepBody.Faces.ElementAt(2);
ComponentIndex index = face1.ComponentIndex();
IEnumerable<ComponentIndex> componentIndices = new List<ComponentIndex> { index };
BrepEdge edge1 = Get_edge(brepBody, face1);
Cylinder cylinder;
Plane plane;
face1.TryGetCylinder(out cylinder);
bool Isplane = face1.TryGetPlane(out plane);
Transform transform;
if (face1.IsCylinder())
{
Vector3d vector = cylinder.BasePlane.Normal;
Plane plane1 = cylinder.BasePlane;
double tolerance = 0;
double timeLimit = 0.0;
bool useMultipleThreads = false;
double scalefactor = 2;
Point3d point = cylinder.Center;
transform = Transform.Scale(plane1, scalefactor, scalefactor, 1);
//transform = Transform.Translation(20, 20, 1);
brepBody.TransformComponent(componentIndices, transform, tolerance, timeLimit, useMultipleThreads);
activeDoc.Views.Redraw();
object1.CommitChanges();
}
else if (Isplane)
{
double tolerance = activeDoc.ModelAbsoluteTolerance;
double timeLimit = 10.0;
bool useMultipleThreads = true;
//Transform transform = Transform.Translation(0, -10, 0);
//brepBody.TransformComponent(componentIndices, transform, tolerance, timeLimit, useMultipleThreads);
activeDoc.Views.Redraw();
object1.CommitChanges();
}
//Pickup an outer surface
}
else
{
A = "its not a brep body";
}
Here is the code to select a surface and if found cylindrical scale its diameter. When run first time though a script tag in grasshopper it increases the dia but when run again it dosent do the change thereafter if the same cylinderical surface is to be scaled.
Hi @Rushank,
This seems to work with your model:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var go = new GetObject
{
GeometryFilter = ObjectType.Surface,
GeometryAttributeFilter = GeometryAttributeFilter.SubSurface
};
go.SetCommandPrompt("Select cylindrical face");
go.Get();
if (go.CommandResult() != Result.Success)
return go.CommandResult();
var brepFace = go.Object(0).Face();
if (null == brepFace)
return Result.Failure;
var tol = doc.ModelAbsoluteTolerance;
var rc = brepFace.IsCylinder(tol);
if (rc)
{
RhinoApp.WriteLine("IsCylinder = {0}", rc);
rc = brepFace.TryGetFiniteCylinder(out var cylinder, tol);
if (rc)
{
var brep = Brep.CreateFromCylinder(cylinder, false, false);
if (null != brep)
{
var id = doc.Objects.AddBrep(brep);
var rhObj = doc.Objects.Find(id);
rhObj?.Select(true);
}
}
}
doc.Views.Redraw();
return Result.Success;
}
– Dale
Thanks Dale