コード例 #1
0
        public void dimConstr()
        {
            SketchArc           arc = ent as SketchArc;
            SketchLine          sl  = ps.SketchLines.AddByTwoPoints(arc.EndSketchPoint, arc.CenterSketchPoint); sl.Construction = true;
            SketchLine          sl1 = ps.SketchLines.AddByTwoPoints(arc.StartSketchPoint, arc.CenterSketchPoint); sl1.Construction = true;
            RadiusDimConstraint r   = constraints.addRadius(ent, sl.StartSketchPoint, sl1.StartSketchPoint, name);

            constraints.addTwoLineAngle(sl, sl1, arc.CenterSketchPoint, name);
            r.TextPoint = u.midPt(sl.StartSketchPoint.Geometry, sl.EndSketchPoint.Geometry, 0.4);
        }
コード例 #2
0
        public void constr(Entity prev)
        {
            SketchArc arc = ent as SketchArc;

            if (prev.ent.Type != ObjectTypeEnum.kSketchLineObject)
            {
                return;
            }
            if (con.HasFlag(cType.t))
            {
                constraints.addTangent(prev.ent, arc as SketchEntity);
            }
        }
コード例 #3
0
 public ArcInv(SketchArc arc)
     : base(entTypes.Arc)
 {
     R   = arc.Radius * 10;
     ang = arc.SweepAngle / Math.PI * 180;
     checkArc(arc.Geometry);
     if (arc.Constraints.OfType <TangentSketchConstraint>().FirstOrDefault() != null)
     {
         con = cType.t;
     }
     else
     {
         x   = arc.CenterSketchPoint.Geometry.X; y = arc.CenterSketchPoint.Geometry.Y;
         cen = u.createPoint2d(x, y);
     }
 }
コード例 #4
0
        // Arc
        public void exportArc(SketchArc arc, String varname)
        {
            double centerX = arc.CenterSketchPoint.Geometry.X;
            double centerY = arc.CenterSketchPoint.Geometry.Y;

            double radius = arc.Radius;

            using (StreamWriter outputFile = new StreamWriter(jscadPath, true))
            {
                outputFile.WriteLine("var " + varname + "= CSG.Path2D.arc({");
                outputFile.WriteLine("center: [" + convertCommaToDot(centerX) + "," + convertCommaToDot(centerY) + ",0],");
                outputFile.WriteLine("radius: " + convertCommaToDot(radius) + ",");
                outputFile.WriteLine("startangle: 0,");
                outputFile.WriteLine("endangle: 180");
                outputFile.WriteLine("}).close().innerToCAG();");
            }
        }
コード例 #5
0
        public override void draw()
        {
            sp = null; UnitVector2d v = null; double sAng = 0;
            if (prev.ent.Type == ObjectTypeEnum.kSketchPointObject)
            {
                sp = prev.ent as SketchPoint;
            }
            else if (prev.ent.Type == ObjectTypeEnum.kSketchLineObject)
            {
                sl = prev.ent as SketchLine;
                setCenter();
                if (cen == null)
                {
                    setCenter(sl);
                }
                sp   = sl.EndSketchPoint;
                v    = sl.Geometry.Direction;
                sAng = v.AngleTo(u.createUnitVector2d(1, 0));
            }
            //SketchArc arc = ps.SketchArcs.AddByCenterStartSweepAngle(cen, R, sAng, -ang);
            //constraints.addConsid(arc.StartSketchPoint as SketchEntity, sl.EndSketchPoint as SketchEntity);
            if (ang < 0)
            {
                clockwise = false;
            }
            if (ang < 0)
            {
                sAng = sAng - Math.PI;
            }
            SketchArc arc = ps.SketchArcs.AddByThreePoints(sp, pointToArc(x, y, sp.Geometry, ang / 2 + sAng), pointToArc(x, y, sp.Geometry, ang + sAng));

            //SketchArc arc = ps.SketchArcs.AddByCenterStartEndPoint(cen, sp, pointToArc(x, y, sp.Geometry, ang + sAng), clockwise);
            if (ang > 0)
            {
                startPt = arc.StartSketchPoint; endPt = arc.EndSketchPoint;
            }
            else
            {
                startPt = arc.EndSketchPoint; endPt = arc.StartSketchPoint;
            }
            ent = (SketchEntity)arc;
            constr(prev);
            dimConstr();
        }
コード例 #6
0
        public PlanarSketch Separator(double direction)
        {
            PlanarSketch sketch       = partCompDef.Sketches.Add(partCompDef.WorkPlanes[3]);
            SketchPoints points_      = sketch.SketchPoints;
            SketchArcs   arcs_        = sketch.SketchArcs;
            SketchLines  lines_       = sketch.SketchLines;
            Point2d      center_point = transGeom.CreatePoint2d(Dw / 2 * direction, (D / 2 - d / 2) / 2 + d / 2);
            SketchPoint  points       = sketch.SketchPoints.Add(transGeom.CreatePoint2d(Dw * direction, (D / 2 - d / 2) / 2 + d / 2));
            SketchPoint  points2      = sketch.SketchPoints.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2));

            center_line = sketch.SketchLines.AddByTwoPoints(points, points2);
            SketchArc      arc      = sketch.SketchArcs.AddByCenterStartEndPoint(center_point, points, points2, true);
            RevolveFeature revolve1 = Create_Revolve(sketch, PartFeatureOperationEnum.kNewBodyOperation);

            Create_Circular_Array(revolve1);
            sketch  = partCompDef.Sketches.Add(partCompDef.WorkPlanes[3]);
            points_ = sketch.SketchPoints;
            lines_  = sketch.SketchLines;
            points_.Add(transGeom.CreatePoint2d((Dw / 2 + 0.25) * direction, (D / 2 - d / 2) / 2 + d / 2 + 0.15));
            points_.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2 + 0.3));
            points_.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2 - 0.15));
            points_.Add(transGeom.CreatePoint2d(Dw / 2 * direction, (D / 2 - d / 2) / 2 + d / 2 - 0.1));
            for (int i = 1; i < 4; i++)
            {
                lines_.AddByTwoPoints(points_[i], points_[i + 1]);
            }
            ObjectCollection obj_collection = InventorApplication.TransientObjects.CreateObjectCollection();

            obj_collection.Add(sketch.SketchEntities[5]);
            obj_collection.Add(sketch.SketchEntities[6]);
            obj_collection.Add(sketch.SketchEntities[7]);
            sketch.OffsetSketchEntitiesUsingDistance(obj_collection, 0.1 * direction, false);
            lines_.AddByTwoPoints(sketch.SketchLines[1].StartSketchPoint, sketch.SketchLines[4].StartSketchPoint);
            lines_.AddByTwoPoints(sketch.SketchLines[3].EndSketchPoint, sketch.SketchLines[6].EndSketchPoint);
            center_line = sketch.SketchLines.AddByTwoPoints(transGeom.CreatePoint2d(-1, 0), transGeom.CreatePoint2d(1, 0));
            RevolveFeature revolve2 = Create_Revolve(sketch, PartFeatureOperationEnum.kNewBodyOperation);

            obj_collection = InventorApplication.TransientObjects.CreateObjectCollection();
            obj_collection.Add(revolve1.SurfaceBodies[1]);
            CombineFeature combine = partCompDef.Features.CombineFeatures.Add(revolve2.SurfaceBodies[1], obj_collection, PartFeatureOperationEnum.kCutOperation);

            return(sketch);
        }
