Exemple #1
0
        /////////////////////////////////////////////////////////////
        // Use: Returns Thread Pitch as string using default units.
        //
        /////////////////////////////////////////////////////////////
        public static string GetThreadPitchStr(ThreadInfo threadInfo,
                                               Document doc)
        {
            double pitch = ThreadWorker.GetThreadPitch(threadInfo);

            UnitsOfMeasure uom = doc.UnitsOfMeasure;

            return(uom.GetStringFromValue(pitch,
                                          UnitsTypeEnum.kDefaultDisplayLengthUnits));
        }
Exemple #2
0
        /////////////////////////////////////////////////////////////
        // 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);
            }
        }
Exemple #3
0
        /////////////////////////////////////////////////////////////
        // Use: Modelizes a Tapered ThreadFeature.
        //
        /////////////////////////////////////////////////////////////
        public static bool ModelizeThreadTapered(PartDocument doc,
                                                 PartFeature feature,
                                                 PlanarSketch templateSketch,
                                                 ThreadInfo threadInfo,
                                                 Face threadedFace,
                                                 double extraPitch)
        {
            Transaction Tx =
                _Application.TransactionManager.StartGlobalTransaction(
                    doc as _Document,
                    "Modelizing Thread ");

            try
            {
                double pitch =
                    ThreadWorker.GetThreadPitch(threadInfo);

                Vector threadDirection =
                    threadInfo.ThreadDirection;

                Point coilBase =
                    threadInfo.ThreadBasePoints[1] as Point;

                bool isInteriorFace =
                    Toolkit.IsInteriorFace(threadedFace);

                Line sideDir =
                    ThreadWorker.GetThreadSideDirection(
                        threadInfo,
                        threadedFace);

                Vector sketchYAxis =
                    sideDir.RootPoint.VectorTo(coilBase);

                sketchYAxis.ScaleBy((isInteriorFace ? -1.0 : 1.0));

                PlanarSketch newSketch = Toolkit.InsertSketch(doc,
                                                              templateSketch,
                                                              sideDir.Direction,
                                                              sketchYAxis.AsUnitVector(),
                                                              sideDir.RootPoint);

                bool rightHanded = threadInfo.RightHanded;

                bool IsExpanding = ThreadWorker.IsExpanding(
                    threadInfo,
                    threadedFace);

                double taper =
                    Math.Abs(threadDirection.AngleTo(
                                 sideDir.Direction.AsVector()))
                    * (IsExpanding ? 1.0 : -1.0);

                if (!ThreadWorker.InitializeForCoilTapered(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
            {
                try
                {
                    Tx.Abort();
                    return(false);
                }
                catch
                {
                    return(false);
                }
            }
        }