Ejemplo n.º 1
0
        public void PartDocument_IsReturned()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var      path            = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;
            Document doc             = app.Documents.Add(DocumentTypeEnum.kPartDocumentObject, path + "Standard.ipt", true);

            var doc2 = doc.ReturnSpecificDocumentObject();

            //var tt = doc2.GetPropertyValue("Author");
            var tt = PropertyShim.GetPropertyValue(doc2, "Author");
            //only exists in ParDocuments
            PartComponentDefinition test = null;

            try
            {
                test = doc2.ComponentDefinition;
            }
            catch { }

            try
            {
                Assert.IsNotNull(test);
            }
            finally { doc.Close(true); }
        }
Ejemplo n.º 2
0
        public override void CreateModule(ParameterBase Parameter)
        {
            parCylineDoor = Parameter as ParCylinderDoor;
            if (parCylineDoor == null)
            {
                return;
            }
            init();
            PartDocument            part    = InventorTool.CreatePart();
            PartComponentDefinition partDef = part.ComponentDefinition;
            PlanarSketch            osketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
            SketchEllipticalArc     Arc1    = osketch.SketchEllipticalArcs.Add(InventorTool.Origin, InventorTool.Left, parCylineDoor.DoorRadius, parCylineDoor.InRadius, 0, Math.PI / 2);
            SketchEllipticalArc     Arc2    = osketch.SketchEllipticalArcs.Add(InventorTool.Origin, InventorTool.Left, parCylineDoor.DoorRadius + parCylineDoor.Thickness, parCylineDoor.InRadius + parCylineDoor.Thickness, 0, Math.PI / 2);

            osketch.GeometricConstraints.AddConcentric((SketchEntity)Arc1, (SketchEntity)Arc2);
            SketchLine Line1 = osketch.SketchLines.AddByTwoPoints(Arc1.StartSketchPoint, Arc2.StartSketchPoint);
            SketchLine Line2 = osketch.SketchLines.AddByTwoPoints(Arc1.EndSketchPoint, Arc2.EndSketchPoint);

            osketch.GeometricConstraints.AddHorizontalAlign(Arc1.StartSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddVerticalAlign(Arc1.EndSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddHorizontal((SketchEntity)Line1);
            osketch.GeometricConstraints.AddVertical((SketchEntity)Line2);
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, true, InventorTool.TranGeo.CreatePoint2d(-parCylineDoor.DoorRadius / 2, 0));
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, false, InventorTool.TranGeo.CreatePoint2d(0, -parCylineDoor.InRadius / 2));

            Point2d p = InventorTool.TranGeo.CreatePoint2d((Line1.StartSketchPoint.Geometry.X + Line1.EndSketchPoint.Geometry.X) / 2 + 1, (Line1.StartSketchPoint.Geometry.Y + Line1.EndSketchPoint.Geometry.Y) / 2 + 1);

            osketch.DimensionConstraints.AddTwoPointDistance(Line1.StartSketchPoint, Line1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);
            Profile        profile = osketch.Profiles.AddForSolid();
            RevolveFeature revolve = partDef.Features.RevolveFeatures.AddFull(profile, Line1, PartFeatureOperationEnum.kNewBodyOperation);
        }
Ejemplo n.º 3
0
        private void getInsertFace(PartComponentDefinition oPartCompDef)
        {
            switch (m_insertPlane)
            {
            case 1:
                m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[5];
                break;

            case 2:
                m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[4];
                break;

            case 3:
                m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[3];
                break;

            case 4:
                m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[2];
                break;

            case 5:
                m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[1];
                break;

            case 6:
                m_insertFace = oPartCompDef.Features.ExtrudeFeatures["拉伸1"].Faces[6];
                break;
            }
        }
Ejemplo n.º 4
0
        }  //Main form closing

        private void assemble()
        {
            try
            {
                path = var_es._Doc.FullFileName.Remove(var_es._Doc.FullFileName.Length - 4);

                //создаём новый AssemblyDocument
                assemb_doc = (AssemblyDocument)var_es.InventorApp.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject, var_es.InventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kAssemblyDocumentObject), false);
                AssemblyComponentDefinition assemb_doc_Comp = assemb_doc.ComponentDefinition;

                //сохраняем созданий AssemblyDocument
                assemb_doc.SaveAs(path + @"/Shaft.iam", true);

                //Создаём матрицу
                TransientGeometry TG     = var_es.InventorApp.TransientGeometry;
                Matrix            matrix = TG.CreateMatrix();

                //привязываем наш AssemblyDocument в браузере к AssemblyDocument, который открыл пользователь
                var_es.part_doc = (PartDocument)var_es.InventorApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, var_es.InventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true);
                PartComponentDefinition doc_def = var_es.part_doc.ComponentDefinition;
            }
            catch (Exception e3)
            {
                MessageBox.Show(e3.ToString());
            }
        }
Ejemplo n.º 5
0
        private void ExtrudeSketch(int x, int y)
        {
            //PartDocument oPartDoc = default(PartDocument);
            //oPartDoc = (PartDocument)_invApp.Documents.Add(Inventor.DocumentTypeEnum.kPartDocumentObject,_invApp.FileManager.GetTemplateFile(Inventor.DocumentTypeEnum.kPartDocumentObject));
            PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument;

            PartComponentDefinition oCompDef = default(PartComponentDefinition);

            oCompDef = oPartDoc.ComponentDefinition;

            PlanarSketch oSketch = default(PlanarSketch);

            oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[1]);
            oSketch.SketchLines.AddAsTwoPointRectangle(_invApp.TransientGeometry.CreatePoint2d(-x, -y), _invApp.TransientGeometry.CreatePoint2d(x, y));

            Profile oProfile = default(Profile);

            oProfile = oSketch.Profiles.AddForSolid();

            ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition);

            oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, Inventor.PartFeatureOperationEnum.kJoinOperation);
            oExtrudeDef.SetDistanceExtent(5, Inventor.PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);

            ExtrudeFeature oExtrude = default(ExtrudeFeature);

            oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef);
        }