コード例 #7
0
        //Скетч шариков
        public PlanarSketch BallsRow2()
        {
            PlanarSketch sketch  = partCompDef.Sketches.Add(partCompDef.WorkPlanes[3]);
            SketchPoints points_ = sketch.SketchPoints;

            points_.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2 + Dw / 2));
            points_.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2));
            points_.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2 - Dw / 2));
            SketchArcs arcs_ = sketch.SketchArcs;

            arcs_.AddByCenterStartEndPoint(points_[2], points_[1], points_[3], true);
            Point2d     center_point = transGeom.CreatePoint2d(-Dw / 2, (D / 2 - d / 2) / 2 + d / 2);
            SketchPoint points       = sketch.SketchPoints.Add(transGeom.CreatePoint2d(arcs_[1].Radius - Dw / 2, (D / 2 - d / 2) / 2 + d / 2));
            SketchPoint points2      = sketch.SketchPoints.Add(transGeom.CreatePoint2d(-arcs_[1].Radius - Dw / 2, (D / 2 - d / 2) / 2 + d / 2));

            center_line = sketch.SketchLines.AddByTwoPoints(points, points2);
            SketchArc arc = sketch.SketchArcs.AddByCenterStartEndPoint(center_point, points, points2, true);

            return(sketch);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: ferdiansyahz/Archie_
        private void Feature4(int x, int y)
        {
            try
            {
                PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument;
                oPartDoc.UnitsOfMeasure.LengthUnits = Inventor.UnitsTypeEnum.kMillimeterLengthUnits;
                PartComponentDefinition oCompDef = default(PartComponentDefinition);
                oCompDef = oPartDoc.ComponentDefinition;
                //Inventor.Point2d point1 = _invApp.TransientGeometry.CreatePoint2d(6, 13.8);
                //Inventor.Point2d point2 = _invApp.TransientGeometry.CreatePoint2d(-6, 13.8);
                PlanarSketch oSketch = default(PlanarSketch);
                oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]);
                SketchArc arc1 = oSketch.SketchArcs.AddByThreePoints(_invApp.TransientGeometry.CreatePoint2d(5.879, 13.8), _invApp.TransientGeometry.CreatePoint2d(0, 15), _invApp.TransientGeometry.CreatePoint2d(-5.879, 13.8));
                SketchArc arc2 = oSketch.SketchArcs.AddByThreePoints(arc1.StartSketchPoint, _invApp.TransientGeometry.CreatePoint2d(0, 9), arc1.EndSketchPoint);
                //oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), 15);
                //oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 15), 6);

                Profile oProfile = default(Profile);
                oProfile = oSketch.Profiles.AddForSolid();
                //oProfile = oSketch.Profiles.AddForSurface(arc2);

                ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition);
                oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kCutOperation);
                oExtrudeDef.SetDistanceExtent(3, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

                ExtrudeFeature oExtrude = default(ExtrudeFeature);
                oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef);
            }
            catch
            {
                try
                {
                    Feature3(x, y);
                }
                catch
                {
                    Feature2(x, y);
                }
            }
        }
コード例 #9
0
        //SketchPoint get_line(int index, string point)
        //{
        //    SketchLine element = (SketchLine)Segments[index];
        //    if (point == "a" || point == "A") return element.GetStartPoint2();
        //    if (point == "b" || point == "B") return element.GetEndPoint2();
        //    return null;
        //}
        //SketchPoint get_arc(int index, string point)
        //{
        //    SketchArc element = (SketchArc)Segments[index];
        //    if (point == "a" || point == "A") return element.GetStartPoint2();
        //    if (point == "b" || point == "B") return element.GetEndPoint2();
        //    if (point == "c" || point == "C") return element.GetCenterPoint2();
        //    return null;
        //}
        SketchPoint get(int index, string point)
        {
            if (index < 0)
            {
                index = (iSegments - 1) - abs(index);
            }

            SketchSegment segment = Segments[index];

            if (segment.GetType() == (int)swSketchSegments_e.swSketchARC)
            {
                SketchArc element = (SketchArc)segment;
                if (point == "a" || point == "A")
                {
                    return(element.GetStartPoint2());
                }
                if (point == "b" || point == "B")
                {
                    return(element.GetEndPoint2());
                }
                if (point == "c" || point == "C")
                {
                    return(element.GetCenterPoint2());
                }
            }
            if (segment.GetType() == (int)swSketchSegments_e.swSketchLINE)
            {
                SketchLine element = (SketchLine)segment;
                if (point == "a" || point == "A")
                {
                    return(element.GetStartPoint2());
                }
                if (point == "b" || point == "B")
                {
                    return(element.GetEndPoint2());
                }
            }
            return(null);
        }
コード例 #10
0
ファイル: Exporter.cs プロジェクト: medizinmensch/mMod
        // Arc (finished)
        public static string ExportArc(SketchArc arc, string entityName)
        {
            double centerX = Math.Round(arc.CenterSketchPoint.Geometry.X, 4) * factor;
            double centerY = Math.Round(arc.CenterSketchPoint.Geometry.Y, 4) * factor;

            double radius = Math.Round(arc.Radius, 4) * factor;

            double startAngle = Math.Round(arc.StartAngle * (180 / Math.PI), 4);
            double sweepAngle = Math.Round(arc.SweepAngle * (180 / Math.PI), 4);

            string nameCenterX    = entityName + "_CenterX";
            string nameCenterY    = entityName + "_CenterY";
            string nameRadius     = entityName + "_Radius";
            string nameStartAngle = entityName + "_StartAngle";
            string nameSweepAngle = entityName + "_SweepAngle";

            Parameter param1 = new Parameter(nameCenterX, "Center X of " + entityName, "float",
                                             centerX, 0.1);
            Parameter param2 = new Parameter(nameCenterY, "Center Y of " + entityName, "float",
                                             centerY, 0.1);
            Parameter param3 = new Parameter(nameRadius, "Radius of " + entityName, "float",
                                             radius, 0.1);

            //Parameter param4 = new Parameter(nameStartAngle, "Start angle of " + entityName, "float",startAngle, 1);
            //Parameter param5 = new Parameter(nameSweepAngle, "Sweep angle of " + entityName, "float",sweepAngle, 1);

            Shakespeare.ListOfParameter.Add(param1);
            Shakespeare.ListOfParameter.Add(param2);
            Shakespeare.ListOfParameter.Add(param3);
            //Shakespeare.ListOfParameter.Add(param4);
            //Shakespeare.ListOfParameter.Add(param5);

            string javaScriptVariable = "var " + entityName + " = CSG.Path2D.arc({center: [params." + nameCenterX +
                                        ", params." + nameCenterY + ",0], radius: params." + nameRadius +
                                        ", startangle: " + startAngle.ToString(myCultureInfo) + ",  endangle: " + sweepAngle.ToString(myCultureInfo) + "}).close().innerToCAG();";

            return("\t" + javaScriptVariable);
        }
コード例 #11
0
        public void getLoop()                            //获取一个草图中所有最小环
        {
            for (int i = 0; i < pois.Count; i++)         //以下主要为Dijkstra算法,基于上面存储边与点的基础上,故以下不加以算法注释
            {
                if (pois[i].nextSegs.Count < 2)
                {
                    continue;
                }
                for (int j = 0; j < pois[i].nextSegs.Count; j++)
                {
                    List <int> temLoop = new List <int>();
                    int[]      path    = new int[pois.Count];
                    int[]      dis     = new int[pois.Count];
                    int[]      visited = new int[pois.Count];
                    for (int k = 0; k < pois.Count; k++)
                    {
                        path[k]    = -1;
                        visited[k] = 0;
                        if (adj[i, k] != INF)
                        {
                            dis[k] = adj[i, k];
                        }
                        else
                        {
                            dis[k] = INF;
                        }
                    }
                    visited[i] = 1;

                    /*
                     * adj[i, pois[i].next[j]] = INF;
                     * adj[pois[i].next[j], i] = INF;
                     * dis[pois[i].next[j]] = INF;
                     */
                    int tem_count = 0;
                    for (int k = 0; k < pois[i].next.Count; k++)
                    {
                        if (pois[i].next[k] == pois[i].next[j])
                        {
                            tem_count++;
                        }
                    }
                    if (tem_count < 2)
                    {
                        adj[i, pois[i].next[j]] = INF;
                        adj[pois[i].next[j], i] = INF;
                        dis[pois[i].next[j]]    = INF;
                    }

                    int minIndex = -1;
                    for (int k = 1; k < pois.Count; k++)
                    {
                        int min = INF;
                        for (int m = 0; m < pois.Count; m++)
                        {
                            if (visited[m] != 1 && dis[m] < min)
                            {
                                min      = dis[m];
                                minIndex = m;
                            }
                        }
                        if (minIndex == -1)
                        {
                            break;
                        }
                        if (k == 1)
                        {
                            path[minIndex] = i;
                        }
                        visited[minIndex] = 1;
                        for (int m = 0; m < pois.Count; m++)
                        {
                            if (dis[m] > adj[minIndex, m] + min && visited[m] != 1)
                            {
                                dis[m]  = adj[minIndex, m] + min;
                                path[m] = minIndex;
                            }
                        }
                    }
                    adj[i, pois[i].next[j]] = 1;
                    adj[pois[i].next[j], i] = 1;

                    /*
                     * Debug.Print("Path:" + i);
                     * for(int k = 0; k < path.Length; k++)
                     * {
                     *  Debug.Print("==>" + path[k]);
                     * }
                     */

                    int  next = path[pois[i].next[j]];
                    int  last = pois[i].next[j];
                    bool flag = false;
                    while (next != i)
                    {
                        if (next == -1)
                        {
                            flag = true;
                            break;
                        }
                        for (int k = 0; k < loopSegs.Count; k++)
                        {
                            if ((loopSegs[k].end == next && loopSegs[k].start == last) || (loopSegs[k].end == last && loopSegs[k].start == next))
                            {
                                temLoop.Add(k);
                            }
                        }
                        last = next;
                        next = path[next];
                    }
                    if (flag)
                    {
                        break;
                    }
                    for (int k = 0; k < loopSegs.Count; k++)
                    {
                        if ((loopSegs[k].end == last && loopSegs[k].start == next) || (loopSegs[k].end == next && loopSegs[k].start == last))
                        {
                            temLoop.Add(k);
                        }
                    }
                    for (int k = 0; k < loopSegs.Count; k++)
                    {
                        if ((loopSegs[k].end == i && loopSegs[k].start == pois[i].next[j]) || (loopSegs[k].end == pois[i].next[j] && loopSegs[k].start == i))
                        {
                            temLoop.Add(k);
                        }
                    }

                    if (loopCheck(temLoop))
                    {
                        loops.Add(temLoop);
                    }
                }
            }

            for (int i = 0; i < loopSegs.Count; i++)
            {
                if (loopSegs[i].seg.GetType() == 1)
                {
                    SketchArc temArc = (SketchArc)loopSegs[i].seg;
                    if (temArc.GetStartPoint2() == temArc.IGetEndPoint2())
                    {
                        List <int> tem = new List <int>();
                        tem.Add(i);
                        loops.Add(tem);
                    }
                }
            }
        }
