////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //Use: Returns Plane object from input entity. Supports Face, Workplane and Faces.
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static Plane GetPlane(object planarEntity)
        {
            ObjectTypeEnum type = GetInventorType(planarEntity);

            switch (type)
            {
            case ObjectTypeEnum.kFaceObject:
            case ObjectTypeEnum.kFaceProxyObject:

                Face face = planarEntity as Face;
                return(face.Geometry as Plane);

            case ObjectTypeEnum.kWorkPlaneObject:
            case ObjectTypeEnum.kWorkPlaneProxyObject:

                WorkPlane workplane = planarEntity as WorkPlane;
                return(workplane.Plane);

            case ObjectTypeEnum.kFacesObject:

                Face face1 = (planarEntity as Faces)[1];
                return(face1.Geometry as Plane);

            default:
                return(null);
            }
        }
예제 #2
0
        /////////////////////////////////////////////////////////////
        // Use: Inserts new sketch in part and copies content
        //      from input sketch
        /////////////////////////////////////////////////////////////
        public static PlanarSketch InsertSketch(PartDocument doc,
                                                PlanarSketch sketch,
                                                UnitVector xAxis,
                                                UnitVector yAxis,
                                                Point basePoint)
        {
            PartComponentDefinition compDef =
                doc.ComponentDefinition;

            WorkAxis wa1 = compDef.WorkAxes.AddFixed(
                basePoint, xAxis, _ConstructionWorkFeature);

            WorkAxis wa2 = compDef.WorkAxes.AddFixed(
                basePoint, yAxis, _ConstructionWorkFeature);

            WorkPlane wp = compDef.WorkPlanes.AddByTwoLines(
                wa1, wa2, _ConstructionWorkFeature);

            WorkPoint origin = compDef.WorkPoints.AddFixed(
                basePoint, _ConstructionWorkFeature);

            PlanarSketch newSketch =
                compDef.Sketches.AddWithOrientation(
                    wp, wa1, true, true, origin, false);

            sketch.CopyContentsTo(newSketch as Sketch);

            return(newSketch);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //Use: Returns Normal as UnitVetor for different type of input entities.
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static UnitVector GetNormal(object planarEntity)
        {
            ObjectTypeEnum type = GetInventorType(planarEntity);

            switch (type)
            {
            case ObjectTypeEnum.kFaceObject:
            case ObjectTypeEnum.kFaceProxyObject:

                Face face = planarEntity as Face;
                return(GetFaceNormal(face));

            case ObjectTypeEnum.kWorkPlaneObject:
            case ObjectTypeEnum.kWorkPlaneProxyObject:

                WorkPlane workplane = planarEntity as WorkPlane;
                return(workplane.Plane.Normal);

            case ObjectTypeEnum.kFacesObject:

                Face face1 = (planarEntity as Faces)[1];
                return(GetFaceNormal(face1));

            default:
                return(null);
            }
        }
예제 #4
0
        static public void project(SheetMetalComponentDefinition smcd, string name)
        {
            WorkPlane    wp = smcd.WorkPlanes["Шип_справа"];
            PlanarSketch ps = smcd.Sketches.Add(wp);

            ps.Name = name; ps.Visible = false;
            ps.ProjectedCuts.Add();
        }
예제 #5
0
        private void ExcuteAlign(PartDocument partDoc, WorkPlane refPlane, string paraName, int coeff)
        {
            PartComponentDefinition oPartCompDef;

            oPartCompDef = partDoc.ComponentDefinition;

            WorkAxis thisFaceAxis;

            thisFaceAxis = oPartCompDef.WorkAxes.AddByRevolvedFace(m_thisFace, false);
            Double thisDist = GetDistanceBetwLineAndFace(oPartCompDef, thisFaceAxis, refPlane);

            thisFaceAxis.Delete();

            WorkAxis withThisFaceAxis;

            withThisFaceAxis = oPartCompDef.WorkAxes.AddByRevolvedFace(m_withThisFace, false);
            Double withThisDist = GetDistanceBetwLineAndFace(oPartCompDef, withThisFaceAxis, refPlane);

            withThisFaceAxis.Delete();

            Double differ;

            differ = thisDist - withThisDist;

            AttributeSets atr = m_thisiFeature.AttributeSets;

            AttributeSet abs = atr["MyAttribSet"];

            Inventor.Attribute att            = abs["InternalName"];
            Inventor.Attribute footprint      = abs["Footprint"];
            string             footprintCheck = footprint.Value;

            string thisiFeatureName = att.Value;
            string oParameterName   = thisiFeatureName + ":" + paraName;

            foreach (iFeatureInput oInput in m_thisiFeature.iFeatureDefinition.iFeatureInputs)
            {
                if (oInput.Name == thisiFeatureName + ":" + paraName || oInput.Name == thisiFeatureName + ":" + paraName + ":2")
                {
                    iFeatureParameterInput oParamInput;
                    oParamInput = (iFeatureParameterInput)oInput;
                    Double newValue = oParamInput.Parameter.Value + coeff * differ;
                    oParamInput.Parameter.Value = newValue;
                }
            }
            if (footprintCheck == "Yes")
            {
                if (paraName == "y")
                {
                    MoveSketch(0, coeff * differ);
                }
                else
                {
                    MoveSketch(coeff * differ, 0);
                }
            }
            partDoc.Update2();
        }
예제 #6
0
        // create a feature
        private void createFeature()
        {
            PartDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                   mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject,
                                                                                    SystemOfMeasureEnum.kDefaultSystemOfMeasure,
                                                                                    DraftingStandardEnum.kDefault_DraftingStandard, null),
                                                   true) as PartDocument;

            // Get the XZ Plane
            WorkPlane oWorkPlane = oDoc.ComponentDefinition.WorkPlanes[2];

            PlanarSketch oSketch = oDoc.ComponentDefinition.Sketches.Add(oWorkPlane, false);

            TransientGeometry oTG = mApp.TransientGeometry;

            //Create some transient points used for defining the lines (see BRep Module)
            Point2d[] oPoints = new Point2d[5];

            oPoints[0] = oTG.CreatePoint2d(0, 0);
            oPoints[1] = oTG.CreatePoint2d(-10, 0);
            oPoints[2] = oTG.CreatePoint2d(-10, -10);
            oPoints[3] = oTG.CreatePoint2d(5, -10);
            oPoints[4] = oTG.CreatePoint2d(5, -5);

            //Add the sketchlines, coincident constraints will be created automatically
            //since the "Line.EndSketchPoint" are provided each time we create a new line
            SketchLine[] oLines = new SketchLine[5];

            oLines[0] = oSketch.SketchLines.AddByTwoPoints(oPoints[0], oPoints[1]);
            oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, oPoints[2]);
            oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, oPoints[3]);
            oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oPoints[4]);

            oSketch.SketchArcs.AddByCenterStartEndPoint(oTG.CreatePoint2d(0, -5), oLines[3].EndSketchPoint, oLines[0].StartSketchPoint, true);

            //Create a profile for the extrusion, here no need to worry since there is only
            //a single profile that is possible
            Profile oProfile = oSketch.Profiles.AddForSolid(true, null, null);



            // Definition Way:
            PartComponentDefinition oPartDocDef = oDoc.ComponentDefinition;

            // get ExtrudeFeatures collection
            ExtrudeFeatures extrudes = oPartDocDef.Features.ExtrudeFeatures;

            // Create an extrude definition in the new surface body
            ExtrudeDefinition extrudeDef = extrudes.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);

            // Modify the extent
            extrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);


            // Create the extrusion.
            ExtrudeFeature extrude = extrudes.Add(extrudeDef);
        }