Ejemplo n.º 6
0
        public void ChangeParam(Document doc, string paramName, string paramValue)
        {
            UserParameters userParams;

            if (doc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
            {
                LogTrace("Part Document");
                PartComponentDefinition partComponentDef = ((PartDocument)doc).ComponentDefinition;
                Parameters docParams = partComponentDef.Parameters;
                userParams = docParams.UserParameters;
            }

            else
            {
                LogTrace("Unknown Document");
                // unsupported doc type, throw exception
                throw new Exception("Unsupported document type: " + doc.DocumentType.ToString());
            }

            using (new HeartBeat())
            {
                try
                {
                    LogTrace($"Setting {paramName} to {paramValue}");
                    UserParameter userParam = userParams[paramName];
                    userParam.Expression = paramValue;
                }
                catch (Exception e)
                {
                    LogError("Cannot update '{0}' parameter. ({1})", paramName, e.Message);
                }
            }
        }
Ejemplo n.º 7
0
        private MateiMateDefinition findAxis(PartComponentDefinition def, Edge ed)
        {
            if (ed.TangentiallyConnectedEdges.Count == 1)
            {
                Face f = (ed.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ed.Faces[1] : ed.Faces[2];
                return(def.iMateDefinitions.AddMateiMateDefinition(f, 0, InferredTypeEnum.kInferredLine));
            }
            SelectionFilterEnum[] sels = new SelectionFilterEnum[] { SelectionFilterEnum.kWorkAxisFilter };
            Arc3d             c        = ed.Geometry as Arc3d;
            ObjectsEnumerator col      = def.FindUsingPoint(ed.PointOnEdge, ref sels, c.Radius * 5, false);
            WorkAxis          ax       = null;

            foreach (var item in col.OfType <WorkAxis>())
            {
                ax = item;
                //Face f = (ed.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ed.Faces[1]: ed.Faces[2];
                if (ax.DefinitionType == WorkAxisDefinitionEnum.kNormalToSurfaceWorkAxis)
                {
                    return(def.iMateDefinitions.AddMateiMateDefinition(ax, 0, InferredTypeEnum.kInferredLine));
                }
                ax = null;
            }
            if (ax == null)
            {
                return(iMate__(ed, def));
            }
            return(null);
        }
Ejemplo n.º 8
0
        private void CreateInvLayout()
        {
            CreateLayoutPartFile();

            Inventor.AssemblyComponentDefinition componentDefinition = InventorServices.Persistence.PersistenceManager.ActiveAssemblyDoc.ComponentDefinition;
            TransformationMatrix = InventorApplication.TransientGeometry.CreateMatrix();
            ComponentOccurrence  componentOccurrence = componentDefinition.Occurrences.Add(LayoutPartPath, TransformationMatrix);
            ComponentOccurrences occurrences         = componentDefinition.Occurrences;

            //TODO This is janky.  Don't need to assume that we are starting in an empty assembly file.
            ComponentOccurrence     layoutOccurrence          = occurrences[1];
            PartComponentDefinition layoutComponentDefinition = (PartComponentDefinition)layoutOccurrence.Definition;

            for (int i = 0; i < ModulePoints.Count; i++)
            {
                WorkPoint workPoint = layoutComponentDefinition.WorkPoints.AddFixed(ModulePoints[i], false);
                workPoint.Grounded = true;
                workPoint.Visible  = false;
                //Inventor's API documentation is so bad!
                object workPointProxyObject;
                layoutOccurrence.CreateGeometryProxy(workPoint, out workPointProxyObject);
                LayoutWorkPointProxies.Add((WorkPointProxy)workPointProxyObject);
                LayoutWorkPoints.Add(workPoint);
            }

            LayoutWorkPlane          = layoutComponentDefinition.WorkPlanes.AddByThreePoints(layoutWorkPoints[0], layoutWorkPoints[1], layoutWorkPoints[2]);
            LayoutWorkPlane.Grounded = true;
            LayoutWorkPlane.Visible  = false;
            object wPlaneProxyObject;

            layoutOccurrence.CreateGeometryProxy(LayoutWorkPlane, out wPlaneProxyObject);
            ModuleWorkPlaneProxyAssembly = (WorkPlaneProxy)wPlaneProxyObject;
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Updates the material for all parts
        /// </summary>
        public void updateMaterial()
        {
            AssemblyDocument    assemblyDoc = (AssemblyDocument)invApp.ActiveDocument;
            DocumentsEnumerator allRefDocs  = assemblyDoc.AllReferencedDocuments;

            // Find all part files and change the material
            foreach (Document oDoc in allRefDocs)
            {
                if (oDoc.DocumentType.Equals(DocumentTypeEnum.kPartDocumentObject))
                {
                    PartDocument            partDoc = (PartDocument)oDoc;
                    PartComponentDefinition partDef = partDoc.ComponentDefinition;

                    // Try to set the material
                    try
                    {
                        partDef.Material.Name = material;
                    }
                    catch
                    {
                    }
                    finally
                    {
                        // Release objects
                        partDoc = null;
                        partDef = null;
                    }
                }
            }

            // Release objects
            allRefDocs  = null;
            assemblyDoc = null;
        }
 public PartEventsLib(Application inventorApp, PartComponentDefinition
                      partComponentDef)
 {
     this.inventorApp = inventorApp;
     PartEvents       = partComponentDef.PartEvents;
     Activate();
 }
Ejemplo n.º 12
0
        private void Feature3(int x, int y)
        {
            PartDocument oPartDoc = (PartDocument)_invApp.ActiveDocument;

            oPartDoc.UnitsOfMeasure.LengthUnits = Inventor.UnitsTypeEnum.kMillimeterLengthUnits;
            PartComponentDefinition oCompDef = default(PartComponentDefinition);

            oCompDef = oPartDoc.ComponentDefinition;

            PlanarSketch oSketch = default(PlanarSketch);

            oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]);
            oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), 6);
            oSketch.SketchCircles.AddByCenterRadius(_invApp.TransientGeometry.CreatePoint2d(0, 0), 17.5);

            Profile oProfile = default(Profile);

            oProfile = oSketch.Profiles.AddForSolid();

            ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition);

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

            ExtrudeFeature oExtrude = default(ExtrudeFeature);

            oExtrude = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef);
        }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 14
