Exemple #1
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 #2
0
        /////////////////////////////////////////////////////////////
        // Use: Initializes parameters to create new solid bodies
        //      affected by the future CoilFeature for Standard
        //      Thread.
        /////////////////////////////////////////////////////////////
        private static bool InitializeForCoilStandard(
            PartDocument doc,
            ThreadInfo threadInfo,
            Face threadedFace,
            string sketchName,
            bool isInteriorFace, double pitchValue)
        {
            Parameter pitch =
                Toolkit.FindAndUpdateParameter(doc,
                                               "Pitch",
                                               sketchName);

            if (pitch == null)
            {
                return(false);
            }

            Parameter offset =
                Toolkit.FindAndUpdateParameter(doc,
                                               "ThreadOffset",
                                               sketchName);

            if (offset == null)
            {
                return(false);
            }

            Parameter major =
                Toolkit.FindAndUpdateParameter(doc,
                                               "MajorRadius",
                                               sketchName);

            if (major == null)
            {
                return(false);
            }

            Parameter minor =
                Toolkit.FindAndUpdateParameter(doc,
                                               "MinorRadius",
                                               sketchName);

            if (minor == null)
            {
                return(false);
            }

            pitch.Value = pitchValue;

            offset.Value = 0;

            double majorRad =
                ThreadWorker.GetThreadMajorRadiusStandard(
                    threadedFace);

            //Modif
            major.Value = (isInteriorFace ? 0 : majorRad);

            doc.Update();

            double minorRad =
                (isInteriorFace ?
                 majorRad + Math.Abs((double)minor.Value) :
                 Math.Abs((double)minor.Value));

            if (isInteriorFace)
            {
                major.Value = (isInteriorFace ? Math.Abs((double)minor.Value) : majorRad);
                doc.Update();
            }

            bool ret = ThreadWorker.CreateCoilBodyStandard(doc,
                                                           threadInfo,
                                                           minorRad,
                                                           majorRad,
                                                           isInteriorFace);

            return(ret);
        }