예제 #7
0
        static public MirrorFeature addMirror(SheetMetalComponentDefinition smcd, ObjectCollection objs, string name, UnitVector vec)
        {
            SheetMetalFeatures smf = (SheetMetalFeatures)smcd.Features;
            WorkPlane          wp  = smcd.WorkPlanes.OfType <WorkPlane>().First(e => InvDoc.u.eq(vec, e.Plane.Normal));
            MirrorFeature      mir = smf.MirrorFeatures.Add(objs, wp, false, PatternComputeTypeEnum.kAdjustToModelCompute);

            mir.Name = name;
            return(mir);
        }
예제 #8
0
        public Sketch NewSketch(PartDocument part, KMainPlane plane, bool ProjectEdges = false)
        {
            // get the component definition
            PartComponentDefinition partDef = part.ComponentDefinition;

            //get the workplane
            WorkPlane workPlane = partDef.WorkPlanes[plane];

            //create a new sketch
            return(partDef.Sketches.Add(workPlane, ProjectEdges) as Sketch);
        }
        // ! Aggiunge il piano in mezzo alla lamiera
        public static WorkPlane addPlaneInTheMiddleOfBox(PartDocument oDoc)
        {
            SheetMetalComponentDefinition oComp = (SheetMetalComponentDefinition)oDoc.ComponentDefinition;

            try
            {
                return(oComp.WorkPlanes["Manual"]);
            }
            catch { }

            Box oRb = oComp.SurfaceBodies[1].RangeBox;

            TransientBRep oTransientBRep = iApp.TransientBRep;

            SurfaceBody oBody = oTransientBRep.CreateSolidBlock(oRb);

            NonParametricBaseFeature oBaseFeature = oComp.Features.NonParametricBaseFeatures.Add(oBody);

            FaceCollection oFaceColl = iApp.TransientObjects.CreateFaceCollection();

            foreach (Face f in oBaseFeature.SurfaceBodies[1].Faces)
            {
                WorkPlane tmpWp = oComp.WorkPlanes.AddByPlaneAndOffset(f, 0);

                //if (tmpWp.Plane.IsParallelTo[oComp.WorkPlanes[1].Plane])
                if (tmpWp.Plane.IsParallelTo[oComp.WorkPlanes[1].Plane])
                {
                    oFaceColl.Add(f);
                }

                tmpWp.Delete();
            }

            WorkPlane wpWork = null;

            if (oFaceColl.Count >= 2)
            {
                WorkPlane wp1 = oComp.WorkPlanes.AddByPlaneAndOffset(oFaceColl[1], 0);
                WorkPlane wp2 = oComp.WorkPlanes.AddByPlaneAndOffset(oFaceColl[2], 0);

                wpWork          = oComp.WorkPlanes.AddByTwoPlanes(wp1, wp2);
                wpWork.Name     = "wpWorkReference";
                wpWork.Grounded = true;
                wpWork.Visible  = false;

                oBaseFeature.Delete(false, true, true);

                wp1.Delete();
                wp2.Delete();
            }

            return(wpWork);
        }