0
        private void CreatePart_Click(object sender, EventArgs e)
        {
            if (inventor == null)
            {
                MessageBox.Show("No inventor instance detected", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            PartDocument doc = inventor.Documents.Add(DocumentTypeEnum.kPartDocumentObject, null, true) as PartDocument;

            doc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"]["Author"].Value = "Vladyslav Romanchuk";

            //User-defined property
            doc.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"].Add("Parts R Us", "Supplier");
            PartComponentDefinition partDefinition = (PartComponentDefinition)doc.ComponentDefinition;

            // Create a 2D sketch on the X-Y plane.
            PlanarSketch      sketch1 = (PlanarSketch)partDefinition.Sketches.Add(partDefinition.WorkPlanes[3]);
            TransientGeometry tg      = inventor.TransientGeometry;

            Point2d[] points = new Point2d[5] {
                tg.CreatePoint2d(0, 0), tg.CreatePoint2d(0, 20), tg.CreatePoint2d(20, 20), tg.CreatePoint2d(20, -10), tg.CreatePoint2d(10, -10)
            };
            SketchLine[] lines = new SketchLine[5];
            lines[0] = sketch1.SketchLines.AddByTwoPoints(points[0], points[1]);
            for (int i = 1; i < lines.Length - 1; i++)
            {
                lines[i] = sketch1.SketchLines.AddByTwoPoints(lines[i - 1].EndSketchPoint, points[i + 1]);
            }
            sketch1.SketchArcs.AddByCenterStartEndPoint(tg.CreatePoint2d(10, 0), lines[3].EndSketchPoint, lines[0].StartSketchPoint, false);

            //Extrude
            Profile           profile           = sketch1.Profiles.AddForSolid();
            ExtrudeDefinition extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation);

            extrudeDefinition.SetDistanceExtent(6, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);
            ExtrudeFeature extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition);

            //second scatch
            Face topCap = extrude.EndFaces[1];

            sketch1 = partDefinition.Sketches.Add(topCap, false);

            Point2d      center = sketch1.ModelToSketchSpace(tg.CreatePoint(2.5, 1.5, 1.5));
            SketchCircle Circle = sketch1.SketchCircles.AddByCenterRadius(center, 1);

            profile           = sketch1.Profiles.AddForSolid(true, null, null);
            extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kJoinOperation);
            extrudeDefinition.SetDistanceExtent(4, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);
            extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition);
            Edges          cylinderEdges = extrude.SideFaces[1].Edges;
            EdgeCollection filletEdges   = inventor.TransientObjects.CreateEdgeCollection(null);

            //foreach (var el in cylinderEdges)
            //    filletEdges.Add(el);
            filletEdges.Add(cylinderEdges[2]);
            //adding fillet
            partDefinition.Features.FilletFeatures.AddSimple(filletEdges, 0.25, false, false, false, false, false, true);
            //doc.SaveAs("D:\\SaveTest2.ipt", false);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Everything you need to know about RevolveFeatures
        /// </summary>
        /// <returns>List of "RevolveFeature"s</returns>
        public List <RevolveFeature> GetRevolveFeatures()
        {
            PartComponentDefinition partComponentDefinition = InventorDocument.ComponentDefinition;

            List <RevolveFeature> toReturn = new List <RevolveFeature>();

            foreach (RevolveFeature revolveFeature in partComponentDefinition.Features.RevolveFeatures)
            {
                toReturn.Add(revolveFeature);

                //MessageBox.Show(revolveFeature.Parameters[revolveFeature.Parameters.Count].Value.ToString());
                if (revolveFeature.ExtentType == PartFeatureExtentEnum.kFullSweepExtent) //wenn volle Rotation
                {
                    List <string> msg = new List <string>
                    {
                        revolveFeature.ExtendedName,          //z.B. "Neue Rotation 45°"
                        revolveFeature.Name,                  //z.B. "Umdrehung1"
                        revolveFeature.Profile.Type
                        .ToString(),                          //enthält das Profil (Profil.Parent sollte die Skizze enthalten)
                        revolveFeature.ExtentType
                        .ToString(),                          // enthält die möglichen ExtentType typen. Z.B. kAngleExtent oder kFullSweepExtent.
                        revolveFeature.Operation
                        .ToString(),                          // z.B. kNewBodyOperation, kIntersectOperation, kCutOperation, kJoinOperation
                        revolveFeature.AxisEntity.ToString(), // gibt die Rotationsachse zurück
                        "360"                                 // Der Rotationswinkel
                    };
                }
                if (revolveFeature.ExtentType == PartFeatureExtentEnum.kAngleExtent
                    ) //wenn drehung mit bestimmten Winkel
                {
                    double Rotationswinkel = 360 / (2 * Math.PI) *
                                             double.Parse(revolveFeature.Parameters[revolveFeature.Parameters.Count]
                                                          .Value.ToString());

                    List <string> msg = new List <string>
                    {
                        revolveFeature.ExtendedName,          //z.B. "Neue Rotation 45°"
                        revolveFeature.Name,                  //z.B. "Umdrehung1"
                        revolveFeature.Profile.Type
                        .ToString(),                          //enthält das Profil (Profil.Parent sollte die Skizze enthalten)
                        revolveFeature.ExtentType
                        .ToString(),                          // enthält die möglichen ExtentType typen. Z.B. kAngleExtent oder kFullSweepExtent.
                        revolveFeature.Operation
                        .ToString(),                          // z.B. kNewBodyOperation, kIntersectOperation, kCutOperation, kJoinOperation
                        revolveFeature.AxisEntity.ToString(), // gibt die Rotationsachse zurück
                        revolveFeature.Parameters[revolveFeature.Parameters.Count]
                        .Name,                                // Der Rotationswinkelparametername
                        Rotationswinkel.ToString()            // Der Rotationswinkelwert
                    };
                }

                if (revolveFeature.Profile.Count > 1)
                {
                    NotImplementedTypes.Add("revolveFeature " + revolveFeature.Name +
                                            ": Only 1 Profile per Sketch");
                }
            }
            return(toReturn);
        }