コード例 #12
0
        public static void addProjectCut(PartDocument oDoc, WorkPlane oWpReference, bool manual = false)
        {
            SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oDoc.ComponentDefinition;

            WorkPlane oWpWork = oCompDef.WorkPlanes.AddByPlaneAndOffset(oWpReference, 0);

            oWpWork.Name    = "wpWork";
            oWpWork.Visible = false;

            PlanarSketch oSketch     = oCompDef.Sketches.Add(oWpWork);
            ProjectedCut oProjectCut = oSketch.ProjectedCuts.Add();

            if (!manual)
            {
                int tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities);

                int    loop   = 0;
                double offset = 1;
                while (tmpSegmThk != 2)
                {
                    // Devo spostare il piano se ci sono cose nel mezzo
                    oWpWork.SetByPlaneAndOffset(oWpReference, offset);

                    tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities);
                    loop++;

                    offset += offset;

                    if (loop == 20)
                    {
                        throw new Exception("Numero massimo offset piano.");
                    }
                }

                oProjectCut.Delete();

                oProjectCut = oSketch.ProjectedCuts.Add();
            }

            List <ObjectCollection> dataLine = splittoLinea(oProjectCut.SketchEntities);

            ObjectCollection linea = lengthPerimetro();

            TransientGeometry oTransGeom     = iApp.TransientGeometry;
            UnitVector        oNormalVector  = oSketch.PlanarEntityGeometry.Normal;
            UnitVector2d      oLineDir       = linea[1].Geometry.Direction;
            UnitVector        oLineVector    = (UnitVector)oTransGeom.CreateUnitVector(oLineDir.X, oLineDir.Y, 0);
            UnitVector        oOffsetVector  = (UnitVector)oLineVector.CrossProduct(oNormalVector);
            UnitVector        oDesiredVector = (UnitVector)oTransGeom.CreateUnitVector(0, 1, 0);

            bool bNaturalOffsetDir;

            if (oOffsetVector.IsEqualTo(oDesiredVector))
            {
                bNaturalOffsetDir = true;
            }
            else
            {
                bNaturalOffsetDir = false;
            }

            SketchEntitiesEnumerator oSSketchEntitiesEnum = oSketch.OffsetSketchEntitiesUsingDistance(linea, 0.5, bNaturalOffsetDir, false);

            oProjectCut.Delete();

            styleSketch(oSketch.SketchEntities);

            int countThicknessSegment(SketchEntitiesEnumerator oSketchEntities)
            {
                int result = 0;

                foreach (SketchEntity e in oSketchEntities)
                {
                    if (e.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine oSketchLine = (SketchLine)e;

                        double length = Math.Round(oSketchLine.Length * 100) / 100;

                        if (length == Math.Round(oCompDef.Thickness.Value * 100) / 100)
                        {
                            result++;
                        }
                    }
                }

                return(result);
            }

            List <ObjectCollection> splittoLinea(SketchEntitiesEnumerator oSketchEntities)
            {
                List <ObjectCollection> tmp = new List <ObjectCollection>();

                tmp.Add(iApp.TransientObjects.CreateObjectCollection());
                tmp.Add(iApp.TransientObjects.CreateObjectCollection());
                tmp.Add(iApp.TransientObjects.CreateObjectCollection());

                int indice = 0;

                foreach (SketchEntity oSketchEntity in oSketchEntities)
                {
                    if (oSketchEntity.Type != ObjectTypeEnum.kSketchPointObject)
                    {
                        if (oSketchEntity.Type == ObjectTypeEnum.kSketchLineObject)
                        {
                            SketchLine oSketchLine = (SketchLine)oSketchEntity;

                            if (Math.Round(oSketchLine.Length * 100) / 100 == Math.Round(oCompDef.Thickness.Value * 100) / 100)
                            {
                                if (indice == 0)
                                {
                                    indice = 1;
                                }
                                else
                                {
                                    indice = 2;
                                }
                            }
                            else
                            {
                                tmp[indice].Add(oSketchEntity);
                            }
                        }

                        if (oSketchEntity.Type == ObjectTypeEnum.kSketchArcObject)
                        {
                            tmp[indice].Add(oSketchEntity);
                        }
                    }
                }

                foreach (SketchEntity oSketchEntity in tmp[0])
                {
                    tmp[2].Add(oSketchEntity);
                }

                List <ObjectCollection> result = new List <ObjectCollection>();

                result.Add(tmp[1]);
                result.Add(tmp[2]);

                return(result);
            }

            void styleSketch(SketchEntitiesEnumerator oSketchEntities)
            {
                foreach (SketchEntity oSe in oSketchEntities)
                {
                    if (oSe.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine se = (SketchLine)oSe;

                        se.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255);
                        se.LineType      = LineTypeEnum.kDashDottedLineType;
                    }
                    else if (oSe.Type == ObjectTypeEnum.kSketchArcObject)
                    {
                        SketchArc sa = (SketchArc)oSe;

                        sa.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255);
                        sa.LineType      = LineTypeEnum.kDashDottedLineType;
                    }
                }
            }

            ObjectCollection lengthPerimetro()
            {
                double l0 = 0;
                double l1 = 0;

                foreach (SketchEntity oSE in dataLine[0])
                {
                    if (oSE.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine se = (SketchLine)oSE;

                        l0 = l0 + se.Length;
                    }
                    else if (oSE.Type == ObjectTypeEnum.kSketchArcObject)
                    {
                        SketchArc se = (SketchArc)oSE;

                        l0 = l0 + se.Length;
                    }
                }
                foreach (SketchEntity oSE in dataLine[1])
                {
                    if (oSE.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine se = (SketchLine)oSE;

                        l1 = l1 + se.Length;
                    }
                    else if (oSE.Type == ObjectTypeEnum.kSketchArcObject)
                    {
                        SketchArc se = (SketchArc)oSE;

                        l1 = l1 + se.Length;
                    }
                }

                if (l0 > l1)
                {
                    return(dataLine[0]);
                }
                else
                {
                    return(dataLine[1]);
                }
            }
        }