예제 #10
0
        public void addProject()
        {
            try
            {
                m_asmCompDef = asmDoc.ComponentDefinition;
                invApp       = (Inventor.Application)asmDoc.Parent;
                tg           = invApp.TransientGeometry;
                smcd         = (SheetMetalComponentDefinition)m_asmCompDef.Occurrences[1].Definition;
                SheetMetalComponentDefinition smcd2 = (SheetMetalComponentDefinition)m_asmCompDef.Occurrences[2].Definition;
                //m_asmCompDef.Occurrences[1].Edit();
                CommandManager cmdMgr = ((Inventor.Application)asmDoc.Parent).CommandManager;
                FaceProxy      face;
                object         obj = cmdMgr.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Выберите плоскость эскиза:");
                objCol = invApp.TransientObjects.CreateObjectCollection();
                face   = (FaceProxy)obj;
                asmDoc.SelectSet.Select(m_asmCompDef.Occurrences[2]);
                //((PartDocument)smcd.Document).SelectSet.Select(m_asmCompDef.Occurrences[2].CreateGeometryProxy());
                //double[] pts = {face.PointOnFace.X,face.PointOnFace.Y,face.PointOnFace.Z};
                //double[] normals = {0,0,0};
                //face.Evaluator.GetNormalAtPoint(ref pts, ref normals);
                //Plane pl = invApp.TransientGeometry.CreatePlane(face.PointOnFace, invApp.TransientGeometry.CreateVector(normals[0], normals[1], normals[2]));
                //obj = m_asmCompDef.Occurrences[2].Definition.SurfaceBodies[1];
                //m_PartDoc.SelectSet.Select()
                obj = null;
                WorkPlane wp = smcd2.WorkPlanes[3];
                m_asmCompDef.Occurrences[1].CreateGeometryProxy(face, out obj);
                FaceProxy face2 = (FaceProxy)obj;
                ps = smcd.Sketches.Add(face2);
                ProjectedCut cut = ps.ProjectedCuts.Add();
                PlanarSketch pls = smcd2.Sketches.Add(smcd2.WorkPlanes[3]);
                m_asmCompDef.Occurrences[2].CreateGeometryProxy(pls, out obj);
                psp = (PlanarSketchProxy)obj;
                foreach (var item in ps.SketchLines)
                {
                    m_asmCompDef.Occurrences[1].CreateGeometryProxy(item, out obj);
                    psp.AddByProjectingEntity(obj);
                }
                //m_asmCompDef.Occurrences[2].CreateGeometryProxy(smcd.WorkPlanes[3],out obj);
                //m_asmCompDef.Occurrences[1].CreateGeometryProxy(ps,out obj);

                //psp.ProjectedCuts.Add();
                TransientGeometry tr = invApp.TransientGeometry;
                //cmdMgr.ControlDefinitions["SketchProjectCutEdgesCmd"].Execute();
                //enumerat = invApp.TransientGeometry.SurfaceSurfaceIntersection(m_asmCompDef.Occurrences[2].Definition.SurfaceBodies[1], pl);
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #11
0
        //Зеркальное отражение детали
        public void Mirror_Obj(RevolveFeature feature, PartDocument part)
        {
            PartComponentDefinition partCompDef = part.ComponentDefinition;
            PlanarSketch            sketch      = partCompDef.Sketches.Add(partCompDef.WorkPlanes[1]);

            sketch.Visible = false;
            TransientGeometry transGeom      = InventorApplication.TransientGeometry;
            SketchLine        line_1         = sketch.SketchLines.AddByTwoPoints(transGeom.CreatePoint2d(-6, -5), transGeom.CreatePoint2d(-6, 5));
            SketchLine        line_2         = sketch.SketchLines.AddByTwoPoints(transGeom.CreatePoint2d(6, -5), transGeom.CreatePoint2d(6, 5));
            WorkPlane         wp             = partCompDef.WorkPlanes.AddByTwoLines(line_1, line_2, true);
            ObjectCollection  obj_collection = InventorApplication.TransientObjects.CreateObjectCollection();

            obj_collection.Add(feature);
            MirrorFeature mirror = partCompDef.Features.MirrorFeatures.Add(obj_collection, wp, false, PatternComputeTypeEnum.kAdjustToModelCompute);
        }
예제 #12
0
        private void SetToolPlane(WorkPlane workPlane, ref StringBuilder code)
        {
            CurrentWorkPlane = workPlane;

            switch (CurrentWorkPlane)
            {
            case WorkPlane.LatheXz:
            {
            } break;

            default:
                throw new NotImplementedException();
            }

            code.AppendLine(NumericControl.CMDM_SpindleStop);
            code.AppendLine(NumericControl.CMDM_Lathe3Ax_On);
            code.AppendLine("G0G28H0");
        }
예제 #13
0
 public SketchInv() : base(entTypes.Sketch)
 {
     base.name = xml.getAttributeValue("Name");
     def       = doc.ComponentDefinition;
     ps        = u.findInCol <PlanarSketch>(def.Sketches, e => e.Name == name);
     if (ps == null)
     {
         namePlane = xml.getAttributeValue("Plane");
         pl        = u.findInCol <WorkPlane>(def.WorkPlanes, e => e.Name == namePlane);
         if (pl != null)
         {
             ps = def.Sketches.Add(pl);
         }
         ps.Name = name;
         update  = false;
     }
     else
     {
         update = true;
     }
     readXML();
     constraints.ps = ps;
 }
예제 #14
0
        private static void settoPiani(double v1, double v2, double modulo)
        {
            PartDocument ThisDoc = (PartDocument)iApp.ActiveDocument;

            PartComponentDefinition oPartCompDef = ThisDoc.ComponentDefinition;

            SurfaceBody osb = oPartCompDef.SurfaceBodies[1];

            WorkPlane mMinore = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(oPartCompDef.WorkPlanes[2], 0);

            mMinore.Name = "AsseMinore";

            WorkPlane mMaggiore = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(oPartCompDef.WorkPlanes[2], modulo);

            mMaggiore.Name = "AsseMaggiore";

            WorkPlane taglioTop = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(oPartCompDef.WorkPlanes[2], modulo - v2);

            taglioTop.Name = "taglioTop";

            WorkPlane taglioBottom = oPartCompDef.WorkPlanes.AddByPlaneAndOffset(oPartCompDef.WorkPlanes[2], v1);

            taglioBottom.Name = "taglioBottom";
        }
        public static void main(string path, ToolStripProgressBar pb1, ToolStripStatusLabel tstl1, ListView lv1)
        {
            // ! Istanza inventor
            getIstance();

            // ! Tutti gli ipt dentro la folder
            // ? oDoc = (PartDocument) iApp.ActiveDocument;
            string[] listFiles = System.IO.Directory.GetFiles(@path, "*.ipt");

            int counter = 0;

            pb1.Minimum = 0;
            pb1.Maximum = listFiles.Length;

            // ! Ciclo la lista ipt dentro la folder
            foreach (string file in listFiles)
            {
                counter++;

                pb1.Value = counter;

                if (System.IO.Path.GetExtension(file) == ".ipt")
                {
                    tstl1.Text = System.IO.Path.GetFileName(file);

                    // ! Apro il documento
                    PartDocument oDoc = (PartDocument)iApp.Documents.Open(@file);

                    // ! Imposto SheetMetalDocument
                    setSheetMetalDocument(oDoc);

                    // ! Imposto thickness
                    setThickness(oDoc);
                    //setThicknessFisso(oDoc, "Steel DX51D THK 1.5mm");

                    // ! Elimino raggiature
                    List <string> faceCollToKeep = deleteFillet(oDoc);
                    if (faceCollToKeep == null)
                    {
                        ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0);
                        item1.SubItems.Add("Errore nell'eliminazione delle raggiature");
                        lv1.Items.AddRange(new ListViewItem[] { item1 });

                        //oDoc.Close();
                        //continue;
                    }
                    else
                    {
                        // ! Elimino facce
                        deleteFace(oDoc, faceCollToKeep);

                        // ! Creo Profilo
                        bool profStatus = createProfile(oDoc);
                        if (!profStatus)
                        {
                            ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0);
                            item1.SubItems.Add("Errore nella creazione profilo");
                            lv1.Items.AddRange(new ListViewItem[] { item1 });

                            //oDoc.Close();
                            continue;
                        }

                        //!Creo Raggiature
                        createFillet(oDoc);
                    }

                    //!Cerco le lavorazioni
                    //IDictionary<Face, List<Lavorazione>> lavorazione = detectLavorazioni(oDoc);

                    //!Creo sketch lavorazioni
                    // List<string> nomeSketch = createSketchLavorazione(oDoc, lavorazione);

                    //!Elimino con direct le lavorazioni
                    //deleteLavorazione(oDoc);

                    //!Cut lavorazione
                    //createCutLavorazione(oDoc, nomeSketch);

                    //!Aggiungo piano nel mezzo
                    WorkPlane oWpReference = addPlaneInTheMiddleOfBox(oDoc);

                    //!Aggiungo proiezione cut
                    bool projCutStatus = addProjectCut(oDoc, oWpReference);
                    if (!projCutStatus)
                    {
                        ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0);
                        item1.SubItems.Add("Errore nella creazione della proiezione cut");
                        lv1.Items.AddRange(new ListViewItem[] { item1 });

                        //oDoc.Close();
                        continue;
                    }

                    // ! Coloro lato bello
                    setTexture(oDoc);

                    // ! Faccio lo sviluppo
                    bool sviluppoLamStatus = sviluppoLamiera(oDoc);
                    if (!sviluppoLamStatus)
                    {
                        ListViewItem item1 = new ListViewItem(System.IO.Path.GetFileName(file), 0);
                        item1.SubItems.Add("Errore nella creazione dello sviluppo");
                        lv1.Items.AddRange(new ListViewItem[] { item1 });
                    }

                    // ! Chiudo il documento
                    //oDoc.Close(true);

                    // Nascondo Sketch esportazione template
                    try
                    {
                        oDoc.ComponentDefinition.Sketches["EXP_ConvexHull"].Visible = false;
                    }
                    catch { }


                    // ! Salvo il documento
                    //oDoc.Save();
                    oDoc.Close();
                }
            }

            MessageBox.Show("Procedimento completato", "Creator Sheet Metal");
        }