Ejemplo n.º 16
0
        public PartParameterList(Inventor.Application currentApp)
        {
            invApp = currentApp;

            // Must Detect if in In-Place Edit Session
            partDoc        = (PartDocument)invApp.ActiveEditDocument;
            currentPartDef = partDoc.ComponentDefinition;
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        public void selEdge(string promt, SelectionFilterEnum filter)
        {
            PartFeature pf = CmdMgr.Pick(filter, promt) as PartFeature;
            HoleFeature hf = pf as HoleFeature;

            if (hf == null)
            {
                return;
            }
            //ICollection<Edge> col = null;
            foreach (Face item in hf.SideFaces)
            {
                Edge ed = checkBox1.Checked ? item.Edges[2] : item.Edges[1];
                edges.Add(ed);
            }
//             System.Collections.IEnumerator en = PartCompDef.Features.GetEnumerator();
//             en.Reset();
//             while(en.Current != null)
//             {
//                en.
//             }
            PartCompDef = hf.Parent as PartComponentDefinition;
//             for (int i = 1; i < PartCompDef.Features.Count; i++)
//          {
//                 MirrorFeature mf = PartCompDef.Features[i] as MirrorFeature;
//                 if (mf == null) continue;
//                 HoleFeature holeF = PartCompDef.Features[i - 1] as HoleFeature;
//                 if (hf == null)
//                     holeF = PartCompDef.Features[i - 2] as HoleFeature;
//                 else
//                     continue;
//                 foreach (PartFeature item in mf.ParentFeatures)
//                 {
//                     if (item is HoleFeature && holeF.Equals(item))
//                     {
//                         if (mf.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface)
//                             edges.Add(mf.Faces[1].Edges[1]);
//                     }
//                 }
//          }
            foreach (MirrorFeature item in PartCompDef.Features.MirrorFeatures)
            {
                foreach (PartFeature m in item.ParentFeatures)
                {
                    if (m.Equals(hf))
                    {
                        if (item.Faces[1].SurfaceType != SurfaceTypeEnum.kCylinderSurface)
                        {
                            continue;
                        }
                        Edge ed = checkBox1.Checked ? item.Faces[1].Edges[2] : item.Faces[1].Edges[1];
                        edges.Add(ed);
                    }
                }
            }
        }
Ejemplo n.º 19
0
        /////////////////////////////////////////////////////////////
        // Use: Creates CoilFeature that represents the modelized
        //      Thread.
        /////////////////////////////////////////////////////////////
        private static bool CreateCoilFeature(PartDocument doc,
                                              Profile profile,
                                              Vector threadDirection,
                                              Point basePoint,
                                              bool rightHanded,
                                              double taper,
                                              double pitch,
                                              double extraPitch)
        {
            try
            {
                PartComponentDefinition compDef =
                    doc.ComponentDefinition;

                WorkAxis wa = compDef.WorkAxes.AddFixed(
                    basePoint,
                    threadDirection.AsUnitVector(),
                    _ConstructionWorkFeature);

                double height = threadDirection.Length + 2 * pitch;

                double coilPitch = pitch * (100 + extraPitch) * 0.01;

                CoilFeature coil =
                    compDef.Features.CoilFeatures.AddByPitchAndHeight(
                        profile,
                        wa,
                        coilPitch,
                        height,
                        PartFeatureOperationEnum.kCutOperation,
                        false,
                        !rightHanded,
                        taper,
                        false,
                        0,
                        0,
                        false,
                        0,
                        0);

                ObjectCollection bodies =
                    _Application.TransientObjects.
                    CreateObjectCollection(null);

                bodies.Add(
                    compDef.SurfaceBodies[compDef.SurfaceBodies.Count]);

                coil.SetAffectedBodies(bodies);

                return(coil.HealthStatus == HealthStatusEnum.kUpToDateHealth);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 20
0
        //function to draw shaft with all features
        public static void Shaft()
        {
            partDef = var_es.part_doc.ComponentDefinition;
            tg      = var_es.InventorApp.TransientGeometry;
            sketch  = partDef.Sketches.Add(partDef.WorkPlanes[3]);
            Edges   = default(EdgeCollection);
            Edges   = var_es.InventorApp.TransientObjects.CreateEdgeCollection();
            S_Face  = null;
            E_Face  = null;
            Side_F  = null;
            int i = 0, j = 1;

            foreach (var part in var_es.list)
            {
                S_Face = null;
                E_Face = null;
                var obj = part;
                if (obj != null)
                {
                    obj.Create_BR(tg, ref sketch, Edges, ref S_Face, ref E_Face, ref partDef);
                }
                try
                {
                    if (var_es.chamfer_list.Count != 0)
                    {
                        S_Face = obj.Start_face;
                        E_Face = obj.End_face;
                        if (part is Pol)
                        {
                            Side_F = obj.Side_faces;
                        }

                        Edges = var_es.InventorApp.TransientObjects.CreateEdgeCollection();
                        if (var_es.chamfer_list[i] != null)
                        {
                            Create feature = var_es.chamfer_list[i];
                            feature.Create_BR(tg, ref sketch, Edges, ref S_Face, ref E_Face, ref partDef);
                        }
                        Edges  = var_es.InventorApp.TransientObjects.CreateEdgeCollection();
                        S_Face = obj.Start_face;
                        E_Face = obj.End_face;
                        if (var_es.chamfer_list[j] != null)
                        {
                            Create feature = var_es.chamfer_list[j];
                            feature.Create_BR(tg, ref sketch, Edges, ref S_Face, ref E_Face, ref partDef);
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
                i += 2;
                j += 2;
            }
        }
Ejemplo n.º 21
0
        public override void CreateModule(ParameterBase Parameter)
        {
            parCylinder = Parameter as ParCylinder;
            if (parCylinder == null)
            {
                return;
            }
            init();


            PartDocument            part = InventorTool.CreatePart();
            PartComponentDefinition partDef = part.ComponentDefinition;
            PlanarSketch            osketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
            SketchEllipticalArc     Arc1, Arc2;
            SketchLine Line1, Line2;

            CreateLines(osketch, out Arc1, out Line1, parCylinder.CapRadius, parCylinder.InRadius, parCylinder.Length);

            //SketchLine line5= offsetLine<SketchLine>(osketch, Line1, 2, true);
            //SketchOffsetSpline arc5 = (SketchOffsetSpline)offsetLine(osketch, Arc1, 2, true);
            //SketchLine Line3 = osketch.SketchLines.AddByTwoPoints(Arc1.StartSketchPoint, arc5.StartSketchPoint);
            //SketchLine Line4 = osketch.SketchLines.AddByTwoPoints(Line1.EndSketchPoint, line5.EndSketchPoint);
            //osketch.GeometricConstraints.AddHorizontal((SketchEntity)Line3);
            //osketch.GeometricConstraints.AddVertical((SketchEntity)Line4);
            //osketch.GeometricConstraints.AddEqualLength(Line3, Line4);
            //osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, true, InventorTool.TranGeo.CreatePoint2d(-parCylinder.CapRadius / 2, 0));
            //osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, false, InventorTool.TranGeo.CreatePoint2d(0, -parCylinder.InRadius / 2));
            //Point2d p = InventorTool.TranGeo.CreatePoint2d((Line1.StartSketchPoint.Geometry.X + Line1.EndSketchPoint.Geometry.X) / 2, (Line1.StartSketchPoint.Geometry.Y + Line1.EndSketchPoint.Geometry.Y) / 2 + 1);
            //osketch.DimensionConstraints.AddTwoPointDistance(Line1.StartSketchPoint, Line1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);
            //p = InventorTool.TranGeo.CreatePoint2d((Line4.StartSketchPoint.Geometry.X + Line4.EndSketchPoint.Geometry.X) / 2 + 1, (Line4.StartSketchPoint.Geometry.Y + Line4.EndSketchPoint.Geometry.Y) / 2);
            //osketch.DimensionConstraints.AddTwoPointDistance(Line4.StartSketchPoint, Line4.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);

            CreateLines(osketch, out Arc2, out Line2, parCylinder.CapRadius + parCylinder.Thickness, parCylinder.InRadius + parCylinder.Thickness, parCylinder.Length);
            SketchLine Line3 = osketch.SketchLines.AddByTwoPoints(Arc1.StartSketchPoint, Arc2.StartSketchPoint);
            SketchLine Line4 = osketch.SketchLines.AddByTwoPoints(Line1.EndSketchPoint, Line2.EndSketchPoint);

            osketch.GeometricConstraints.AddHorizontalAlign(Arc1.StartSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddVerticalAlign(Arc1.EndSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddHorizontal((SketchEntity)Line3);
            osketch.GeometricConstraints.AddVertical((SketchEntity)Line4);
            osketch.GeometricConstraints.AddEqualLength(Line3, Line4);
            osketch.GeometricConstraints.AddConcentric((SketchEntity)Arc1, (SketchEntity)Arc2);
            // osketch.GeometricConstraints.AddCoincident((SketchEntity)InventorTool.Origin, (SketchEntity)Arc1.CenterSketchPoint);
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, true, InventorTool.TranGeo.CreatePoint2d(-parCylinder.CapRadius / 2, 0));
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, false, InventorTool.TranGeo.CreatePoint2d(0, -parCylinder.InRadius / 2));
            Point2d p = InventorTool.TranGeo.CreatePoint2d((Line1.StartSketchPoint.Geometry.X + Line1.EndSketchPoint.Geometry.X) / 2, (Line1.StartSketchPoint.Geometry.Y + Line1.EndSketchPoint.Geometry.Y) / 2 + 1);

            osketch.DimensionConstraints.AddTwoPointDistance(Line1.StartSketchPoint, Line1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);
            p = InventorTool.TranGeo.CreatePoint2d((Line4.StartSketchPoint.Geometry.X + Line4.EndSketchPoint.Geometry.X) / 2 + 1, (Line4.StartSketchPoint.Geometry.Y + Line4.EndSketchPoint.Geometry.Y) / 2);
            osketch.DimensionConstraints.AddTwoPointDistance(Line4.StartSketchPoint, Line4.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);

            CreateRibs(osketch, Line2);
            Profile        profile = osketch.Profiles.AddForSolid();
            RevolveFeature revolve = partDef.Features.RevolveFeatures.AddFull(profile, Line3, PartFeatureOperationEnum.kNewBodyOperation);
        }
Ejemplo n.º 22
0
        //--------------------------------------------------------------------------------------
        //获得插入元件的安装表面
        private void GetInsertFace(PartComponentDefinition partCompDef, Face face, out int planeNumb, out int faceNumb)
        {
            WorkAxis workAxis;

            workAxis = partCompDef.WorkAxes.AddByRevolvedFace(face, true);
            Line oAxisLine;

            oAxisLine = workAxis.Line;
            UnitVector oAxisVector;

            oAxisVector = oAxisLine.Direction;

            Double[] coords = new Double[3];
            oAxisVector.GetUnitVectorData(ref coords);

            string strCoords;

            strCoords = coords[0].ToString() + coords[1].ToString() + coords[2].ToString();

            planeNumb = 0;
            faceNumb  = 0;
            switch (strCoords)
            {
            case "00-1":
                planeNumb = 1;
                faceNumb  = 5;
                break;

            case "010":
                planeNumb = 2;
                faceNumb  = 4;
                break;

            case "-100":
                planeNumb = 3;
                faceNumb  = 3;
                break;

            case "0-10":
                planeNumb = 4;
                faceNumb  = 2;
                break;

            case "100":
                planeNumb = 5;
                faceNumb  = 1;
                break;

            case "001":
                planeNumb = 6;
                faceNumb  = 6;
                break;
            }
        }
Ejemplo n.º 23
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);
        }
Ejemplo n.º 24
0
 public override void CreateModule(ParameterBase Parameter)
 {
     parPedestal = Parameter as ParPedestal;
     if (parPedestal == null)
     {
         return;
     }
     init();
     part    = InventorTool.CreatePart();
     partDef = part.ComponentDefinition;
     PlanarSketch osketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
 }
Ejemplo n.º 25
0
        private double GetDistanceBetwEdgeAndFace(PartComponentDefinition partCompDef, Edge edge, Face face)
        {
            NameValueMap cont;

            cont = m_inventorApplication.TransientObjects.CreateNameValueMap();

            Double oDistance;

            oDistance = m_inventorApplication.MeasureTools.GetMinimumDistance(edge.Geometry.Center, face, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference, cont);

            return(oDistance);
        }
Ejemplo n.º 26
0
        private static void generaProfilo(string v, double modulo)
        {
            PartDocument ThisDoc = (PartDocument)iApp.ActiveDocument;

            PartComponentDefinition oPartCompDef = ThisDoc.ComponentDefinition;

            PlanarSketch oSketch = (PlanarSketch)oPartCompDef.Sketches[v];

            Profile oProfile = oSketch.Profiles.AddForSolid();

            ExtrudeFeature oExtrude = oPartCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, modulo, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, PartFeatureOperationEnum.kJoinOperation);
        }
Ejemplo n.º 27
0
    /// <summary>
    /// Exports from a ComponentPartDefinition.
    /// </summary>
    /// <param name="pcd"></param>
    /// <param name="bestResolution"></param>
    /// <param name="separateFaces"></param>
    /// <param name="ignorePhysics"></param>
    public void Export(PartComponentDefinition pcd, bool bestResolution = false,
                       bool separateFaces = false, bool ignorePhysics = false)
    {
        List <ExportPlan> plans = new List <ExportPlan>();

        plans.AddRange(GenerateExportList(pcd, bestResolution, separateFaces, ignorePhysics));

        for (int i = 0; i < plans.Count; i++)
        {
            AddFacets(plans[i].surf, plans[i].bestResolution, plans[i].separateFaces);
        }
    }
Ejemplo n.º 28
0
        public void GetDistance()
        {
            PartComponentDefinition partComponentDefinition = InventorDocument.ComponentDefinition;
            /*Inventor.WorkPlane*/
            int countWorkPlanes = partComponentDefinition.WorkPlanes.Count;

            foreach (WorkPlane workPlane in partComponentDefinition.WorkPlanes)
            {
                var origin   = TransientGeometry.CreatePoint(0, 0, 0);
                var distance = workPlane.Plane.DistanceTo(origin);
            }
        }
        public void DrawASketchRectangle(Inventor.Application InvApp)
        {
            PartDocument            oPartDoc = InvApp.ActiveDocument as PartDocument;
            PartComponentDefinition oPartDef = oPartDoc.ComponentDefinition;

            Point2d oPoint1 = InvApp.TransientGeometry.CreatePoint2d(0, 0);
            Point2d oPoint2 = InvApp.TransientGeometry.CreatePoint2d(10, 10);

            oPartDef.Sketches[1].SketchLines.AddAsTwoPointRectangle(oPoint1, oPoint2);

            InvApp.ActiveDocument.Views[1].Fit();
        }
Ejemplo n.º 30
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);
        }
Ejemplo n.º 31
0
        internal void PlaceWorkGeometryForContsraints(PartComponentDefinition layoutComponentDefinition, ComponentOccurrence layoutOccurrence, int moduleNumber)
        {
            PartDocument partDoc = (PartDocument)layoutComponentDefinition.Document;
            ReferenceKeyManager refKeyManager = partDoc.ReferenceKeyManager;
            
            //TODO: Property ModuleId can be factored out and _binder.ContextData can be used instead.
            ModuleId = moduleNumber;

            for (int i = 0; i < PointObjects.Count; i++)
            {
                //Each ModuleObject needs to have its ContextManager set.
                PointObjects[i].Binder.ContextManager.BindingContextManager = refKeyManager;
                WorkPoint workPoint;
                if (PointObjects[i].Binder.GetObjectFromTrace<WorkPoint>(out workPoint))
                {
                    Inventor.Point newLocation = PersistenceManager.InventorApplication.TransientGeometry.CreatePoint(InternalModulePoints[i].X,
                                                                                                                              InternalModulePoints[i].Y,
                                                                                                                              InternalModulePoints[i].Z);

                    workPoint.SetFixed(InternalModulePoints[i].ToPoint());
                }

                else
                {
                    workPoint = layoutComponentDefinition.WorkPoints.AddFixed(InternalModulePoints[i].ToPoint(), false);
                    PointObjects[i].Binder.SetObjectForTrace<WorkPoint>(workPoint, ModuleUtilities.ReferenceKeysSorter);
                }

                //workPoint.Visible = false;

                object workPointProxyObject;
                layoutOccurrence.CreateGeometryProxy(workPoint, out workPointProxyObject);
                LayoutWorkPointProxies.Add((WorkPointProxy)workPointProxyObject);
                LayoutWorkPoints.Add(workPoint);
            }

            //If we will have more than 2 constraints, it will help assembly stability later
            //if we have a plane to constrain to first.
            if (InternalModulePoints.Count > 2)
            {
                
                WorkPlane workPlane;
                //TODO: Is this a good idea? Why is this a list? Will we ever have more
                //than work plane?  
                PlaneObjects[0].Binder.ContextManager.BindingContextManager = refKeyManager;
                if (PlaneObjects[0].Binder.GetObjectFromTrace<WorkPlane>(out workPlane))
                {
                    if (workPlane.DefinitionType == WorkPlaneDefinitionEnum.kThreePointsWorkPlane)
                    {
                        workPlane.SetByThreePoints(LayoutWorkPoints[0], LayoutWorkPoints[1], LayoutWorkPoints[2]);
                        LayoutWorkPlane = workPlane;
                        object wPlaneProxyObject;
                        layoutOccurrence.CreateGeometryProxy(workPlane, out wPlaneProxyObject);
                        LayoutWorkPlaneProxy = (WorkPlaneProxy)wPlaneProxyObject;
                    }
                }
                else
                {
                    //If the first three points are colinear, adding a workplane will fail.  We will check the area of a triangle 
                    //described by the first three points. If the area is very close to 0, we can assume these points are colinear, and we should
                    //not attempt to construct a work plane from them.
                    Inventor.Point pt1 = LayoutWorkPoints[0].Point;
                    Inventor.Point pt2 = LayoutWorkPoints[1].Point;
                    Inventor.Point pt3 = LayoutWorkPoints[2].Point;
                    if (Math.Abs(pt1.X * (pt2.Y - pt3.Y) + pt2.X * (pt3.Y - pt1.Y) + pt3.X * (pt1.Y - pt2.Y)) > .0000001)
                    {
                        workPlane = layoutComponentDefinition.WorkPlanes.AddByThreePoints(LayoutWorkPoints[0], LayoutWorkPoints[1], LayoutWorkPoints[2], false);
                        PlaneObjects[0].Binder.SetObjectForTrace<WorkPlane>(workPlane, ModuleUtilities.ReferenceKeysSorter);
                        workPlane.Grounded = true;
                        //workPlane.Visible = false;
                        LayoutWorkPlane = workPlane;
                        object wPlaneProxyObject;
                        layoutOccurrence.CreateGeometryProxy(workPlane, out wPlaneProxyObject);
                        LayoutWorkPlaneProxy = (WorkPlaneProxy)wPlaneProxyObject;
                    }
                }
            }
        }
Ejemplo n.º 32
0
        private void CreateShaft3dmodel(object sender, EventArgs e)
        {
            if (listViewShaftElements.Items.Count > 0)
            {

                if ((!ModelCreated) & (HeightOfNeighbourElementsIsDifferent()))
                {
                    PlanarSketch oSketch = default(PlanarSketch);
                    SketchPoints oSkPnts = default(SketchPoints);
                    Object actObj = ThisApplication.ActiveEditObject;
                    oSketch = (PlanarSketch)actObj;
                    oSkPnts = oSketch.SketchPoints;

                    oTransGeom = ThisApplication.TransientGeometry;
                    partDoc = (Inventor.PartDocument)ThisApplication.ActiveDocument;
                    oPartCompDef = partDoc.ComponentDefinition;

                    int TotalLenght2 = 0;
                    foreach (ListViewItem eachItem in listViewShaftElements.Items)
                    {
                        PartOfShaft POShaft = new PartOfShaft();
                        POShaft.PartHeight = Convert.ToInt32(eachItem.SubItems[1].Text);
                        POShaft.PartWidth = Convert.ToInt32(eachItem.SubItems[2].Text);
                        POShaft.CRectangle(POShaft.PartWidth, POShaft.PartHeight, TotalLenght2);

                        TotalLenght2 = TotalLenght2 + POShaft.PartWidth;
                        tbLenghtOfShaft.Text = Convert.ToString(TotalLenght2);
                    }

                    // Создание центральной оси для будущего вращения прямоугольников вокруг нее.
                    Point2d CentralLine_StartPoint = oTransGeom.CreatePoint2d(0, 0);
                    Point2d CentralLine_EndPoint = oTransGeom.CreatePoint2d(TotalLenght2, 0);
                    SketchLine CentralLineForRevolveAround = default(SketchLine);
                    CentralLineForRevolveAround = oSketch.SketchLines.AddByTwoPoints(CentralLine_StartPoint, CentralLine_EndPoint);

                    // Вращение.
                    oProfile0 = oSketch.Profiles.AddForSolid();
                    RevolveFeature oRevFeature = default(RevolveFeature);
                    oRevFeature = partDoc.ComponentDefinition.Features.RevolveFeatures.AddFull(oProfile0, CentralLineForRevolveAround, PartFeatureOperationEnum.kNewBodyOperation);

                    // Добавление фасок и кромок.

                    int StartPoint_X = 0, EndPoint_X = 0;
                    double MiddlePoint_X1 = 0, MiddlePoint_X2 = 0;
                    double SizeOfTypeStart = 0, SizeOfTypeEnd = 0;
                    double AngleStart, AngleEnd, SizeOfTypeEnd1, SizeOfTypeEnd2, SizeOfTypeStart1, SizeOfTypeStart2;

                    foreach (ListViewItem eachItem in listViewShaftElements.Items)
                    {
                        Point oPointStart = default(Point);
                        oPointStart = oTransGeom.CreatePoint(StartPoint_X, Convert.ToInt32(eachItem.SubItems[1].Text));

                        MiddlePoint_X1 = StartPoint_X + Convert.ToDouble(eachItem.SubItems[2].Text) / 2 - 0.02;
                        MiddlePoint_X2 = StartPoint_X + Convert.ToDouble(eachItem.SubItems[2].Text) / 2 + 0.02;
                        StartPoint_X = StartPoint_X + Convert.ToInt32(eachItem.SubItems[2].Text);
                        Point oPointEnd = default(Point);
                        EndPoint_X = StartPoint_X;
                        oPointEnd = oTransGeom.CreatePoint(EndPoint_X, Convert.ToInt32(eachItem.SubItems[1].Text));

                        Point oPointMiddle = default(Point);
                        oPointMiddle = oTransGeom.CreatePoint(MiddlePoint_X1, Convert.ToInt32(eachItem.SubItems[1].Text));

                        Face objFaceMiddle = (Face)partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kFaceObject, oPointMiddle, 0.01);

                        Object objStart = partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kEdgeObject, oPointStart, 0.01);
                        partDoc.SelectSet.Select(objStart);

                        // Определение коллекции начальных углов.
                        EdgeCollection oEdgesStart = default(EdgeCollection);
                        oEdgesStart = ThisApplication.TransientObjects.CreateEdgeCollection();
                        oEdgesStart.Add(objStart);
                        try
                        {
                            switch (eachItem.SubItems[3].Text)
                            {
                                case "Standart":
                                    partDoc.SelectSet.Clear();
                                    break;
                                case "Fillet":
                                    SizeOfTypeStart = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    FilletFeature oFilletStart = default(FilletFeature);
                                    oFilletStart = oPartCompDef.Features.FilletFeatures.AddSimple(oEdgesStart, SizeOfTypeStart);
                                    break;
                                case "Chamfer (Distance)":
                                    SizeOfTypeStart = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    ChamferFeature oChamferStart_D = default(ChamferFeature);
                                    oChamferStart_D = oPartCompDef.Features.ChamferFeatures.AddUsingDistance(oEdgesStart, SizeOfTypeStart);
                                    break;
                                case "Chamfer (Distance And Angle)":
                                    SizeOfTypeStart = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    AngleStart = Convert.ToDouble(eachItem.SubItems[6].Text);
                                    ChamferFeature oChamferStart_DaA = default(ChamferFeature);
                                    oChamferStart_DaA = oPartCompDef.Features.ChamferFeatures.AddUsingDistanceAndAngle(oEdgesStart, objFaceMiddle, SizeOfTypeStart, AngleStart);
                                    break;
                                case "Chamfer (Two Distances)":
                                    SizeOfTypeStart1 = Convert.ToDouble(eachItem.SubItems[4].Text);
                                    SizeOfTypeStart2 = Convert.ToDouble(eachItem.SubItems[5].Text);
                                    ChamferFeature oChamferStart_DD = default(ChamferFeature);
                                    oChamferStart_DD = oPartCompDef.Features.ChamferFeatures.AddUsingTwoDistances(oEdgesStart, objFaceMiddle, SizeOfTypeStart1, SizeOfTypeStart2);
                                    break;

                            }
                        }

                        catch
                        {
                            MessageBox.Show(eachItem.SubItems[3].Text + " " + eachItem.SubItems[4].Text + " " + eachItem.SubItems[5].Text + " " + eachItem.SubItems[6].Text);
                        }

                        Point oPointMiddle2 = default(Point);
                        oPointMiddle2 = oTransGeom.CreatePoint(MiddlePoint_X2, Convert.ToInt32(eachItem.SubItems[1].Text));
                        Face objFaceMiddle2 = (Face)partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kFaceObject, oPointMiddle2, 0.01);

                        Object objEnd = partDoc.ComponentDefinition.SurfaceBodies[1].LocateUsingPoint(ObjectTypeEnum.kEdgeObject, oPointEnd, 0.01);
                        partDoc.SelectSet.Select(objEnd);

                        // Определение коллекции конечных углов.
                        EdgeCollection oEdgesEnd = default(EdgeCollection);
                        oEdgesEnd = ThisApplication.TransientObjects.CreateEdgeCollection();
                        oEdgesEnd.Add(objEnd);

                        switch (eachItem.SubItems[7].Text)
                        {
                            case "Standart":
                                partDoc.SelectSet.Clear();
                                break;
                            case "Fillet":
                                SizeOfTypeEnd = Convert.ToDouble(eachItem.SubItems[8].Text);
                                FilletFeature oFilletEnd = default(FilletFeature);
                                oFilletEnd = oPartCompDef.Features.FilletFeatures.AddSimple(oEdgesEnd, SizeOfTypeEnd);
                                break;
                            case "Chamfer (Distance)":
                                SizeOfTypeEnd = Convert.ToDouble(eachItem.SubItems[8].Text);
                                ChamferFeature oChamferEnd_D = default(ChamferFeature);
                                oChamferEnd_D = oPartCompDef.Features.ChamferFeatures.AddUsingDistance(oEdgesEnd, SizeOfTypeEnd);
                                break;
                            case "Chamfer (Distance And Angle)":
                                SizeOfTypeEnd = Convert.ToDouble(eachItem.SubItems[8].Text);
                                AngleEnd = Convert.ToDouble(eachItem.SubItems[10].Text);
                                ChamferFeature oChamferEnd_DaA = default(ChamferFeature);
                                oChamferEnd_DaA = oPartCompDef.Features.ChamferFeatures.AddUsingDistanceAndAngle(oEdgesEnd, objFaceMiddle2, SizeOfTypeEnd, AngleEnd);
                                break;
                            case "Chamfer (Two Distances)":
                                SizeOfTypeEnd1 = Convert.ToDouble(eachItem.SubItems[8].Text);
                                SizeOfTypeEnd2 = Convert.ToDouble(eachItem.SubItems[9].Text);
                                ChamferFeature oChamferEnd_DD = default(ChamferFeature);
                                oChamferEnd_DD = oPartCompDef.Features.ChamferFeatures.AddUsingTwoDistances(oEdgesEnd, objFaceMiddle2, SizeOfTypeEnd1, SizeOfTypeEnd2);
                                break;

                        }
                    }

                    ThisApplication.ActiveView.GoHome();
                    ModelCreated = true;
                }

                else if (ModelCreated)
                {
                    MessageBox.Show("The 3d model was already created!");
                }
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Инициализация приложения
        /// </summary>
        public void Initialization(Application InventorApplication)
        {
            if (InventorApplication == null) throw new AccessingNullException();

            // В открытом приложении создаем метрическуюсборку
            _partDoc = (PartDocument)InventorApplication.Documents.Add
                (DocumentTypeEnum.kPartDocumentObject, InventorApplication.FileManager.GetTemplateFile
                        (DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kMetricSystemOfMeasure));
            //Описание документа
            _partDef = _partDoc.ComponentDefinition;
            //инициализация метода геометрии
            _transGeometry = InventorApplication.TransientGeometry;
        }