コード例 #13
0
        override protected void ButtonDefinition_OnExecute(NameValueMap context)
        {
            try
            {
                //check to make sure a sketch is active
                if (InventorApplication.ActiveEditObject is PlanarSketch)
                {
                    //if same session, combobox definitions will already exist
                    ComboBoxDefinition slotWidthComboBoxDefinition;
                    slotWidthComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotWidthCboBox"];

                    ComboBoxDefinition slotHeightComboBoxDefinition;
                    slotHeightComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotHeightCboBox"];

                    //get the selected width from combo box
                    double slotWidth;
                    slotWidth = slotWidthComboBoxDefinition.ListIndex;

                    //get the selected height from combo box
                    double slotHeight;
                    slotHeight = slotHeightComboBoxDefinition.ListIndex;

                    if (slotWidth > 0 && slotHeight > 0)
                    {
                        //draw the sketch for the slot
                        PlanarSketch planarSketch;
                        planarSketch = (PlanarSketch)InventorApplication.ActiveEditObject;

                        SketchLine[] lines = new SketchLine[2];
                        SketchArc[]  arcs  = new SketchArc[2];

                        TransientGeometry transientGeometry;
                        transientGeometry = InventorApplication.TransientGeometry;

                        //start a transaction so the slot will be within a single undo step
                        Transaction createSlotTransaction;
                        createSlotTransaction = InventorApplication.TransactionManager.StartTransaction(InventorApplication.ActiveDocument, "Create Slot");

                        //draw the lines and arcs that make up the shape of the slot
                        lines[0] = planarSketch.SketchLines.AddByTwoPoints(transientGeometry.CreatePoint2d(0, 0), transientGeometry.CreatePoint2d(slotWidth, 0));
                        arcs[0]  = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(slotWidth, slotHeight / 2.0), lines[0].EndSketchPoint, transientGeometry.CreatePoint2d(slotWidth, slotHeight), true);

                        lines[1] = planarSketch.SketchLines.AddByTwoPoints(arcs[0].EndSketchPoint, transientGeometry.CreatePoint2d(0, slotHeight));
                        arcs[1]  = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(0, slotHeight / 2.0), lines[1].EndSketchPoint, lines[0].StartSketchPoint, true);

                        //create the tangent constraints between the lines and arcs
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[0], null);
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[0], null);
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[1], null);
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[1], null);

                        //create a parallel constraint between the two lines
                        planarSketch.GeometricConstraints.AddParallel((SketchEntity)lines[0], (SketchEntity)lines[1], true, true);

                        //end the transaction
                        createSlotTransaction.End();
                    }
                    else
                    {
                        //valid width/height was not specified
                        MessageBox.Show("Please specify valid slot width and height");
                    }
                }
                else
                {
                    //no sketch is active, so display an error
                    MessageBox.Show("A sketch must be active for this command");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
コード例 #14
0
        protected override void ButtonDefinition_OnExecute(NameValueMap context)
        {
            try
            {
                //check to make sure a sketch is active
                if (InventorApplication.ActiveEditObject is PlanarSketch)
                {
                    //if same session, combobox definitions will already exist
                    ComboBoxDefinition slotWidthComboBoxDefinition;
                    slotWidthComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotWidthCboBox"];

                    ComboBoxDefinition slotHeightComboBoxDefinition;
                    slotHeightComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotHeightCboBox"];

                    //get the selected width from combo box
                    double slotWidth;
                    slotWidth = slotWidthComboBoxDefinition.ListIndex;

                    //get the selected height from combo box
                    double slotHeight;
                    slotHeight = slotHeightComboBoxDefinition.ListIndex;

                    if (slotWidth > 0 && slotHeight > 0)
                    {
                        //draw the sketch for the slot
                        PlanarSketch  planarSketch;
                        planarSketch = (PlanarSketch)InventorApplication.ActiveEditObject;

                        SketchLine[] lines = new SketchLine[2];
                        SketchArc[] arcs = new SketchArc[2];

                        TransientGeometry transientGeometry;
                        transientGeometry = InventorApplication.TransientGeometry;

                        //start a transaction so the slot will be within a single undo step
                        Transaction createSlotTransaction;
                        createSlotTransaction = InventorApplication.TransactionManager.StartTransaction(InventorApplication.ActiveDocument, "Create Slot");

                        //draw the lines and arcs that make up the shape of the slot
                        lines[0] = planarSketch.SketchLines.AddByTwoPoints(transientGeometry.CreatePoint2d(0, 0), transientGeometry.CreatePoint2d(slotWidth, 0));
                        arcs[0] = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(slotWidth, slotHeight / 2.0), lines[0].EndSketchPoint, transientGeometry.CreatePoint2d(slotWidth, slotHeight), true);

                        lines[1] = planarSketch.SketchLines.AddByTwoPoints(arcs[0].EndSketchPoint, transientGeometry.CreatePoint2d(0, slotHeight));
                        arcs[1] = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(0, slotHeight / 2.0), lines[1].EndSketchPoint, lines[0].StartSketchPoint, true);

                        //create the tangent constraints between the lines and arcs
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[0], null);
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[0], null);
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[1], null);
                        planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[1], null);

                        //create a parallel constraint between the two lines
                        planarSketch.GeometricConstraints.AddParallel((SketchEntity)lines[0], (SketchEntity)lines[1], true, true);

                        //end the transaction
                        createSlotTransaction.End();
                    }
                    else
                    {
                        //valid width/height was not specified
                        MessageBox.Show("Please specify valid slot width and height");
                    }

                }
                else
                {
                    //no sketch is active, so display an error
                    MessageBox.Show("A sketch must be active for this command");

                }
            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: JefftownGH/inventor-1
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                ThisApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
                if (ThisApplication != null)
                {
                    label1.Text = "Inventor запущен.";
                }
            }
            catch
            {
                MessageBox.Show("Запустите Inventor!");
                return;
            }

            //Перевод мм в см
            D /= 10; d /= 10; B /= 10; r /= 10; r1 /= 10;

            //Sketch..
            New_document_Name("Подшипник");
            oPartDoc["Подшипник"].DisplayName = "Подшипник";
            PlanarSketch oSketch = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);

            SketchPoint[]  point      = new SketchPoint[101];
            SketchArc[]    arc        = new SketchArc[101];
            SketchPoint[]  center_arc = new SketchPoint[101];
            SketchLine[]   lines      = new SketchLine[101];
            SketchCircle[] circles    = new SketchCircle[101];

            //Координаты точек вершин прямоугольника
            point[0] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2));
            point[1] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, d / 2));
            point[2] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, d / 2));
            point[3] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2));
            point[4] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (D / 2 - d / 2) / 3 + d / 2));
            point[5] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (D / 2 - d / 2) * 2 / 3 + d / 2));
            point[6] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, (D / 2 - d / 2) / 3 + d / 2));
            point[7] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, (D / 2 - d / 2) * 2 / 3 + d / 2));

            //Соединение верхнего прямоугольника
            lines[0] = oSketch.SketchLines.AddByTwoPoints(point[0], point[5]);
            lines[1] = oSketch.SketchLines.AddByTwoPoints(point[3], point[7]);
            lines[2] = oSketch.SketchLines.AddByTwoPoints(point[0], point[3]);
            lines[3] = oSketch.SketchLines.AddByTwoPoints(point[5], point[7]);

            //Содинение вершин нижнего прямоугольника
            lines[4] = oSketch.SketchLines.AddByTwoPoints(point[4], point[1]);
            lines[5] = oSketch.SketchLines.AddByTwoPoints(point[1], point[2]);
            lines[6] = oSketch.SketchLines.AddByTwoPoints(point[4], point[6]);
            lines[7] = oSketch.SketchLines.AddByTwoPoints(point[6], point[2]);

            //Ось вращения двух прямоугольников
            point[8] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[9] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0));
            lines[8] = oSketch.SketchLines.AddByTwoPoints(point[8], point[9]);

            //Closing the sketch
            oTrans["Подшипник"].End();

            //Вращение
            Profile oProfile = default(Profile);

            oProfile = (Profile)oSketch.Profiles.AddForSolid();
            RevolveFeature revolvefeature = default(RevolveFeature);

            revolvefeature = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile, lines[8], PartFeatureOperationEnum.kJoinOperation);



            /*
             * Новый скетч 1
             */



            //Новый sketch с окружностями
            PlanarSketch oSketch1 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans1  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Окружности
            point[10]  = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, (D / 2 + d / 2) / 2));
            point[11]  = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, (D / 2 + d / 2) / 2));
            circles[0] = oSketch1.SketchCircles.AddByCenterRadius(point[10], (D / 2 - d / 2) / 3.6);
            circles[1] = oSketch1.SketchCircles.AddByCenterRadius(point[11], (D / 2 - d / 2) / 3.6);

            //Ось вращения подшипника
            point[12] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[13] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0));
            lines[9]  = oSketch1.SketchLines.AddByTwoPoints(point[12], point[13]);

            //Closing the sketch 1
            oTrans1.End();

            //Выдавливание выемки
            Profile oProfile1 = default(Profile);

            oProfile1 = (Profile)oSketch1.Profiles.AddForSolid();
            RevolveFeature revolvefeature1 = default(RevolveFeature);

            revolvefeature1 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile1, lines[9], PartFeatureOperationEnum.kCutOperation);

            /*
             * New sketch 4
             */

            //New sketch 4
            PlanarSketch oSketch4 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans4  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Четырехугольник для вычетания выдавливания по краям подшипнника (слева)
            point[20] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2 * 0.7916875 - 0.1));
            point[21] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2 * 0.9275625));
            point[22] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * 0.861125));
            point[23] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * 0.7916875 - 0.1));
            lines[12] = oSketch4.SketchLines.AddByTwoPoints(point[20], point[21]);
            lines[13] = oSketch4.SketchLines.AddByTwoPoints(point[20], point[23]);
            lines[14] = oSketch4.SketchLines.AddByTwoPoints(point[21], point[22]);
            lines[15] = oSketch4.SketchLines.AddByTwoPoints(point[22], point[23]);

            point[26] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2 * 0.7916875 - 0.1));
            point[27] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2 * 0.9275625));
            point[28] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * 0.861125));
            point[29] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * 0.7916875 - 0.1));
            lines[17] = oSketch4.SketchLines.AddByTwoPoints(point[26], point[27]);
            lines[18] = oSketch4.SketchLines.AddByTwoPoints(point[27], point[28]);
            lines[19] = oSketch4.SketchLines.AddByTwoPoints(point[28], point[29]);
            lines[20] = oSketch4.SketchLines.AddByTwoPoints(point[29], point[26]);

            //ось
            point[24] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[25] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0));
            lines[16] = oSketch4.SketchLines.AddByTwoPoints(point[24], point[25]);

            //Closing the sketch 4
            oTrans4.End();

            //Вычетание началось (слева)
            Profile oProfile4 = default(Profile);

            oProfile4 = (Profile)oSketch4.Profiles.AddForSolid();
            RevolveFeature revolveFeature4 = default(RevolveFeature);

            revolveFeature4 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile4, lines[16], PartFeatureOperationEnum.kCutOperation);



            /*
             * New sketch 2
             */



            //Новый sketch с окружностями
            PlanarSketch oSketch2 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans2  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Задаю полуокружность!
            point[14] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * n));
            point[15] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * m));
            lines[10] = oSketch2.SketchLines.AddByTwoPoints(point[14], point[15]);
            point[16] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, (D / 2 + d / 2) / 2));
            arc[0]    = oSketch2.SketchArcs.AddByCenterStartEndPoint(point[16], point[15], point[14], false);


            //Closing the sketch 2
            oTrans2.End();


            //Выдавливание окружности 1
            Profile oProfile2 = default(Profile);

            oProfile2 = (Profile)oSketch2.Profiles.AddForSolid();
            RevolveFeature revolveFeature2 = default(RevolveFeature);

            revolveFeature2 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile2, lines[10], PartFeatureOperationEnum.kJoinOperation);

            //New sketch 3
            PlanarSketch oSketch3 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans3  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Задаю окружность второго шарика
            point[17] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * n));
            point[18] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * m));
            lines[11] = oSketch3.SketchLines.AddByTwoPoints(point[17], point[18]);
            point[19] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, (D / 2 + d / 2) / 2));
            arc[1]    = oSketch3.SketchArcs.AddByCenterStartEndPoint(point[19], point[17], point[18], false);

            //Closing the sketch 3
            oTrans3.End();

            //Вращение шарика
            Profile oProfile3 = default(Profile);

            oProfile3 = (Profile)oSketch3.Profiles.AddForSolid();
            RevolveFeature revolveFeature3 = default(RevolveFeature);

            revolveFeature3 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile3, lines[11], PartFeatureOperationEnum.kJoinOperation);

            WorkAxis         oAxis          = oCompDef["Подшипник"].WorkAxes[1];
            ObjectCollection oObjCollection = ThisApplication.TransientObjects.CreateObjectCollection();

            oObjCollection.Add(revolveFeature3);
            CircularPatternFeature CircularPatternFeature = oCompDef["Подшипник"].Features.CircularPatternFeatures.Add(oObjCollection, oAxis, true, count, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute);

            WorkAxis         oAxis1          = oCompDef["Подшипник"].WorkAxes[1];
            ObjectCollection oObjCollection1 = ThisApplication.TransientObjects.CreateObjectCollection();

            oObjCollection1.Add(revolveFeature2);
            CircularPatternFeature oCircularPatternFeature1 = oCompDef["Подшипник"].Features.CircularPatternFeatures.Add(oObjCollection1, oAxis1, true, count, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute);



            /*НАЧАЛО ВАЛА
             * НАЧАЛО ВАЛА
             * НАЧАЛО ВАЛА
             * НАЧАЛО ВАЛА
             */



            //New sketch 5
            PlanarSketch oSketch5 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans5  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Ось вала
            point[30] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[31] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0.7, 0));
            lines[16] = oSketch5.SketchLines.AddByTwoPoints(point[30], point[31]);

            //Эскиз вала
            point[32] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (((D / 2 - d / 2) / 3 + d / 2) + d / 2) / 2));
            point[33] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, d / 2));
            lines[17] = oSketch5.SketchLines.AddByTwoPoints(point[32], point[33]);
            point[34] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(-0.1 * k, (((D / 2 - d / 2) / 3 + d / 2) + d / 2) / 2));
            lines[18] = oSketch5.SketchLines.AddByTwoPoints(point[32], point[34]);
            point[35] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(-0.1 * k, 0));
            lines[19] = oSketch5.SketchLines.AddByTwoPoints(point[34], point[35]);
            point[36] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k, d / 2));
            lines[20] = oSketch5.SketchLines.AddByTwoPoints(point[33], point[36]);
            point[37] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k, 0.4 * k));
            lines[21] = oSketch5.SketchLines.AddByTwoPoints(point[36], point[37]);
            point[38] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k + 0.3 * k, 0.4 * k));
            lines[22] = oSketch5.SketchLines.AddByTwoPoints(point[37], point[38]);
            point[39] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k + 0.3 * k, 0));
            lines[23] = oSketch5.SketchLines.AddByTwoPoints(point[38], point[39]);
            lines[24] = oSketch5.SketchLines.AddByTwoPoints(point[39], point[35]);

            //Closing
            oTrans5.End();

            //Вращение вала
            Profile oProfile5 = default(Profile);

            oProfile5 = (Profile)oSketch5.Profiles.AddForSolid();
            RevolveFeature revolveFeature5 = default(RevolveFeature);

            revolveFeature5 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile5, lines[16], PartFeatureOperationEnum.kJoinOperation);

            //Вращение вала

            /*Profile oProfile5 = default(Profile);
             * oProfile5 = (Profile)oSketch5.Profiles.AddForSolid();
             * RevolveFeature revolveFeature5 = default(RevolveFeature);
             * revolveFeature5 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile5, lines[16], PartFeatureOperationEnum.kJoinOperation);*/



            //см в мм
            D *= 10; d *= 10; B *= 10; r *= 10; r1 *= 10;
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: reikus/SolidWorks-Automation
        // Durchläuft alle Feature des geladenenen Teils und sucht nach Kreis-Elementen, gibt diese in ListBox aus
        private void b_analyze_Click_Click(object sender, EventArgs e)
        {
            //Variablen
            ModelDoc2 swModel;
            Feature   swFeature, subFeature;
            String    FeatureName, FeatureType;
            Sketch    swSketch;

            Object[]    Segments;
            SketchPoint cPoint;

            // Bereinigen der ListBox
            lb_output.Items.Clear();

            // sldprt breits geöffnent, daher nur auslesen des bereits geöffneten Teils
            swModel   = (ModelDoc2)swApp.ActiveDoc;
            swFeature = (Feature)swModel.FirstFeature();

            // Durchlaufen aller Features
            while (swFeature != null)
            {
                // Output des Featurenamen und Typs in ListBox
                lb_output.Items.Add(swFeature.Name + " " + swFeature.GetTypeName());

                // Überprüfen, ob Feature vom Typ Schnitt
                // weiterhin, ob Name "Bohrbild"
                if (swFeature.GetTypeName() == "Cut" && swFeature.Name == "Bohrbild")
                {
                    // Auslesen des ersten Sub-Features
                    subFeature = (Feature)swFeature.GetFirstSubFeature();

                    // Durchlaufen aller Sub-Features
                    while (subFeature != null)
                    {
                        FeatureName = subFeature.Name;
                        FeatureType = subFeature.GetTypeName();

                        // Output des Sub-Feature Name und Typs in ListBox
                        lb_output.Items.Add("\t" + FeatureName + "\t" + FeatureType);

                        // Überprüfen, ob es sich um Skizze handelt (ProfilFeature)
                        if (FeatureType == "ProfileFeature")
                        {
                            // Auslesen des spezifischen Features
                            swSketch = (Sketch)subFeature.GetSpecificFeature2();
                            // Auslesen der Skizzenegmente
                            Segments = (Object[])swSketch.GetSketchSegments();

                            // Durchlaufe alle Sketch-Segmente
                            foreach (SketchSegment sketchSeg in Segments)
                            {
                                // Prüfen, ob aktuelles Sketch-Segment vom Typ swSketchARC
                                if (sketchSeg.GetType() == (int)swSketchSegments_e.swSketchARC)
                                {
                                    // Umwandeln in Skizzenkreis
                                    SketchArc arc = (SketchArc)sketchSeg;
                                    // Auslesen Mittelpunkt
                                    cPoint = (SketchPoint)arc.GetCenterPoint2();

                                    // Ausgeben in Listbox
                                    lb_output.Items.Add("\tKreis: X = " + cPoint.X + "\tY=" + cPoint.Y + "\tZ=" + cPoint.Z +
                                                        "\tR=" + arc.GetRadius());
                                }
                            }
                        }

                        // nächstes Sub-Feature
                        // wenn keines mehr vorhanden, liefert "null" zurück und bricht aus Schleife aus
                        subFeature = (Feature)subFeature.GetNextSubFeature();
                    }
                }
                // nächstes Feature
                swFeature = (Feature)swFeature.GetNextFeature();
            }
        }