예제 #16
0
        public static void main_(string path)
        {
            // ! prendo instanza Inventor
            getIstance();

            //oDoc = (PartDocument) iApp.ActiveDocument;
            string[] listFiles = System.IO.Directory.GetFiles(@path, "*.ipt");

            int counter = 0;

            foreach (string file in listFiles)
            {
                counter++;

                if (System.IO.Path.GetExtension(file) == ".ipt")
                {
                    PartDocument oDoc = (PartDocument)iApp.Documents.Open(@file);

                    // ! Imposto SheetMetalDocument
                    setSheetMetalDocument(oDoc);

                    // ! Imposto thickness
                    setThickness(oDoc);

                    // ! Elimino raggiature
                    List <string> faceCollToKeep = deleteFillet(oDoc);

                    // ! Elimino facce
                    deleteFace(oDoc, faceCollToKeep);

                    // ! Creo Profilo
                    createProfile(oDoc);

                    // ! Creo Raggiature
                    createFillet(oDoc);

                    // ! Cerco le lavorazioni
                    IDictionary <Face, List <Lavorazione> > lavorazione = detectLavorazioni(oDoc);

                    // ! Creo sketch lavorazioni
                    List <string> nomeSketch = createSketchLavorazione(oDoc, lavorazione);

                    // ! Elimino con direct le lavorazioni
                    deleteLavorazione(oDoc);

                    // ! Cut lavorazione
                    createCutLavorazione(oDoc, nomeSketch);

                    // ! Aggiungo piano nel mezzo
                    WorkPlane oWpReference = addPlaneInTheMiddleOfBox(oDoc);

                    // ! Aggiungo proiezione cut
                    addProjectCut(oDoc, oWpReference);

                    // ! Coloro lato bello
                    setTexture(oDoc);

                    oDoc.Close();
                }
            }
        }
