private void triangleSticker(ref PartDocument pDoc, double heigth, double width, string txt = "", double thickness = 0.01)
        {
            PartComponentDefinition compDef = pDoc.ComponentDefinition;
            PlanarSketch            ps      = compDef.Sketches.Add(compDef.WorkPlanes[3]);
            SketchLine line1 = ps.SketchLines.AddByTwoPoints(m_TG.CreatePoint2d(-width / 20, -heigth / 30), m_TG.CreatePoint2d(width / 20, -heigth / 30));
            SketchLine line2 = ps.SketchLines.AddByTwoPoints(line1.StartSketchPoint, m_TG.CreatePoint2d(0, heigth / 30 * 2));

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

            extDef.SetDistanceExtent(thickness / 10, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            ExtrudeFeature extr = compDef.Features.ExtrudeFeatures.Add(extDef);

            extr.Appearance = InvDoc.u.createColor(pDoc, "red_", "красный_", 255, 0, 0);
            if (txt != "")
            {
                ps = compDef.Sketches.Add(extr.EndFaces[1]);
                Inventor.TextBox tb = ps.TextBoxes.AddFitted(m_TG.CreatePoint2d(), txt);
                tb.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter;
                tb.VerticalJustification   = VerticalTextAlignmentEnum.kAlignTextMiddle;
                tb.SingleLineText          = false;
                //tb.Rotation = Math.PI;
                if (mirror)
                {
                    tb.Rotation = Math.PI;
                }
                EmbossFeature emb = compDef.Features.EmbossFeatures.AddEmbossFromFace(ps.Profiles.AddForSolid(false, ps.TextBoxes), 0.0005, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
                emb.Appearance = InvDoc.u.createColor(pDoc, "black_", "черный_", 0, 0, 0);
            }
        }
Beispiel #2
0
        //creating a new sketched symbol definition object and
        //    inserting it into the active sheet.
        //    This sample consists of two subs.
        //    The first demonstrates the creation of a sketched symbol definition and
        //    the second inserts it into the active sheet.
        //    To run the sample have a drawing document open and run the CreateSketchedSymbolDefinition Sub.
        //    After this you can run the InsertSketchedSymbolOnSheet to insert the sketched symbol into the active sheet.
        //    The insertion sub demonstrates the use of the insertion point in the symbol's definition while inserting the symbol.

        /// <summary>
        ///  creating a new sketched symbol definition object     '''
        /// </summary>
        /// <remarks></remarks>
        public void CreateSketchedSymbolDefinition()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument;

            // Create the new sketched symbol definition.
            SketchedSymbolDefinition oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("Circular Callout");

            // Open the sketched symbol definition's sketch for edit. This is done by calling the Edit
            // method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates
            // a copy of the sketched symbol definition's and opens it for edit.
            DrawingSketch oSketch = null;

            oSketchedSymbolDef.Edit(out oSketch);

            TransientGeometry oTG = _InvApplication.TransientGeometry;

            // Use the functionality of the sketch to add sketched symbol graphics.
            SketchLine oSketchLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(20, 0));

            SketchCircle oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(22, 0), 2);

            oSketch.GeometricConstraints.AddCoincident((SketchEntity)oSketchLine.EndSketchPoint, (SketchEntity)oSketchCircle);

            // Make the starting point of the sketch line the insertion point
            oSketchLine.StartSketchPoint.InsertionPoint = true;

            // Add a prompted text field at the center of the sketch circle.
            string sText = null;

            sText = "<Prompt>Enter text 1</Prompt>";
            Inventor.TextBox oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22, 0), sText);
            oTextBox.VerticalJustification   = VerticalTextAlignmentEnum.kAlignTextMiddle;
            oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter;

            oSketchedSymbolDef.ExitEdit(true);
        }
        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);
            }
        }