コード例 #17
0
ファイル: segs.cs プロジェクト: Lostoner/Solidworks_Features
 public Arc(SketchSegment segments)
 {
     seg = (SketchArc)segments;
     ori = segments;
 }
コード例 #18
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                ThisApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
                if (ThisApplication != null)
                {
                    label1.Text = "Inventor запущен.";
                }
            }
            catch
            {
                MessageBox.Show("Запустите Inventor!");
                return;
            }

            A = Convert.ToDouble(textBox1.Text);
            B = Convert.ToDouble(textBox2.Text);
            C = Convert.ToDouble(textBox3.Text);
            D = Convert.ToDouble(textBox4.Text);
            E = Convert.ToDouble(textBox5.Text);
            F = Convert.ToDouble(textBox6.Text);
            G = Convert.ToDouble(textBox7.Text);
            H = Convert.ToDouble(textBox8.Text);
            I = Convert.ToDouble(textBox9.Text);
            J = Convert.ToDouble(textBox10.Text);
            K = Convert.ToDouble(textBox11.Text);
            L = Convert.ToDouble(textBox12.Text);
            M = Convert.ToDouble(textBox13.Text);

            //Перевод мм в см
            A /= 10; B /= 10; C /= 10; D /= 10; E /= 10; F /= 10; G /= 10; H /= 10; I /= 10; J /= 10; K /= 10; L /= 10; M /= 10;

            SketchPoint[] point = new SketchPoint[101];
            SketchLine[]  lines = new SketchLine[101];
            SketchArc[]   arc   = new SketchArc[101];

            //Эскиз в осях XY
            New_document_Name("Деталь");
            oPartDoc["Деталь"].DisplayName = "Деталь";
            PlanarSketch oSketch = oCompDef["Деталь"].Sketches.Add(oCompDef["Деталь"].WorkPlanes[3]);

            //Построение эскиза
            point[0] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(0, 0));
            point[1] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A, 0));
            lines[0] = oSketch.SketchLines.AddByTwoPoints(point[0], point[1]);

            point[2] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A, D));
            lines[1] = oSketch.SketchLines.AddByTwoPoints(point[1], point[2]);

            point[3] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d((A - E) / 2 + E, D));
            lines[2] = oSketch.SketchLines.AddByTwoPoints(point[2], point[3]);

            point[4] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d((A - E) / 2, D));
            point[5] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(0, D));
            lines[3] = oSketch.SketchLines.AddByTwoPoints(point[4], point[5]);
            lines[4] = oSketch.SketchLines.AddByTwoPoints(point[0], point[5]);

            point[6] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d((A - E) / 2 + E, D - I));
            point[7] = oSketch.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d((A - E) / 2, D - I));
            lines[5] = oSketch.SketchLines.AddByTwoPoints(point[4], point[7]);
            lines[6] = oSketch.SketchLines.AddByTwoPoints(point[3], point[6]);
            lines[7] = oSketch.SketchLines.AddByTwoPoints(point[6], point[7]);

            //Конец эскиза
            oTrans["Деталь"].End();

            //Выдавливание первого эскиза (прямоугольника с выемкой)
            Profile oProfile = default(Profile);

            oProfile = (Profile)oSketch.Profiles.AddForSolid();
            ExtrudeFeature oExtrude;

            oExtrude = oCompDef["Деталь"].Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, B, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection, PartFeatureOperationEnum.kJoinOperation);

            //Верхний эскиз для выдавливания "рампы"
            PlanarSketch oSketch1 = oCompDef["Деталь"].Sketches.Add(oCompDef["Деталь"].WorkPlanes[3]);
            Transaction  oTrans1  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Построение точек
            point[8] = oSketch1.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(0, D));
            point[9] = oSketch1.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A, D));
            lines[8] = oSketch1.SketchLines.AddByTwoPoints(point[8], point[9]);

            point[10] = oSketch1.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d((A - C) / 2, D + J));
            point[11] = oSketch1.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A - (A - C) / 2, D + J));
            point[12] = oSketch1.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d((A - 2 * K) / 2, D + J));
            point[13] = oSketch1.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d((A - 2 * K) / 2 + 2 * K, D + J));
            lines[9]  = oSketch1.SketchLines.AddByTwoPoints(point[11], point[13]);
            lines[10] = oSketch1.SketchLines.AddByTwoPoints(point[10], point[12]);
            lines[11] = oSketch1.SketchLines.AddByTwoPoints(point[8], point[10]);
            lines[12] = oSketch1.SketchLines.AddByTwoPoints(point[9], point[11]);

            //Арка
            point[11] = oSketch1.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A / 2, D + J));
            arc[0]    = oSketch1.SketchArcs.AddByCenterStartEndPoint(point[11], point[12], point[13]);

            //Конец эскиза
            oTrans1.End();

            //Выдавливание "рампы"
            Profile oProfile1 = default(Profile);

            oProfile1 = (Profile)oSketch1.Profiles.AddForSolid();
            ExtrudeFeature oExtrude1;

            oExtrude1 = oCompDef["Деталь"].Features.ExtrudeFeatures.AddByDistanceExtent(oProfile1, M, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection, PartFeatureOperationEnum.kJoinOperation);

            //Эскиз вырезаний при выдавливании.
            PlanarSketch oSketch2 = oCompDef["Деталь"].Sketches.Add(oCompDef["Деталь"].WorkPlanes[3]);
            Transaction  oTrans2  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Построение эскиза!
            point[13] = oSketch2.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(0, 0));
            point[14] = oSketch2.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A, 0));
            lines[13] = oSketch2.SketchLines.AddByTwoPoints(point[13], point[14]);

            point[15] = oSketch2.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(0, G));
            lines[14] = oSketch2.SketchLines.AddByTwoPoints(point[13], point[15]);

            point[16] = oSketch2.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A, G));
            lines[15] = oSketch2.SketchLines.AddByTwoPoints(point[15], point[16]);
            lines[16] = oSketch2.SketchLines.AddByTwoPoints(point[16], point[14]);

            //Конец эскиза
            oTrans2.End();

            //Выдавливание (вычетание) прямоугольника снизу
            Profile oProfile2 = default(Profile);

            oProfile2 = (Profile)oSketch2.Profiles.AddForSolid();
            ExtrudeFeature oExtrude2;

            oExtrude2 = oCompDef["Деталь"].Features.ExtrudeFeatures.AddByDistanceExtent(oProfile2, F, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection, PartFeatureOperationEnum.kCutOperation);

            //New Sketch, где последний эскиз
            PlanarSketch oSketch3 = oCompDef["Деталь"].Sketches.Add(oCompDef["Деталь"].WorkPlanes[3]);
            Transaction  oTrans3  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Построение эскиза
            point[17] = oSketch3.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(0, D + J));
            point[18] = oSketch3.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A, D + J));
            lines[16] = oSketch3.SketchLines.AddByTwoPoints(point[17], point[18]);

            point[19] = oSketch3.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(0, D + J - H));
            lines[17] = oSketch3.SketchLines.AddByTwoPoints(point[17], point[19]);

            point[20] = oSketch3.SketchPoints.Add(oTransGeom["Деталь"].CreatePoint2d(A, D + J - H));
            lines[18] = oSketch3.SketchLines.AddByTwoPoints(point[20], point[18]);
            lines[19] = oSketch3.SketchLines.AddByTwoPoints(point[20], point[19]);

            //Закрытие эскиза
            oTrans3.End();

            //Выдавливание (отрицательное) так называемой "рампы" ниже
            Profile oProfile3 = default(Profile);

            oProfile3 = (Profile)oSketch3.Profiles.AddForSolid();
            ExtrudeFeature oExtrude3;

            oExtrude3 = oCompDef["Деталь"].Features.ExtrudeFeatures.AddByDistanceExtent(oProfile3, L, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection, PartFeatureOperationEnum.kCutOperation);
        }