예제 #17
0
        private double GetDistanceBetwLineAndFace(PartComponentDefinition partCompDef, WorkAxis workAxis, WorkPlane workPlane)
        {
            NameValueMap cont;

            cont = m_inventorApplication.TransientObjects.CreateNameValueMap();

            Double oDistance;

            oDistance = m_inventorApplication.MeasureTools.GetMinimumDistance(workAxis, workPlane, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference, cont);

            return(oDistance);
        }
예제 #18
0
        /////////////////////////////////////////////////////////////
        // Use: Creates new solid bodies affected by the future
        //      CoilFeature for Tapered Thread.
        /////////////////////////////////////////////////////////////
        private static bool CreateCoilBodyTapered(PartDocument doc,
                                                  ThreadInfo threadInfo,
                                                  Face threadedFace,
                                                  double depth,
                                                  bool isInteriorFace)
        {
            try
            {
                PartComponentDefinition compDef =
                    doc.ComponentDefinition;

                Vector direction = threadInfo.ThreadDirection;

                Point basePoint =
                    threadInfo.ThreadBasePoints[1] as Point;

                Point endPoint = _Tg.CreatePoint(
                    basePoint.X + direction.X,
                    basePoint.Y + direction.Y,
                    basePoint.Z + direction.Z);

                UnitVector yAxis = direction.AsUnitVector();

                UnitVector xAxis = Toolkit.GetOrthoVector(yAxis);

                WorkPoint wpt = compDef.WorkPoints.AddFixed(basePoint,
                                                            _ConstructionWorkFeature);

                WorkPlane wpl = compDef.WorkPlanes.AddFixed(basePoint,
                                                            xAxis, yAxis, _ConstructionWorkFeature);

                WorkAxis xWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         xAxis, _ConstructionWorkFeature);

                WorkAxis yWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         yAxis, _ConstructionWorkFeature);

                PlanarSketch sketch =
                    compDef.Sketches.AddWithOrientation(wpl,
                                                        xWa, true, true, wpt, false);

                Cone cone = threadedFace.Geometry as Cone;

                double revDepth =
                    depth / Math.Cos(cone.HalfAngle) *
                    (isInteriorFace ? -1.0 : 1.0);

                Line l1 = Toolkit.GetFaceSideDirection(threadedFace, xAxis);

                Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector());

                Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector());

                Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point;
                Point p2 = l1.IntersectWithCurve(l3, 0.0001)[1] as Point;

                Point p3 = _Tg.CreatePoint(
                    p2.X - xAxis.X * revDepth,
                    p2.Y - xAxis.Y * revDepth,
                    p2.Z - xAxis.Z * revDepth);

                Point p4 = _Tg.CreatePoint(
                    p1.X - xAxis.X * revDepth,
                    p1.Y - xAxis.Y * revDepth,
                    p1.Z - xAxis.Z * revDepth);

                SketchPoint skp1 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p1), false);

                SketchPoint skp2 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p2), false);

                SketchPoint skp3 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p3), false);

                SketchPoint skp4 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p4), false);

                sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                Profile profile = sketch.Profiles.AddForSolid(true,
                                                              null, null);

                RevolveFeature rev1 =
                    compDef.Features.RevolveFeatures.AddFull(
                        profile,
                        yWa,
                        PartFeatureOperationEnum.kCutOperation);

                sketch = compDef.Sketches.AddWithOrientation(wpl,
                                                             xWa, true, true, wpt, false);

                skp1 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p1), false);

                skp2 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p2), false);

                skp3 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p3), false);

                skp4 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p4), false);

                sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                profile = sketch.Profiles.AddForSolid(true, null, null);

                RevolveFeature rev2 =
                    compDef.Features.RevolveFeatures.AddFull(
                        profile,
                        yWa,
                        PartFeatureOperationEnum.kNewBodyOperation);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #19
