Ejemplo n.º 1
0
        public List <IBody2> CreateBodies(ISldWorks app, bool temp)
        {
            var resBodies = new List <IBody2>();
            var modeler   = app.GetModeler() as Modeler;
            var mathUtil  = app.IGetMathUtility();

            double[] vectorN = new double[] { 1, 0, 0 };
            double[] pointN  = new double[] { 0, 0, 0 };
            if (helix == true)
            {
                for (int i = 0; i < 10; i++)
                {
                    double Xstart = sizeX * i;
                    resBodies.Add(modeler.CreateBodyFromBox3(new double[] { Xstart, 0d, 0d, 1d, 0d, 0d, sizeX, sizeY, sizeZ }));


                    double        Rotation = 36 * (i + 1);
                    var           vector   = mathUtil.CreateVector(vectorN);
                    var           point    = mathUtil.CreatePoint(pointN);
                    MathTransform rotation = (MathTransform)mathUtil.CreateTransformRotateAxis(point, vector, Rotation);
                    resBodies[i].ApplyTransform(rotation);
                }
                if (temp == true)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        resBodies[i].Display3(app.IActiveDoc2, 100, 1);
                    }
                }
                else
                {
                    for (int i = 0; i < 10; i++)
                    {
                        resBodies[i].CreateBaseFeature(resBodies[i]);
                    }
                }
            }
            else
            {
                resBodies.Add(modeler.CreateBodyFromBox3(new double[] { 0d, 0d, 0d, 1d, 0d, 0d, sizeX, sizeY, sizeZ }));
                if (temp == true)
                {
                    resBodies[0].Display3(app.IActiveDoc2, 100, 1);
                }
                else
                {
                    resBodies[0].CreateBaseFeature(resBodies[0]);
                }
            }
            return(resBodies);
        }
Ejemplo n.º 2
0
        public List <IBody2> CreateBodies(ISldWorks app, bool preview)

        {
            int errorCount = 0;

            var resBodies = new List <IBody2>();

            var modeler = app.GetModeler() as IModeler;

            List <IBody2> thinPanelBodies = new List <IBody2>();

            foreach (IFace2 face in PanelFaces)
            {
                thinPanelBodies.Add(face.ICreateSheetBody());
            }

            List <IBody2> thickBeamBodies = new List <IBody2>();

            foreach (IFace2 face in BeamFaces)
            {
                thickBeamBodies.Add(modeler.ThickenSheet(face.ICreateSheetBody(), BeamThickness / 2, (int)swThickenDirection_e.swThickenDirection_Both));
            }

            foreach (Body2 thinPanelBody in thinPanelBodies)
            {
                var perforatedPanel = default(Body2);

                if (!preview)
                {
                    perforatedPanel = thinPanelBody.ICopy();
                }

                foreach (Body2 thickBeamBody in thickBeamBodies)
                {
                    if (preview)
                    {
                        try
                        {
                            var thickPanelBody = modeler.ThickenSheet(thinPanelBody, PanelThickness / 2, (int)swThickenDirection_e.swThickenDirection_Both);

                            resBodies.Add(BodyOperation(thickPanelBody, thickBeamBody, swBodyOperationType_e.SWBODYINTERSECT));

                            //TODO Must Ask if I need to do this?
                            Marshal.ReleaseComObject(thickPanelBody);
                            thickPanelBody = null;
                        }

                        catch
                        {
                            errorCount++;
                        }
                    }
                    else
                    {
                        var thisPanelFaces = OffsetBothWays(thinPanelBody, PanelThickness / 2);

                        var thisHoleFaces = IntersectBothWays(thisPanelFaces, thickBeamBody);

                        var thisHoleBody = ThickenMerge(thisHoleFaces, PanelThickness);

                        if (thisHoleBody.GetFaceCount() > 6)
                        {
                            var faces = (thisHoleBody.GetFaces() as object[]).Cast <Face2>().ToList();
                            faces.Sort((x, y) => x.GetArea().CompareTo(y.GetArea()));
                            var smallFaces = faces.Take(thisHoleBody.GetFaceCount() - 6).ToArray();

                            thisHoleBody.DeleteFaces5(smallFaces,
                                                      (int)swHealActionType_e.swHealAction_GrowParent,
                                                      (int)swLoopProcessOption_e.swLoopProcess_Auto,
                                                      DoLocalCheck: true,
                                                      out object outBodies,
                                                      out bool localCheckResult);
                            // disabling checking didn't have any noticable speed improvements
                        }

                        var count = thisHoleBody.GetFaceCount();

                        perforatedPanel = BodyOperation(perforatedPanel, thisHoleBody, swBodyOperationType_e.SWBODYCUT);
                    }
                }

                if (!preview)
                {
                    resBodies.Add(perforatedPanel);
                }
            }

            return(resBodies);

            (Body2 normal, Body2 opposite) OffsetBothWays(IBody2 midBody, double distance)
            {
                return(midBody.MakeOffset(distance, false), midBody.MakeOffset(distance, true));
            }

            (Body2 normal, Body2 opposite) IntersectBothWays((Body2 normal, Body2 opposite) targets, Body2 tool)
            {
                return(BodyOperation(targets.normal, tool, swBodyOperationType_e.SWBODYINTERSECT),
                       BodyOperation(targets.opposite, tool, swBodyOperationType_e.SWBODYINTERSECT));
            }

            Body2 ThickenMerge((Body2 normal, Body2 opposite) faces, double distance)
            {
                return(BodyOperation(modeler.ThickenSheet(faces.normal, PanelThickness, (int)swThickenDirection_e.swThickenDirection_Side2),
                                     modeler.ThickenSheet(faces.opposite, PanelThickness, (int)swThickenDirection_e.swThickenDirection_Side1),
                                     swBodyOperationType_e.SWBODYADD));
            }
        }