コード例 #19
0
        public void storeSegments2()                    //获取边与点,取代上面三个函数,目前使用中
        {
            if (sket.GetSketchPoints2() == null)
            {
                Debug.Print("No points!");
                return;
            }
            verNum = sket.GetSketchPoints2().Length;            //以下为保存边、边的邻接点;点、点的邻接边的操作
            adj    = new int[verNum, verNum];
            for (int i = 0; i < verNum; i++)                    //初始化邻接点数组,为之后的最小环提取做准备,在存储点与边的同时需要存储邻接关系
            {
                for (int j = 0; j < verNum; j++)
                {
                    adj[i, j] = INF;
                }
            }
            object[] segments = sket.GetSketchSegments();
            foreach (SketchSegment seg in segments)             //此时遍历所有边,判断边的类型,而后分类存储
            {
                bool flag = false;
                int  type = seg.GetType();
                switch (type)
                {
                case 0:
                    flag = false;
                    loopSeg    temLine = new loopSeg(seg);
                    SketchLine line    = (SketchLine)seg;
                    temLine.setPoint(addPoint(line.GetStartPoint2()), addPoint(line.GetEndPoint2()));
                    temLine.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temLine.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temLine);

                        pois[temLine.start].setNext(temLine.end);
                        pois[temLine.end].setNext(temLine.start);

                        pois[temLine.start].setNextSeg2(temLine.index);
                        pois[temLine.end].setNextSeg2(temLine.index);

                        adj[temLine.start, temLine.end] = 1;
                        adj[temLine.end, temLine.start] = 1;
                    }
                    break;

                case 1:
                    flag = false;
                    loopSeg   temArc = new loopSeg(seg);
                    SketchArc arc    = (SketchArc)seg;
                    temArc.setPoint(addPoint(arc.GetStartPoint2()), addPoint(arc.GetEndPoint2()));
                    temArc.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temArc.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temArc);

                        pois[temArc.start].setNext(temArc.end);
                        pois[temArc.end].setNext(temArc.start);

                        pois[temArc.start].setNextSeg2(temArc.index);
                        pois[temArc.end].setNextSeg2(temArc.index);

                        adj[temArc.start, temArc.end] = 1;
                        adj[temArc.end, temArc.start] = 1;
                    }
                    break;

                case 2:
                    flag = false;
                    loopSeg       temEll = new loopSeg(seg);
                    SketchEllipse ell    = (SketchEllipse)seg;
                    temEll.setPoint(addPoint(ell.GetStartPoint2()), addPoint(ell.GetEndPoint2()));
                    temEll.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temEll.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temEll);

                        pois[temEll.start].setNext(temEll.end);
                        pois[temEll.end].setNext(temEll.start);

                        pois[temEll.start].setNextSeg2(temEll.index);
                        pois[temEll.end].setNextSeg2(temEll.index);

                        adj[temEll.start, temEll.end] = 1;
                        adj[temEll.end, temEll.start] = 1;
                    }
                    break;

                case 3:
                    flag = false;
                    loopSeg      temSpl = new loopSeg(seg);
                    SketchSpline spl    = (SketchSpline)seg;
                    object[]     tem    = spl.GetPoints2();
                    temSpl.setPoint(addPoint((SketchPoint)tem[0]), addPoint((SketchPoint)tem[tem.Length - 1]));
                    temSpl.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temSpl.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temSpl);

                        pois[temSpl.start].setNext(temSpl.end);
                        pois[temSpl.end].setNext(temSpl.start);

                        pois[temSpl.start].setNextSeg2(temSpl.index);
                        pois[temSpl.end].setNextSeg2(temSpl.index);

                        adj[temSpl.start, temSpl.end] = 1;
                        adj[temSpl.end, temSpl.start] = 1;
                    }
                    break;

                case 5:
                    flag = false;
                    loopSeg        temPar = new loopSeg(seg);
                    SketchParabola par    = (SketchParabola)seg;
                    temPar.setPoint(addPoint(par.GetStartPoint2()), addPoint(par.GetEndPoint2()));
                    temPar.setIndex(loopSegs.Count);
                    for (int i = 0; i < loopSegs.Count; i++)
                    {
                        if (temPar.same(loopSegs[i]))
                        {
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        loopSegs.Add(temPar);

                        pois[temPar.start].setNext(temPar.end);
                        pois[temPar.end].setNext(temPar.start);

                        pois[temPar.start].setNextSeg2(temPar.index);
                        pois[temPar.end].setNextSeg2(temPar.index);

                        adj[temPar.start, temPar.end] = 1;
                        adj[temPar.end, temPar.start] = 1;
                    }
                    break;

                case 4:
                    break;
                }
            }
        }
