Exemplo n.º 1
0
        public static void MyVisualOutput_ComposedPatterns(List <MyComposedPattern> listOfOutputComposedPattern,
                                                           List <MyComposedPattern> listOfOutputComposedPatternTwo, SldWorks mySwApplication, ModelDoc2 SwModel)
        {
            SwModel.ClearSelection2(true);
            //SwModel.Insert3DSketch();

            int      nOfPatterns = 0;
            var      tolerance   = Math.Pow(10, -4);
            MyVertex headCentroidPattern;
            MyVertex backCentroidPattern;

            foreach (var composedPattern in listOfOutputComposedPattern)
            {
                nOfPatterns         = composedPattern.listOfMyPattern.Count;
                headCentroidPattern = composedPattern.listOfMyPattern[0].patternCentroid;
                backCentroidPattern = composedPattern.listOfMyPattern[nOfPatterns - 1].patternCentroid;
                if (composedPattern.pathOfMyComposedPattern.GetType() == typeof(MyLine))
                {
                    SwModel.GetActiveSketch2();
                    SwModel.CreateLine2(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                        backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z);
                }
                else //typeof(MyCircumForPath)
                {
                    var pathObject   = (MyCircumForPath)composedPattern.pathOfMyComposedPattern;
                    var circumCenter = pathObject.circumcenter;
                    //SwModel.CreateArc2(pathObject.circumcenter.x, pathObject.circumcenter.y, pathObject.circumcenter.z,
                    //    headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                    //    backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z, -1);   //o +1?

                    if (
                        Math.Abs(headCentroidPattern.Distance(backCentroidPattern) -
                                 composedPattern.constStepOfMyComposedPattern) < tolerance)
                    {
                        //SwModel.ClearSelection2(true);
                        SwModel.Insert3DSketch();
                        SwModel.GetActiveSketch2();
                        SwModel.CreateCircle2(circumCenter.x, circumCenter.y, circumCenter.z,
                                              headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z);
                        //SwModel.InsertSketch();
                    }
                    else
                    {
                        //SwModel.ClearSelection2(true);
                        //SwModel.Insert3DSketch();
                        SwModel.GetActiveSketch2();
                        SwModel.Create3PointArc(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                                backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z,
                                                composedPattern.listOfMyPattern[1].patternCentroid.x,
                                                composedPattern.listOfMyPattern[1].patternCentroid.y,
                                                composedPattern.listOfMyPattern[1].patternCentroid.z);
                        //SwModel.InsertSketch();
                    }
                }
            }

            foreach (var composedPattern in listOfOutputComposedPatternTwo)
            {
                headCentroidPattern = composedPattern.listOfMyPattern[0].patternCentroid;
                backCentroidPattern = composedPattern.listOfMyPattern[1].patternCentroid;
                SwModel.GetActiveSketch2();
                SwModel.CreateLine2(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                    backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z);
            }
            SwModel.InsertSketch();

            #region esempio linea funzionante
            //ModelDoc2 SwModel = mySwApplication.ActiveDoc;
            //SwModel.ClearSelection2(true);
            //SwModel.Insert3DSketch();
            //SwModel.GetActiveSketch2();
            //SwModel.CreateLine2(0, 0, 0, 0, 0.1, 0.1);

            //SwModel.InsertSketch();
            #endregion
        }
Exemplo n.º 2
0
        //This function prints the detected COMPOSED patterns of components (lines and circles).
        public static void ShowAndPrintResults_Assembly_ComposedPatterns(
            List <MyComposedPatternOfComponents> listOfOutputComposedPattern,
            List <MyComposedPatternOfComponents> listOfOutputComposedPatternTwo, ModelDoc2 SwModel, SldWorks swApplication)
        {
            SwModel.ClearSelection2(true);
            SwModel.Insert3DSketch();

            int      nOfPatterns;
            var      tolerance = Math.Pow(10, -4);
            MyVertex headCentroidPattern;
            MyVertex backCentroidPattern;

            foreach (var composedPattern in listOfOutputComposedPattern)
            {
                nOfPatterns         = composedPattern.ListOfMyPatternOfComponents.Count;
                headCentroidPattern = composedPattern.ListOfMyPatternOfComponents[0].patternCentroid;
                backCentroidPattern = composedPattern.ListOfMyPatternOfComponents[nOfPatterns - 1].patternCentroid;
                if (composedPattern.pathOfMyComposedPatternOfComponents.GetType() == typeof(MyLine))
                {
                    SwModel.GetActiveSketch2();
                    SwModel.CreateLine2(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                        backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z);
                }
                else //typeof(MyCircumForPath)
                {
                    var pathObject   = (MyCircumForPath)composedPattern.pathOfMyComposedPatternOfComponents;
                    var circumCenter = pathObject.circumcenter;

                    if (
                        Math.Abs(headCentroidPattern.Distance(backCentroidPattern) -
                                 composedPattern.constStepOfMyComposedPatternOfComponents) < tolerance)
                    {
                        //SwModel.ClearSelection2(true);
                        //SwModel.Insert3DSketch();
                        SwModel.GetActiveSketch2();
                        SwModel.CreateCircle2(circumCenter.x, circumCenter.y, circumCenter.z,
                                              headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z);
                        //SwModel.InsertSketch();
                    }
                    else
                    {
                        //SwModel.ClearSelection2(true);
                        //SwModel.Insert3DSketch();
                        SwModel.GetActiveSketch2();
                        SwModel.Create3PointArc(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                                backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z,
                                                composedPattern.ListOfMyPatternOfComponents[1].patternCentroid.x,
                                                composedPattern.ListOfMyPatternOfComponents[1].patternCentroid.y,
                                                composedPattern.ListOfMyPatternOfComponents[1].patternCentroid.z);
                        //SwModel.InsertSketch();
                    }
                }
            }

            foreach (var composedPattern in listOfOutputComposedPatternTwo)
            {
                headCentroidPattern = composedPattern.ListOfMyPatternOfComponents[0].patternCentroid;
                backCentroidPattern = composedPattern.ListOfMyPatternOfComponents[1].patternCentroid;
                SwModel.CreateLine2(headCentroidPattern.x, headCentroidPattern.y, headCentroidPattern.z,
                                    backCentroidPattern.x, backCentroidPattern.y, backCentroidPattern.z);
            }
            SwModel.InsertSketch();
        }