public void Main() { PartDoc part = swApp.ActiveDoc as PartDoc; if (part != null) { IFace2 face = (part as IModelDoc2).ISelectionManager.GetSelectedObject6(1, -1) as IFace2; if (face != null && face.IGetSurface().IsSphere()) { double[] sphereParams = face.IGetSurface().SphereParams as double[]; IModeler modeler = swApp.IGetModeler(); ISurface sphereSurf = modeler.CreateSphericalSurface2( new double[] { sphereParams[0], sphereParams[1], sphereParams[2] }, new double[] { 0, 0, 1 }, new double[] { 1, 0, 0 }, sphereParams[3]) as ISurface; m_PreviewBody = sphereSurf.CreateTrimmedSheet4(new ICurve[] { null }, true) as IBody2; m_PreviewBody.Display3(part, ToColorRef(255, 255, 0), (int)swTempBodySelectOptions_e.swTempBodySelectOptionNone); part.ClearSelectionsNotify += new DPartDocEvents_ClearSelectionsNotifyEventHandler(OnClearSelections); } else { swApp.SendMsgToUser("Please select spherical surface"); } } else { swApp.SendMsgToUser("Please open part document"); } }
private bool IsHole(IFace2 face) { ISurface surf = face.IGetSurface(); if (surf.IsCylinder()) { double[] uvBounds = face.GetUVBounds() as double[]; double[] evalData = surf.Evaluate((uvBounds[1] - uvBounds[0]) / 2, (uvBounds[3] - uvBounds[2]) / 2, 1, 1) as double[]; double[] pt = new double[] { evalData[0], evalData[1], evalData[2] }; int sense = face.FaceInSurfaceSense() ? 1 : -1; double[] norm = new double[] { evalData[evalData.Length - 3] * sense, evalData[evalData.Length - 2] * sense, evalData[evalData.Length - 1] * sense }; double[] cylParams = surf.CylinderParams as double[]; double[] orig = new double[] { cylParams[0], cylParams[1], cylParams[2] }; double[] dir = new double[] { pt[0] - orig[0], pt[1] - orig[1], pt[2] - orig[2] }; IMathUtility mathUtils = swApp.IGetMathUtility(); IMathVector dirVec = mathUtils.CreateVector(dir) as IMathVector; IMathVector normVec = mathUtils.CreateVector(norm) as IMathVector; return(GetAngle(dirVec, normVec) < Math.PI / 2); } else { throw new NotSupportedException("Only cylindrical face is supported"); } }
private static ICurve[] SplitFaceOnIsoCurves(IFace2 face, int curvesCount, bool vOrU) { var curves = new List <ICurve>(); var surf = face.IGetSurface(); var uvBounds = face.GetUVBounds() as double[]; var minU = uvBounds[0]; var maxU = uvBounds[1]; var minV = uvBounds[2]; var maxV = uvBounds[3]; double thisMin; double thisMax; double otherMin; double otherMax; if (vOrU) //if v param { thisMin = minV; thisMax = maxV; otherMin = minU; otherMax = maxU; } else //if u param { thisMin = minU; thisMax = maxU; otherMin = minV; otherMax = maxV; } var step = (thisMax - thisMin) / (curvesCount - 1); for (int i = 1; i < curvesCount - 1; i++) { var par = thisMin + i * step; var curve = surf.MakeIsoCurve2(vOrU, ref par); double u; double v; if (vOrU) { u = otherMin; v = par; } else { u = par; v = otherMin; } var pt = surf.Evaluate(u, v, 0, 0) as double[]; var startPt = new double[] { pt[0], pt[1], pt[2] }; if (vOrU) { u = otherMax; v = par; } else { u = par; v = otherMax; } pt = surf.Evaluate(u, v, 0, 0) as double[]; var endPt = new double[] { pt[0], pt[1], pt[2] }; curve = curve.CreateTrimmedCurve2(startPt[0], startPt[1], startPt[2], endPt[0], endPt[1], endPt[2]); curves.Add(curve); } return(curves.ToArray()); }
public static bool IsPlanarFace(this IFace2 face) { return(face.IGetSurface().IsPlane()); }