0
        private void ButtonBuild_Click(object sender, EventArgs e)
        {
            if (FalseWrite)
            {
                MessageBox.Show("Неправильно заданы входные параметры\nИсправьте красные поля");
                return;
            }

            string docName = "Первая деталь";

            CreateDoc(docName);

            // Создание эскиза на YX
            PlanarSketch Sketch = CompDef[docName].Sketches.Add(CompDef[docName].WorkPlanes[3]);    // 1 - YZ ; 2 - ZX; 3 - XY

            // Создание массивов Точек, Линий, Дуг, Окружностей
            List <SketchPoint>  points  = new List <SketchPoint>();  // Точки
            List <SketchLine>   lines   = new List <SketchLine>();   // Линии
            List <SketchArc>    arcs    = new List <SketchArc>();    // Дуги
            List <SketchCircle> circles = new List <SketchCircle>(); // Окружности

            /////////////////////////////////////////////////////////// Выдавливание

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 0), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 5.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 10.0 / 10), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 15.0 / 10), false));
            arcs.Add(Sketch.SketchArcs.AddByCenterStartEndPoint(points[points.Count - 2], points[points.Count - 3], points[points.Count - 1], true));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 20.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(20.0 / 10, 20.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(20.0 / 10, 0), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[0], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(10.0 / 10, 10.0 / 10), false));
            circles.Add(Sketch.SketchCircles.AddByCenterRadius(points[points.Count - 1], 4.0 / 10));

            Profile ProfileMain = (Profile)Sketch.Profiles.AddForSolid();

            ExtrudeFeature ExtrudeDef = CompDef[docName].Features.ExtrudeFeatures.AddByDistanceExtent(
                /*Эскиз*/ ProfileMain,
                /*Длина в см*/ 10.0 / 10,
                /*Направление вдоль оси*/ PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
                /*Операция*/ PartFeatureOperationEnum.kJoinOperation,
                /*Эскиз*/ ProfileMain);

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

            WorkPlane WorkinPlace = CompDef[docName].WorkPlanes.AddByPlaneAndOffset(
                CompDef[docName].WorkPlanes[2], 20.0 / 10);

            WorkinPlace.Visible = false;
            Sketch = CompDef[docName].Sketches.Add(WorkinPlace);

            SketchLine line_axis;

            points.Clear();
            lines.Clear();

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-(10.0 - 5) / 10, 0), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-(10.0 - 5) / 10, 10.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-10.0 / 10, 10.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-10.0 / 10, 0), false));
            line_axis = Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]);

            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[0], points[points.Count - 1]));

            Profile        ProfileExternal = (Profile)Sketch.Profiles.AddForSolid();
            RevolveFeature revolvefeature  = CompDef[docName].Features.RevolveFeatures.AddFull(
                ProfileExternal,
                line_axis,
                PartFeatureOperationEnum.kCutOperation);

            Trans[docName].End();

            /////////////////////////////////////////////////////////// Вторая деталь

            docName = "Вторая деталь";
            CreateDoc(docName);

            Sketch = CompDef[docName].Sketches.Add(CompDef[docName].WorkPlanes[3]);

            points.Clear();
            lines.Clear();

            ///////////////////////////////////////////////// Шестиугольник

            double R = 2 * (4.0 / 10) / Math.Sqrt(3), Angle;

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(
                                                   1.65 * Math.Cos(((double)210 / 180) * Math.PI),
                                                   1.65 * Math.Sin(((double)210 / 180) * Math.PI)), true));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(points[0].Geometry.X + R, points[0].Geometry.Y), true));
            for (int i = 2; i < 7; i++)
            {
                Angle = ((((double)i - 2) * 60 + 120) / 180);
                points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(
                                                       points[i - 1].Geometry.X + R * Math.Cos(Angle * Math.PI),
                                                       points[i - 1].Geometry.Y + R * Math.Sin(Angle * Math.PI)), true));

                lines.Add(Sketch.SketchLines.AddByTwoPoints(points[i - 1], points[i]));
            }
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[6], points[1]));

            ProfileMain = (Profile)Sketch.Profiles.AddForSolid();

            ExtrudeDef = CompDef[docName].Features.ExtrudeFeatures.AddByDistanceExtent(
                /*Эскиз*/ ProfileMain,
                /*Длина*/ 10.0 / 10,
                /*Направление вдоль оси*/ PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
                /*Операция*/ PartFeatureOperationEnum.kJoinOperation,
                /*Эскиз*/ ProfileMain);

            ///////////////////////////////////////////////// Фаска
            ChamferFeature Fillet;

            EdgeCollection Edges = ThisApplication.TransientObjects.CreateEdgeCollection();

            int k = 0;

            foreach (SurfaceBody SurfBody in PartDoc[docName].ComponentDefinition.SurfaceBodies)
            {
                foreach (Edge Edge in SurfBody.Edges)
                {
                    if (k == 2)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 5)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 8)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 11)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 14)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 17)
                    {
                        Edges.Add(Edge);
                    }
                    k++;
                }
            }

            Fillet = CompDef[docName].Features.ChamferFeatures.AddUsingDistance(Edges, 2.0 / 10);

            ///////////////////////////////////////////////// СОПРЯЖЕНИЕ
            FilletFeature Fillet1;

            Edges.Clear();

            int n = 0;

            foreach (SurfaceBody SurfBody in PartDoc[docName].ComponentDefinition.SurfaceBodies)
            {
                foreach (Edge Edge in SurfBody.Edges)
                {
                    if (n == 18)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 20)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 21)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 23)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 26)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 27)
                    {
                        Edges.Add(Edge);
                    }

                    n++;
                }
            }

            Fillet1 = CompDef[docName].Features.FilletFeatures.AddSimple(Edges, /*Радиус*/ 1.0 / 10);

            // Заврешение транзакции
            Trans[docName].End();
        }
