///////////////////////////////////////////////////////////// // Use: Returns True if conical thread is expanding. // Works only for tapered threads. ///////////////////////////////////////////////////////////// public static bool IsExpanding( ThreadInfo threadInfo, Face threadedFace) { Point basePoint = threadInfo.ThreadBasePoints[1] as Point; Vector direction = threadInfo.ThreadDirection; Point endPoint = _Tg.CreatePoint( basePoint.X + direction.X, basePoint.Y + direction.Y, basePoint.Z + direction.Z); UnitVector yAxis = direction.AsUnitVector(); UnitVector xAxis = Toolkit.GetOrthoVector(yAxis); Line l1 = Toolkit.GetFaceSideDirection(threadedFace, xAxis); Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector()); Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector()); Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point; Point p2 = l1.IntersectWithCurve(l3, 0.0001)[1] as Point; double dBase = p1.DistanceTo(basePoint); double dEnd = p2.DistanceTo(endPoint); return(dBase < dEnd); }
///////////////////////////////////////////////////////////// // Use: Returns direction of the thread side as Line object. // ///////////////////////////////////////////////////////////// public static Line GetThreadSideDirection(ThreadInfo threadInfo, Face threadedFace) { Point RootPoint1 = threadInfo.ThreadBasePoints[1] as Point; Vector threadDirection = threadInfo.ThreadDirection; Point point = ThreadWorker._Tg.CreatePoint(RootPoint1.X + threadDirection.X, RootPoint1.Y + threadDirection.Y, RootPoint1.Z + threadDirection.Z); UnitVector orthoVector = Toolkit.GetOrthoVector(threadDirection.AsUnitVector()); Line faceSideDirection = Toolkit.GetFaceSideDirection(threadedFace, orthoVector); Line line1 = ThreadWorker._Tg.CreateLine(RootPoint1, orthoVector.AsVector()); Line line2 = ThreadWorker._Tg.CreateLine(point, orthoVector.AsVector()); Point RootPoint2 = faceSideDirection.IntersectWithCurve((object)line1, 0.0001)[1] as Point; Point Point = faceSideDirection.IntersectWithCurve((object)line2, 0.0001)[1] as Point; return(ThreadWorker._Tg.CreateLine(RootPoint2, RootPoint2.VectorTo(Point))); }
///////////////////////////////////////////////////////////// // Use: Returns thread major radius for tapered thread. // ///////////////////////////////////////////////////////////// private static double GetThreadMajorRadiusTapered( ThreadInfo threadInfo, Face threadedFace) { UnitVector yAxis = threadInfo.ThreadDirection.AsUnitVector(); UnitVector xAxis = Toolkit.GetOrthoVector(yAxis); Point basePoint = threadInfo.ThreadBasePoints[1] as Point; Line l1 = Toolkit.GetFaceSideDirection( threadedFace.Geometry, xAxis); Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector()); Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point; return(p1.DistanceTo(basePoint)); }
///////////////////////////////////////////////////////////// // Use: Modelizes a Standard ThreadFeature. // ///////////////////////////////////////////////////////////// public static bool ModelizeThreadStandard(PartDocument doc, PartFeature feature, PlanarSketch templateSketch, ThreadInfo threadInfo, Face threadedFace, double extraPitch) { Transaction Tx = _Application.TransactionManager.StartTransaction( doc as _Document, "Modelizing Thread " + feature.Name); try { double pitch = ThreadWorker.GetThreadPitch(threadInfo); Vector threadDirection = threadInfo.ThreadDirection; bool isInteriorFace = Toolkit.IsInteriorFace(threadedFace); Point basePoint = threadInfo.ThreadBasePoints[1] as Point; if (isInteriorFace) { Vector normal = Toolkit.GetOrthoVector( threadDirection.AsUnitVector()).AsVector(); normal.ScaleBy( ThreadWorker.GetThreadMajorRadiusStandard( threadedFace)); basePoint.TranslateBy(normal); } PlanarSketch newSketch = Toolkit.InsertSketch(doc, templateSketch, threadDirection.AsUnitVector(), Toolkit.GetOrthoVector( threadDirection.AsUnitVector()), basePoint); Point coilBase = threadInfo.ThreadBasePoints[1] as Point; bool rightHanded = threadInfo.RightHanded; double taper = 0; if (!ThreadWorker.InitializeForCoilStandard(doc, threadInfo, threadedFace, newSketch.Name, isInteriorFace, pitch)) { Tx.Abort(); return(false); } Profile profile = newSketch.Profiles.AddForSolid(true, null, null); if (!ThreadWorker.CreateCoilFeature(doc, profile, threadDirection, coilBase, rightHanded, taper, pitch, extraPitch)) { Tx.Abort(); return(false); } newSketch.Shared = false; feature.Suppressed = true; Tx.End(); return(true); } catch { Tx.Abort(); return(false); } }
///////////////////////////////////////////////////////////// // Use: Creates new solid bodies affected by the future // CoilFeature for Tapered Thread. ///////////////////////////////////////////////////////////// private static bool CreateCoilBodyTapered(PartDocument doc, ThreadInfo threadInfo, Face threadedFace, double depth, bool isInteriorFace) { try { PartComponentDefinition compDef = doc.ComponentDefinition; Vector direction = threadInfo.ThreadDirection; Point basePoint = threadInfo.ThreadBasePoints[1] as Point; Point endPoint = _Tg.CreatePoint( basePoint.X + direction.X, basePoint.Y + direction.Y, basePoint.Z + direction.Z); UnitVector yAxis = direction.AsUnitVector(); UnitVector xAxis = Toolkit.GetOrthoVector(yAxis); WorkPoint wpt = compDef.WorkPoints.AddFixed(basePoint, _ConstructionWorkFeature); WorkPlane wpl = compDef.WorkPlanes.AddFixed(basePoint, xAxis, yAxis, _ConstructionWorkFeature); WorkAxis xWa = compDef.WorkAxes.AddFixed(basePoint, xAxis, _ConstructionWorkFeature); WorkAxis yWa = compDef.WorkAxes.AddFixed(basePoint, yAxis, _ConstructionWorkFeature); PlanarSketch sketch = compDef.Sketches.AddWithOrientation(wpl, xWa, true, true, wpt, false); Cone cone = threadedFace.Geometry as Cone; double revDepth = depth / Math.Cos(cone.HalfAngle) * (isInteriorFace ? -1.0 : 1.0); Line l1 = Toolkit.GetFaceSideDirection(threadedFace, xAxis); Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector()); Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector()); Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point; Point p2 = l1.IntersectWithCurve(l3, 0.0001)[1] as Point; Point p3 = _Tg.CreatePoint( p2.X - xAxis.X * revDepth, p2.Y - xAxis.Y * revDepth, p2.Z - xAxis.Z * revDepth); Point p4 = _Tg.CreatePoint( p1.X - xAxis.X * revDepth, p1.Y - xAxis.Y * revDepth, p1.Z - xAxis.Z * revDepth); SketchPoint skp1 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p1), false); SketchPoint skp2 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p2), false); SketchPoint skp3 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p3), false); SketchPoint skp4 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p4), false); sketch.SketchLines.AddByTwoPoints(skp1, skp2); sketch.SketchLines.AddByTwoPoints(skp2, skp3); sketch.SketchLines.AddByTwoPoints(skp3, skp4); sketch.SketchLines.AddByTwoPoints(skp4, skp1); Profile profile = sketch.Profiles.AddForSolid(true, null, null); RevolveFeature rev1 = compDef.Features.RevolveFeatures.AddFull( profile, yWa, PartFeatureOperationEnum.kCutOperation); sketch = compDef.Sketches.AddWithOrientation(wpl, xWa, true, true, wpt, false); skp1 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p1), false); skp2 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p2), false); skp3 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p3), false); skp4 = sketch.SketchPoints.Add( sketch.ModelToSketchSpace(p4), false); sketch.SketchLines.AddByTwoPoints(skp1, skp2); sketch.SketchLines.AddByTwoPoints(skp2, skp3); sketch.SketchLines.AddByTwoPoints(skp3, skp4); sketch.SketchLines.AddByTwoPoints(skp4, skp1); profile = sketch.Profiles.AddForSolid(true, null, null); RevolveFeature rev2 = compDef.Features.RevolveFeatures.AddFull( profile, yWa, PartFeatureOperationEnum.kNewBodyOperation); return(true); } catch { return(false); } }