コード例 #20
0
        public void storeSegments()                     //获取边(被取代)
        {
            verNum = sket.GetSketchPoints2().Length;
            adj    = new int[verNum, verNum];
            //Debug.Print("Storing segments: ");
            object[] segments = sket.GetSketchSegments();
            foreach (SketchSegment seg in segments)
            {
                bool flag = false;
                int  type = seg.GetType();
                switch (type)
                {
                case 0:
                    flag = false;
                    segs.Line  temLine = new segs.Line(seg);
                    SketchLine line    = (SketchLine)seg;
                    temLine.setPoint(addPoint(line.GetStartPoint2()), addPoint(line.GetEndPoint2()));
                    //temLine.setPoint(findPoint(line.GetStartPoint2()), findPoint(line.GetEndPoint2()));
                    for (int i = 0; i < segLin.Count; i++)
                    {
                        if (temLine.same(segLin[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segLin.Add(temLine);
                        pois[temLine.sPoint].setNext(temLine.ePoint);
                        pois[temLine.ePoint].setNext(temLine.sPoint);

                        pois[temLine.sPoint].setNextSeg(0, segLin.Count - 1);
                        pois[temLine.ePoint].setNextSeg(0, segLin.Count - 1);

                        adj[temLine.sPoint, temLine.ePoint] = 1;
                        adj[temLine.ePoint, temLine.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(line.GetStartPoint2()) + "->" + findPoint(line.GetEndPoint2()) + ")");
                    break;

                case 1:
                    segs.Arc  temArc = new segs.Arc(seg);
                    SketchArc arc    = (SketchArc)seg;
                    temArc.setPoint(addPoint(arc.GetStartPoint2()), addPoint(arc.IGetEndPoint2()));
                    //temArc.setPoint(findPoint(arc.GetStartPoint2()), findPoint(arc.IGetEndPoint2()));
                    for (int i = 0; i < segArc.Count; i++)
                    {
                        if (temArc.same(segArc[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segArc.Add(temArc);
                        pois[temArc.sPoint].setNext(temArc.ePoint);
                        pois[temArc.ePoint].setNext(temArc.sPoint);

                        pois[temArc.sPoint].setNextSeg(1, segArc.Count - 1);
                        pois[temArc.ePoint].setNextSeg(1, segArc.Count - 1);

                        adj[temArc.sPoint, temArc.ePoint] = 1;
                        adj[temArc.ePoint, temArc.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(arc.GetStartPoint2()) + "->" + findPoint(arc.GetEndPoint2()) + ")");
                    break;

                case 2:
                    flag = false;
                    segs.Ellipse  temEllipse = new segs.Ellipse(seg);
                    SketchEllipse ellipse    = (SketchEllipse)seg;
                    temEllipse.setPoint(addPoint(ellipse.GetStartPoint2()), addPoint(ellipse.GetEndPoint2()), addPoint(ellipse.GetCenterPoint2()));
                    //temEllipse.setPoint(findPoint(ellipse.GetStartPoint2()), findPoint(ellipse.GetEndPoint2()), findPoint(ellipse.GetCenterPoint2()));
                    for (int i = 0; i < segEll.Count; i++)
                    {
                        if (temEllipse.same(segEll[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segEll.Add(temEllipse);
                        pois[temEllipse.sPoint].setNext(temEllipse.ePoint);
                        pois[temEllipse.ePoint].setNext(temEllipse.sPoint);

                        pois[temEllipse.sPoint].setNextSeg(2, segEll.Count - 1);
                        pois[temEllipse.ePoint].setNextSeg(2, segEll.Count - 1);

                        adj[temEllipse.sPoint, temEllipse.ePoint] = 1;
                        adj[temEllipse.ePoint, temEllipse.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(ellipse.GetStartPoint2()) + "->" + findPoint(ellipse.GetEndPoint2()) + ")");
                    break;

                case 3:
                    flag = false;
                    segs.Spline   temSpline = new segs.Spline(seg);
                    SketchSpline  spline    = (SketchSpline)seg;
                    SketchPoint[] tempoints = spline.GetPoints2();
                    for (int i = 0; i < tempoints.Length; i++)
                    {
                        int index = addPoint(tempoints[i]);
                        temSpline.setPoint(index);
                    }

                    /*
                     * for(int i = 0; i < tempoints.Length; i++)
                     * {
                     *  int index = findPoint(tempoints[i]);
                     *  temSpline.setPoint(index);
                     * }
                     */
                    for (int i = 0; i < segSpl.Count; i++)
                    {
                        if (temSpline.same(segSpl[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segSpl.Add(temSpline);
                        pois[temSpline.sPoint].setNext(temSpline.ePoint);
                        pois[temSpline.ePoint].setNext(temSpline.sPoint);

                        pois[temSpline.sPoint].setNextSeg(3, segSpl.Count - 1);
                        pois[temSpline.ePoint].setNextSeg(3, segSpl.Count - 1);

                        adj[temSpline.sPoint, temSpline.ePoint] = 1;
                        adj[temSpline.ePoint, temSpline.sPoint] = 1;
                    }
                    //Debug.Print("Spline");
                    break;

                case 5:
                    segs.Parabola  temParabola = new segs.Parabola(seg);
                    SketchParabola parabola    = (SketchParabola)seg;
                    temParabola.setPoint(addPoint(parabola.GetStartPoint2()), addPoint(parabola.IGetEndPoint2()));
                    //temParabola.setPoint(findPoint(parabola.GetStartPoint2()), findPoint(parabola.IGetEndPoint2()));
                    for (int i = 0; i < segPar.Count; i++)
                    {
                        if (temParabola.same(segPar[i]))
                        {
                            flag = true;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                    else
                    {
                        segPar.Add(temParabola);
                        pois[temParabola.sPoint].setNext(temParabola.ePoint);
                        pois[temParabola.ePoint].setNext(temParabola.sPoint);

                        pois[temParabola.sPoint].setNextSeg(5, segPar.Count - 1);
                        pois[temParabola.ePoint].setNextSeg(5, segPar.Count - 1);

                        adj[temParabola.sPoint, temParabola.ePoint] = 1;
                        adj[temParabola.ePoint, temParabola.sPoint] = 1;
                    }
                    //Debug.Print("Segment " + count.ToString() + ": " + seg.GetType() + ", (" + findPoint(parabola.GetStartPoint2()) + "->" + findPoint(parabola.GetEndPoint2()) + ")");
                    break;

                case 4:
                    break;
                }
            }
        }
コード例 #21
0
        private void circleSticker(ref PartDocument pDoc, double heigth, double width, double R, string txt = "", double thickness = 0.1)
        {
            PartComponentDefinition compDef = pDoc.ComponentDefinition;

            heigth /= 10; width /= 10; thickness /= 10;
            PlanarSketch ps = compDef.Sketches.Add(compDef.WorkPlanes[2]);
            //SketchEntity origin = ps.AddByProjectingEntity(compDef.WorkPoints[1]);
            double  alfa    = alfaFromL(heigth, R);
            Point2d startPt = m_TG.CreatePoint2d();

            SketchArc arc = ps.SketchArcs.AddByCenterStartSweepAngle(startPt, R, 3.1415926 / 2 - alfa / 2, alfa);
            //ObjectCollection objs = invApp.TransientObjects.CreateObjectCollection();
            //objs.Add(arc);
            //ps.RotateSketchObjects(objs, arc.CenterSketchPoint.Geometry, 1,RemoveConstraints:true);
            //arc = (SketchArc)en[1];
            //ps.GeometricConstraints.AddVerticalAlign((SketchPoint)origin, arc.CenterSketchPoint);
            ObjectCollection objCol = invApp.TransientObjects.CreateObjectCollection();

            objCol.Add(arc);
            SketchEntitiesEnumerator sArc = ps.OffsetSketchEntitiesUsingDistance(objCol, thickness, true);
            SketchArc arc2 = (SketchArc)sArc[1];

            ps.SketchLines.AddByTwoPoints(arc2.StartSketchPoint, arc.StartSketchPoint);
            ps.SketchLines.AddByTwoPoints(arc2.EndSketchPoint, arc.EndSketchPoint);
            Profile           pr     = ps.Profiles.AddForSolid();
            ExtrudeDefinition extDef = compDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(pr, PartFeatureOperationEnum.kNewBodyOperation);

            extDef.SetDistanceExtent(width / 2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection);
            extDef.SetDistanceExtentTwo(width / 2);
            ExtrudeFeature extr = compDef.Features.ExtrudeFeatures.Add(extDef);

            extr.Appearance = InvDoc.u.createColor(pDoc, "white_", "белый_", 255, 255, 255);
            if (txt != "")
            {
                ps = compDef.Sketches.Add(compDef.WorkPlanes[3]);
                Inventor.TextBox tb = ps.TextBoxes.AddByRectangle(pts(-heigth, -width), pts(heigth, width), txt);
                tb.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter;
                tb.VerticalJustification   = VerticalTextAlignmentEnum.kAlignTextMiddle;
                tb.SingleLineText          = false;
                tb.Rotation = Math.PI;
                if (mirror)
                {
                    tb.Rotation = Math.PI;
                }
                if (this.radioButton1.Checked == false)
                {
                    //ObjectCollection col = invApp.TransientObjects.CreateObjectCollection();
                    //col.Add(tb);
                    //ps.RotateSketchObjects(col, pt, Math.PI / 4);
                    tb.Rotation -= Math.PI / 2;
                }
                Face face2 = null;
                foreach (Face f in compDef.SurfaceBodies[1].Faces)
                {
                    if (f.SurfaceType == SurfaceTypeEnum.kCylinderSurface)
                    {
                        double val = Math.Round(((Cylinder)f.Geometry).Radius, 3) * 100;
                        val = Math.Round(val, 0);

                        if /*((int)val == (int)((R + thickness)*100))*/ (InvDoc.u.eq(val, (R + thickness) * 100))
                        {
                            face2 = f; break;
                        }
                    }
                }
                EmbossFeature emb = compDef.Features.EmbossFeatures.AddEmbossFromFace(ps.Profiles.AddForSolid(false, ps.TextBoxes), 0.0005, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, WrapFace: face2);
                emb.Appearance = InvDoc.u.createColor(pDoc, "black_", "черный_", 0, 0, 0);
            }
        }