예제 #20
0
        public static void main(string path)
        {
            // ! prendo instanza Inventor
            getIstance();

            PartDocument oDoc = (PartDocument)iApp.ActiveDocument;

            // ! Imposto SheetMetalDocument
            setSheetMetalDocument(oDoc);

            // ! Imposto thickness
            setThickness(oDoc);

            SheetMetalComponentDefinition oComp = (SheetMetalComponentDefinition)oDoc.ComponentDefinition;

            WorkPlane     oWpReference = null;
            List <string> nameWp       = new List <string>();
            bool          manual       = false;

            foreach (WorkPlane oWp in oComp.WorkPlanes)
            {
                nameWp.Add(oWp.Name);
                if (oWp.Name == "manualPlane")
                {
                    oWpReference = oWp;
                    manual       = true;
                }
            }

            if (!manual)
            {
                // ! Elimino raggiature
                List <string> faceCollToKeep = deleteFillet(oDoc);

                // ! Elimino facce
                deleteFace(oDoc, faceCollToKeep);

                // ! Creo Profilo
                createProfile(oDoc);

                // ! Creo Raggiature
                createFillet(oDoc);

                // ! Cerco le lavorazioni
                IDictionary <Face, List <Lavorazione> > lavorazione = detectLavorazioni(oDoc);

                // ! Creo sketch lavorazioni
                List <string> nomeSketch = createSketchLavorazione(oDoc, lavorazione);

                // ! Elimino con direct le lavorazioni
                deleteLavorazione(oDoc);

                // ! Cut lavorazione
                createCutLavorazione(oDoc, nomeSketch);

                // ! Aggiungo piano nel mezzo
                oWpReference = addPlaneInTheMiddleOfBox(oDoc);

                // ! Aggiungo proiezione cut
                addProjectCut(oDoc, oWpReference, manual);

                // ! Coloro lato bello
            }
            else
            {
                addProjectCut(oDoc, oWpReference, manual);
            }

            setTexture(oDoc);

            oDoc.Close();
        }
예제 #21
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]);
                }
            }
        }
예제 #22
0
        public override void OnExecute(Document document, NameValueMap context, bool succeeded)
        {
            PartDocument oPartDoc;

            oPartDoc = (PartDocument)document;

            PartComponentDefinition oPartCompDef;

            oPartCompDef = oPartDoc.ComponentDefinition;

            if (m_direction == 0)
            {
                MessageBox.Show("软件运行出现错误!");
                return;
            }

            switch (m_direction)
            {
            case 1:
                m_typeNum = 1;
                break;

            case 2:
                m_typeNum = 2;
                break;

            case 3:;
                this.GetAlignType(oPartCompDef);
                break;
            }

            if (m_typeNum == 0)
            {
                MessageBox.Show("软件运行出现错误!");
                return;
            }

            if (m_typeNum == 3)
            {
                this.ExcuteAlign(oPartDoc, m_UCS.YZPlane, "x", 1);
                this.ExcuteAlign(oPartDoc, m_UCS.XZPlane, "y", -1);
            }
            else
            {
                if (m_typeNum == 11)
                {
                    this.ExcuteAlign(oPartDoc, m_UCS.YZPlane, "y", 1);
                    this.ExcuteAlign(oPartDoc, m_UCS.XZPlane, "x", 1);
                }
                else
                {
                    switch (m_typeNum)
                    {
                    case 1:
                        m_refPlane = m_UCS.XZPlane;
                        m_paraName = "y";
                        m_coeff    = -1;
                        break;

                    case 2:
                        m_refPlane = m_UCS.YZPlane;
                        m_paraName = "x";
                        m_coeff    = -1;
                        break;

                    case 4:
                        m_refPlane = m_UCS.YZPlane;
                        m_paraName = "x";
                        m_coeff    = -1;
                        break;

                    case 5:
                        m_refPlane = m_UCS.YZPlane;
                        m_paraName = "x";
                        m_coeff    = 1;
                        break;

                    case 6:
                        m_refPlane = m_UCS.YZPlane;
                        m_paraName = "y";
                        m_coeff    = -1;
                        break;

                    case 7:
                        m_refPlane = m_UCS.XZPlane;
                        m_paraName = "x";
                        m_coeff    = 1;
                        break;

                    case 8:
                        m_refPlane = m_UCS.XZPlane;
                        m_paraName = "y";
                        m_coeff    = 1;
                        break;

                    case 9:
                        m_refPlane = m_UCS.XZPlane;
                        m_paraName = "x";
                        m_coeff    = -1;
                        break;

                    case 10:
                        m_refPlane = m_UCS.XZPlane;
                        m_paraName = "y";
                        m_coeff    = -1;
                        break;

                    case 12:
                        m_refPlane = m_UCS.YZPlane;
                        m_paraName = "y";
                        m_coeff    = 1;
                        break;
                    }

                    this.ExcuteAlign(oPartDoc, m_refPlane, m_paraName, m_coeff);
                }
            }
        }
예제 #23
0
        private void Button1_Click(object sender, EventArgs e)
        {
            PartDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                   mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject,
                                                                                    SystemOfMeasureEnum.kDefaultSystemOfMeasure,
                                                                                    DraftingStandardEnum.kDefault_DraftingStandard, null),
                                                   true) as PartDocument;

            // Get the XZ Plane
            WorkPlane oWorkPlane = oDoc.ComponentDefinition.WorkPlanes[2];

            PlanarSketch oSketch = oDoc.ComponentDefinition.Sketches.Add(oWorkPlane, false);

            TransientGeometry oTG = mApp.TransientGeometry;

            //Create some transient points used for defining the lines (see BRep Module)
            Point2d[] oPoints = new Point2d[5];

            oPoints[0] = oTG.CreatePoint2d(0, 0);
            oPoints[1] = oTG.CreatePoint2d(-10, 0);
            oPoints[2] = oTG.CreatePoint2d(-10, -10);
            oPoints[3] = oTG.CreatePoint2d(5, -10);
            oPoints[4] = oTG.CreatePoint2d(5, -5);

            //Add the sketchlines, coincident constraints will be created automatically
            //since the "Line.EndSketchPoint" are provided each time we create a new line
            SketchLine[] oLines = new SketchLine[5];

            oLines[0] = oSketch.SketchLines.AddByTwoPoints(oPoints[0], oPoints[1]);
            oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, oPoints[2]);
            oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, oPoints[3]);
            oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oPoints[4]);

            oSketch.SketchArcs.AddByCenterStartEndPoint(oTG.CreatePoint2d(0, -5), oLines[3].EndSketchPoint, oLines[0].StartSketchPoint, true);

            //Create a profile for the extrusion, here no need to worry since there is only
            //a single profile that is possible
            Profile oProfile = oSketch.Profiles.AddForSolid(true, null, null);

            //this is the old way, i.e. create the extrude feature directly. it is still supported for backward compatibility
            //ExtrudeFeature oExtrude = oDoc.ComponentDefinition.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile,
            //    5.0, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, 0.0);


            // Definition Way:
            PartComponentDefinition oPartDocDef = oDoc.ComponentDefinition;

            // get ExtrudeFeatures collection
            ExtrudeFeatures extrudes = oPartDocDef.Features.ExtrudeFeatures;

            // Create an extrude definition in the new surface body
              ExtrudeDefinition extrudeDef = extrudes.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation);

            // Modify the extent and taper angles.
            extrudeDef.SetDistanceExtent(8, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            extrudeDef.SetDistanceExtentTwo(20);
            extrudeDef.TaperAngle    = "-2 deg";
            extrudeDef.TaperAngleTwo = "-10 deg";
             
            // Create the extrusion.
            ExtrudeFeature extrude = extrudes.Add(extrudeDef);

            //Fit the view programmatically
            Camera oCamera = mApp.ActiveView.Camera;

            oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation;
            oCamera.Apply();

            mApp.ActiveView.Fit(true);
        }