Exemplo n.º 1
0
        static public void addCutDef(SheetMetalComponentDefinition smcd, Double a, Double b, string name = "Паз")
        {
            try
            {
                SketchBlockDefinition d = smcd.SketchBlockDefinitions[name];
                return;
            }
            catch (Exception)
            {
            }
            SketchBlockDefinition def = smcd.SketchBlockDefinitions.Add(name);
            TransientGeometry     tg  = Macros.StandardAddInServer.m_inventorApplication.TransientGeometry;
            Point2d     pt            = tg.CreatePoint2d();
            SketchPoint origin        = def.SketchPoints.Add(pt, false);

            def.GeometricConstraints.AddGround((SketchEntity)origin);
            SketchLine sl1, sl2, sl3;
            SketchEntitiesEnumerator en = def.SketchLines.AddAsTwoPointRectangle(tg.CreatePoint2d(-b / 2, -a / 2), tg.CreatePoint2d(b / 2, a / 2));

            sl1 = (SketchLine)en[2]; sl2 = (SketchLine)en[4];
            sl3 = midleLine(sl1, sl2);

            //foreach (DimensionConstraint item in def.DimensionConstraints)
            //{
            //    item.Delete();
            //}
        }
Exemplo n.º 2
0
        public void AssemblyFeature()
        {
            AssemblyDocument            oAssDoc = (AssemblyDocument)_InvApplication.ActiveDocument;
            AssemblyComponentDefinition oAsmDef = oAssDoc.ComponentDefinition;

            // Create a sketch on the XY workplane.
            PlanarSketch oSketch = default(PlanarSketch);

            oSketch = oAsmDef.Sketches.Add(oAsmDef.WorkPlanes[3]);

            TransientGeometry oTG = default(TransientGeometry);

            oTG = _InvApplication.TransientGeometry;

            // Draw a rectangle.
            oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(0.1, 0.1), oTG.CreatePoint2d(1, 0.5));
            // Create a profile
            Profile oProfile = default(Profile);

            oProfile = oSketch.Profiles.AddForSolid();

            // Create the extrusion.
            ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition);

            oExtrudeDef = oAsmDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kCutOperation);
            oExtrudeDef.SetDistanceExtent("2 cm", PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);

            oAsmDef.Features.ExtrudeFeatures.Add(oExtrudeDef);
        }
Exemplo n.º 3
0
        internal override void DrawGeom(TransientGeometry TG, ref PlanarSketch sketch, ref List <SketchLine> lines)
        {
            Hord = 2 * Math.Sqrt(Depth * (2 * Radius - Depth));
            //(2 * Math.Sqrt(Depth * (2 * Radius - Depth))) to calculate hord distance
            var length = Distance + Hord;

            _length = 0;
            for (int i = 0; i < index; i++)
            {
                _length += var_es._list[i].Length;
            }

            switch (Side)
            {
            case ('r'):
                _length += var_es._list[index].Length;
                var arc = sketch.SketchArcs.AddByThreePoints(TG.CreatePoint2d(_length - Distance + 0.5 * Hord, var_es._list[index].Radius), TG.CreatePoint2d(_length - Distance, var_es._list[index].Radius - Depth), TG.CreatePoint2d(_length - Distance - 0.5 * Hord, var_es._list[index].Radius));
                sketch.SketchLines.AddByTwoPoints(arc.EndSketchPoint, arc.StartSketchPoint);
                break;

            case ('l'):
                arc = sketch.SketchArcs.AddByThreePoints(TG.CreatePoint2d(_length + Distance - 0.5 * Hord, var_es._list[index].Radius), TG.CreatePoint2d(_length + Distance, var_es._list[index].Radius - Depth), TG.CreatePoint2d(_length + Distance + 0.5 * Hord, var_es._list[index].Radius));
                sketch.SketchLines.AddByTwoPoints(arc.EndSketchPoint, arc.StartSketchPoint);
                break;
            }
        }
Exemplo n.º 4
0
 internal override void DrawGeom(TransientGeometry TG, ref PlanarSketch sketch, ref List<SketchLine> lines)
 {
     try
     {
         _length = 0;
         for (int i = 0; i < index; i++)
         {
             _length += var_es._list[i].Length;
         }
         
         switch (Side)
         {
             case ('r'):
                 _length += var_es._list[index].Length;
                 sketch.SketchLines.AddAsTwoPointRectangle(TG.CreatePoint2d(_length - Distance - Width, Radius), TG.CreatePoint2d(_length - Distance, var_es._list[index].Radius));
                 break;
             case ('l'):
                 sketch.SketchLines.AddAsTwoPointRectangle(TG.CreatePoint2d(_length + Distance, Radius), TG.CreatePoint2d(_length + Distance + Width, var_es._list[index].Radius));
                 break;
         }
     }
     catch (Exception e1)
     {
         MessageBox.Show(e1.ToString());
     }
 }
Exemplo n.º 5
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);
        }
        /// <summary>
        /// Generate drawing document with input model document
        /// </summary>
        /// <param name="filePath">File path for the generated drawing document</param>
        /// <param name="doc">The Inventor document.</param>
        private void SaveAsIDW(string filePath, Document doc)
        {
            LogTrace("Create a new drawing document");
            DrawingDocument drawDoc = (DrawingDocument)inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject);

            Inventor.Sheet sheet;

            LogTrace("Get or create a new drawing sheet");
            try
            {
                if (drawDoc.Sheets.Count > 0)
                {
                    sheet      = drawDoc.Sheets[1];
                    sheet.Size = DrawingSheetSizeEnum.kA2DrawingSheetSize;
                }
                else
                {
                    sheet = drawDoc.Sheets.Add(DrawingSheetSizeEnum.kA2DrawingSheetSize);
                }

                TransientGeometry oTG = inventorApplication.TransientGeometry;
                Inventor.Point2d  pt  = oTG.CreatePoint2d(10, 10);

                LogTrace("Create a base view");
                Inventor.DrawingView dv = sheet.DrawingViews.AddBaseView((_Document)doc, pt, 1, ViewOrientationTypeEnum.kIsoTopLeftViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle, "", null, null);
                LogTrace("Change scale of base drawing view");
                dv.Scale = CalculateViewSize(sheet, dv);

                LogTrace("Create projected view");
                Inventor.Point2d     pt2      = oTG.CreatePoint2d(dv.Position.X, dv.Position.Y + dv.Height * 1.2);
                Inventor.DrawingView projView = sheet.DrawingViews.AddProjectedView(dv, pt2, DrawingViewStyleEnum.kShadedDrawingViewStyle);

                Inventor.Point2d pt3 = oTG.CreatePoint2d(sheet.Width - 5, sheet.Height / 3);
                LogTrace("Create part list");
                Inventor.PartsList pl = sheet.PartsLists.Add(dv, pt3, PartsListLevelEnum.kPartsOnly);

                Inventor.Point2d pt4 = oTG.CreatePoint2d(sheet.Width / 2, sheet.Height / 4);
                LogTrace("Create Revision table");
                Inventor.RevisionTable rtable = sheet.RevisionTables.Add(pt4);
                rtable.ShowTitle = true;
                rtable.Title     = "Revision Table Test";
                rtable.RevisionTableRows[1][1].Text = "Inventor IO";
                rtable.RevisionTableRows[1][3].Text = "Test revision table in drawing";
                rtable.RevisionTableRows[1][4].Text = "Autodesk";
                LogTrace("Done:Create Revision table");

                LogTrace($"Saving IDW {filePath}");
                drawDoc.SaveAs(filePath, false);
                drawDoc.Close();
                LogTrace($"Saved IDW as {filePath}");
            }
            catch (Exception e)
            {
                drawDoc.Close();
                LogError($"Generate IDW fails: {e.Message}");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Рисует прямоугольник по двум точкам
        /// </summary>
        /// <param name="pointOneX">Левая верхняя координата X</param>
        /// <param name="pointOneY">Левая верхняя координата Y</param>
        /// <param name="pointTwoX">Правая нижняя координата X</param>
        /// <param name="pointTwoY">Правая нижняя координата Y</param>
        public void DrawRectangle(double pointOneX, double pointOneY, double pointTwoX, double pointTwoY)
        {
            pointOneX /= divider;
            pointOneY /= divider;
            pointTwoX /= divider;
            pointTwoY /= divider;
            var cornerPointOne = _transGeometry.CreatePoint2d(pointOneX, pointOneY);
            var cornerPointTwo = _transGeometry.CreatePoint2d(pointTwoX, pointTwoY);

            _currentSketch.SketchLines.AddAsTwoPointRectangle(cornerPointOne, cornerPointTwo);
        }
Exemplo n.º 8
0
        /// <summary>
        ///  creating leader text on a sheet.
        /// Before running this sample, open a drawing document and select a linear drawing edge.
        /// </summary>
        /// <remarks></remarks>
        public void AddLeaderNote()
        {
            // Set a reference to the drawing document.
            // This assumes a drawing document is active.
            DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument;

            // Set a reference to the active sheet.
            Sheet oActiveSheet = oDrawDoc.ActiveSheet;

            // Set a reference to the drawing curve segment.
            // This assumes that a drawing curve is selected.
            DrawingCurveSegment oDrawingCurveSegment = oDrawDoc.SelectSet[1];

            // Set a reference to the drawing curve.
            DrawingCurve oDrawingCurve = oDrawingCurveSegment.Parent;

            // Get the mid point of the selected curve
            // assuming that the selected curve is linear
            Point2d oMidPoint = oDrawingCurve.MidPoint;

            // Set a reference to the TransientGeometry object.
            TransientGeometry oTG = _InvApplication.TransientGeometry;

            ObjectCollection oLeaderPoints = _InvApplication.TransientObjects.CreateObjectCollection();

            // Create a few leader points.
            oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 10));
            oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.X + 10, oMidPoint.Y + 5));

            // Create an intent and add to the leader points collection.
            // This is the geometry that the leader text will attach to.
            GeometryIntent oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve);

            oLeaderPoints.Add(oGeometryIntent);

            // Create text with simple string as input. Since this doesn't use
            // any text overrides, it will default to the active text style.
            string sText = null;

            sText = "API Leader Note";

            LeaderNote oLeaderNote = oActiveSheet.DrawingNotes.LeaderNotes.Add(oLeaderPoints, sText);

            // Insert a node.
            LeaderNode oFirstNode = oLeaderNote.Leader.RootNode.ChildNodes[1];

            LeaderNode oSecondNode = oFirstNode.ChildNodes[1];

            oFirstNode.InsertNode(oSecondNode, oTG.CreatePoint2d(oMidPoint.X + 5, oMidPoint.Y + 5));
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Transforms the point2d objects to scale of the sketch in order to draw the rectangle to the proper scale
        /// as shown in the interaction graphics.
        /// </summary>
        protected void AdjustDrawingDocumentPoints()
        {
            TransientGeometry transGeom         = _inventorApplication.TransientGeometry;
            Point2d           tempPoint2d       = transGeom.CreatePoint2d();
            Point2d           tempFinalPosition = transGeom.CreatePoint2d();

            tempPoint2d    = _pickedPoint2d;
            _pickedPoint2d = _drawingSketch.SheetToSketchSpace(tempPoint2d);

            tempFinalPosition.X = _finalPosition.X;
            tempFinalPosition.Y = _finalPosition.Y;
            _upperRightPoint2d  = _drawingSketch.SheetToSketchSpace(tempFinalPosition);

            PositionPoint2dObjects();
        }
Exemplo n.º 11
0
        private void createPart2()
        {
            // create a new part
            PartDocument            oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);
            PartComponentDefinition oDef = oDoc.ComponentDefinition;

            TransientGeometry oTG = mApp.TransientGeometry;

            // create sketch elements
            PlanarSketch oSketch = oDef.Sketches.Add(oDef.WorkPlanes[3]);

            oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(-5, -5), oTG.CreatePoint2d(5, 5));

            SketchPoint oSketchPt = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0));

            Profile oProfile = oSketch.Profiles.AddForSolid();
            // create a plate with a hole feature
            ExtrudeDefinition oExtrudDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);

            oExtrudDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            ExtrudeFeature oExtrudeF = oDef.Features.ExtrudeFeatures.Add(oExtrudDef);

            // Create an object collection for the hole center points.
            ObjectCollection oHoleCenters = default(ObjectCollection);

            oHoleCenters = mApp.TransientObjects.CreateObjectCollection();

            oHoleCenters.Add(oSketchPt);

            // create hole feature
            HolePlacementDefinition oHPdef = (HolePlacementDefinition)oDef.Features.HoleFeatures.CreateSketchPlacementDefinition(oHoleCenters);

            HoleFeature oHoleF = oDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHPdef, "2", PartFeatureExtentDirectionEnum.kNegativeExtentDirection);

            Face         oFace   = oHoleF.SideFaces[1];
            AttributeSet oAttSet = default(AttributeSet);

            Inventor.Attribute oAtt = null;
            oAttSet = oFace.AttributeSets.Add("demoAttset");
            oAtt    = oAttSet.Add("demoAtt", ValueTypeEnum.kStringType, "namedEdge");
            if (System.IO.File.Exists("c:\temp\test2.ipt"))
            {
                System.IO.File.Delete("c:\temp\test2.ipt");
            }


            oDoc.SaveAs("c:\\temp\\test2.ipt", false);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Рисует круг.
 /// </summary>
 /// <param name="centerPointX">Координата X центра круга</param>
 /// <param name="centerPointY">Координата Y центра круга</param>
 /// <param name="diameter">Диаметр круга</param>
 public void DrawCircle(double centerPointX, double centerPointY, double diameter)
 {
     centerPointX /= Index;
     centerPointY /= Index;
     diameter     /= Index;
     _currentSketch.SketchCircles.AddByCenterRadius(_transGeometry.CreatePoint2d(centerPointX, centerPointY),
                                                    0.5 * diameter);
 }
Exemplo n.º 13
0
        internal override void Create_BR(TransientGeometry TG, ref PlanarSketch sketch, EdgeCollection eColl, ref Face B_face, ref Face E_face, ref PartComponentDefinition partDef)
        {
            sketch.SketchLines.AddAsPolygon(Number_of_Edges, TG.CreatePoint2d(), TG.CreatePoint2d(Radius), is_Inscribed);
            Profile           profile = sketch.Profiles.AddForSolid();
            ExtrudeDefinition extrude = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation);

            extrude.SetDistanceExtent(Length, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            ExtrudeFeature extrudeFeature = partDef.Features.ExtrudeFeatures.Add(extrude);

            sketch     = partDef.Sketches.Add(extrudeFeature.EndFaces[1]);
            Start_face = extrudeFeature.StartFaces[1];
            End_face   = extrudeFeature.EndFaces[1];
            foreach (Face side in extrudeFeature.SideFaces)
            {
                Side_faces.Add(side);
            }
        }
        public CenterPointRectangle(IInventorButton rectangleButton, Inventor.Application inventorApplication)
        {
            _inventorApplication = inventorApplication;
            _rectangleButton     = rectangleButton;
            _changeProcessor     = new QubeItToolsChangeProcessor(_inventorApplication, this,
                                                                  "CenterPtRect", "Center Point Rectangle", StandardAddInServer.AddInServerId);
            TransientGeometry tG = _inventorApplication.TransientGeometry;

            _upperRightPoint2d = tG.CreatePoint2d();
            _upperLeftPoint2d  = tG.CreatePoint2d();
            _lowerLeftPoint2d  = tG.CreatePoint2d();
            _lowerRightPoint2d = tG.CreatePoint2d();

            _constructionLineButton = _inventorApplication.CommandManager.ControlDefinitions["SketchConstructionCmd"] as ButtonDefinition;
            _centerLineButton       = _inventorApplication.CommandManager.ControlDefinitions["SketchCenterlineCmd"] as ButtonDefinition;
            _sketchOnlyButton       = _inventorApplication.CommandManager.ControlDefinitions["SketchOnlyCmd"] as ButtonDefinition;
        }
Exemplo n.º 15
0
        internal override void DrawGeom(TransientGeometry TG, ref PlanarSketch sketch, ref List <SketchLine> lines)
        {
            var pos = lines.FindIndex(x => x == SideLine);

            lines.RemoveAt(pos);
            pos += 1;
            sketch.SketchLines[pos].Delete();
            var length = Distance + Width;

            switch (Side)
            {
            case ('r'):
                var point = sketch.SketchLines[pos - 1].EndSketchPoint;
                var line  = sketch.SketchLines.AddByTwoPoints(point, TG.CreatePoint2d(point.Geometry.X + Distance, point.Geometry.Y));
                var line0 = sketch.SketchLines.AddByTwoPoints(line.EndSketchPoint, TG.CreatePoint2d(line.EndSketchPoint.Geometry.X, Radius));
                var line1 = sketch.SketchLines.AddByTwoPoints(line0.EndSketchPoint, TG.CreatePoint2d(line0.EndSketchPoint.Geometry.X + Width, line0.EndSketchPoint.Geometry.Y));
                var line2 = sketch.SketchLines.AddByTwoPoints(line1.EndSketchPoint, TG.CreatePoint2d(line.EndSketchPoint.Geometry.X + Width, line.EndSketchPoint.Geometry.Y));
                sketch.SketchLines.AddByTwoPoints(line2.EndSketchPoint, sketch.SketchLines[pos].StartSketchPoint);
                break;

            case ('l'):
                point = sketch.SketchLines[pos].StartSketchPoint;
                line  = sketch.SketchLines.AddByTwoPoints(sketch.SketchLines[pos - 1].EndSketchPoint, TG.CreatePoint2d(point.Geometry.X - length, point.Geometry.Y));
                line0 = sketch.SketchLines.AddByTwoPoints(line.EndSketchPoint, TG.CreatePoint2d(line.EndSketchPoint.Geometry.X, Radius));
                line1 = sketch.SketchLines.AddByTwoPoints(line0.EndSketchPoint, TG.CreatePoint2d(line0.EndSketchPoint.Geometry.X + Width, line0.EndSketchPoint.Geometry.Y));
                line2 = sketch.SketchLines.AddByTwoPoints(line1.EndSketchPoint, TG.CreatePoint2d(line.EndSketchPoint.Geometry.X + Width, line.EndSketchPoint.Geometry.Y));
                sketch.SketchLines.AddByTwoPoints(line2.EndSketchPoint, point);
                break;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Converts a Point object (which is a 3D Inventor point) into a Point2d object (which is a
        /// 2D point used in sketches).
        /// </summary>
        /// <param name="modelPosition"></param>
        /// <param name="translatedPoint2d"></param>
        protected void PointToPoint2d(Point modelPosition, out Point2d translatedPoint2d)
        {
            TransientGeometry tG          = _inventorApplication.TransientGeometry;
            Point2d           tempPoint2d = tG.CreatePoint2d();

            tempPoint2d.X     = modelPosition.X;
            tempPoint2d.Y     = modelPosition.Y;
            translatedPoint2d = tempPoint2d;
        }
Exemplo n.º 17
0
        private static bool CreateCircle(DataRow iRow, Sheet iSheet, DrawingSketch iSketch, TransientGeometry tg)
        {
            bool isCircleCreated = false;

            try
            {
                int      circleInst = Int32.Parse(iRow.ItemArray[iRow.ItemArray.Count() - 1].ToString());
                int      startNum   = 0;
                string   tempCoord  = iRow.ItemArray[4].ToString();
                string[] coord      = tempCoord.Split(',');
                Double   initX      = Double.Parse(coord[0]);
                Double   initY      = Double.Parse(coord[1]);
                Double   hOffset    = Double.Parse(iRow.ItemArray[5].ToString());
                Double   vOffset    = Double.Parse(iRow.ItemArray[6].ToString());
                Double   radius     = Double.Parse(iRow.ItemArray[3].ToString()) / 2;
                do
                {
                    iSketch.Edit();
                    Point2d cen;
                    if (startNum < circleInst / 2)
                    {
                        cen = tg.CreatePoint2d(initX + (hOffset * startNum), initY);
                    }
                    else
                    {
                        cen = tg.CreatePoint2d(initX + (hOffset * (startNum - 4)), initY + vOffset);
                    }
                    SketchCircle   iCircle = iSketch.SketchCircles.AddByCenterRadius(cen, 2);
                    GeometryIntent oGeo1   = iSheet.CreateGeometryIntent(iCircle, null);
                    iSketch.ExitEdit();
                    iSheet.DrawingDimensions.GeneralDimensions.AddDiameter(cen, oGeo1, false, false, false);
                    isCircleCreated = true;
                    startNum       += 1;
                } while (startNum < circleInst);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(isCircleCreated);
        }
Exemplo n.º 18
0
        //To execute this command, a drawing document with a view need to be available
        private void Border2_Click(object sender, EventArgs e)
        {
            DrawingDocument oDrawDoc = mApp.ActiveDocument as DrawingDocument;

            TransientGeometry oTG = mApp.TransientGeometry;

            //Create the new border definition
            BorderDefinition oBorderDef = oDrawDoc.BorderDefinitions.Add("Sample Border");

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

            oBorderDef.Edit(out oSketch);

            //Use the functionality of the sketch to add geometry
            oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(2, 2), oTG.CreatePoint2d(25.94, 19.59));

            oBorderDef.ExitEdit(true, "");
        }
Exemplo n.º 19
0
        internal override void DrawGeom(TransientGeometry TG, ref PlanarSketch sketch, ref List <SketchLine> lines)
        {
            try
            {
                if (!First)
                {
                    if (Radius == var_es._list[Position - 1].Radius)
                    {
                        var_es._list[Position - 1].Same_as_next = true;
                    }

                    lines.RemoveAt(lines.Count - 1);
                    sketch.SketchLines[sketch.SketchLines.Count].Delete();
                    if (Radius == var_es._list[Position - 1].Radius)
                    {
                        SideLine = sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X + Length, Second_Radius));
                        lines.Add(SideLine);
                        lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X, 0)));
                    }
                    else
                    {
                        lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X, Radius)));
                        SideLine = sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X + Length, Second_Radius));
                        lines.Add(SideLine);
                        lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X, 0)));
                    }
                }
                else if (First)
                {
                    lines.Add(sketch.SketchLines.AddByTwoPoints(TG.CreatePoint2d(), TG.CreatePoint2d(0, Radius)));
                    SideLine = sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(Length, Second_Radius));
                    lines.Add(SideLine);
                    lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(Length)));
                }
            }
            catch (System.Exception e1)
            {
                System.Windows.Forms.MessageBox.Show(e1.ToString());
            }
        }
Exemplo n.º 20
0
        //creating a new sketched symbol definition object and
        //    inserting it into the active sheet.
        //    This sample consists of two subs.
        //    The first demonstrates the creation of a sketched symbol definition and
        //    the second inserts it into the active sheet.
        //    To run the sample have a drawing document open and run the CreateSketchedSymbolDefinition Sub.
        //    After this you can run the InsertSketchedSymbolOnSheet to insert the sketched symbol into the active sheet.
        //    The insertion sub demonstrates the use of the insertion point in the symbol's definition while inserting the symbol.

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

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

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

            oSketchedSymbolDef.Edit(out oSketch);

            TransientGeometry oTG = _InvApplication.TransientGeometry;

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

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

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

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

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

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

            oSketchedSymbolDef.ExitEdit(true);
        }
Exemplo n.º 21
0
        internal override void Create_BR(TransientGeometry TG, ref PlanarSketch sketch, EdgeCollection eColl, ref Face B_face, ref Face E_face, ref PartComponentDefinition partDef)
        {
            sketch.SketchCircles.AddByCenterRadius(TG.CreatePoint2d(), Radius);
            Profile           profile = sketch.Profiles.AddForSolid();
            ExtrudeDefinition extrude = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation);

            extrude.SetDistanceExtent(Length, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            ExtrudeFeature extrudeFeature = partDef.Features.ExtrudeFeatures.Add(extrude);

            sketch     = partDef.Sketches.Add(extrudeFeature.EndFaces[1]);
            Start_face = extrudeFeature.StartFaces[1];
            End_face   = extrudeFeature.EndFaces[1];
            Side_face  = extrudeFeature.SideFaces[1];
        }
Exemplo n.º 22
0
        private Inventor.ExtrudeFeature CreateFlangeExtrustion(ref Inventor.PartDocument PartDocument, string FlangeDiaOD, string FlangeDiaID, string FlangeThickness)
        {
            Inventor.UnitsOfMeasure      UnitsOfMeasure;
            Inventor.PlanarSketch        Sketch;
            Inventor.TransientGeometry   TransientGeometry;
            Inventor.SketchCircle        SketchCircle;
            Inventor.WorkPoint           WorkPoint;
            Inventor.WorkPlane           BaseWorkPlane;
            Inventor.RadiusDimConstraint RadiusDimConstraint = null;
            Inventor.SketchEntity        SketchEntity;
            Inventor.ObjectCollection    SketchObjectCollection;
            Inventor.Profile             Profile;
            Inventor.ExtrudeDefinition   ExtrudeDefinition;
            Inventor.ExtrudeFeature      ExtrudeFeature = null;

            SketchObjectCollection = InvApp.TransientObjects.CreateObjectCollection();

            UnitsOfMeasure = PartDocument.UnitsOfMeasure;
            double DiaOD = 0, DiaID = 0, Thickness = 0;

            DiaOD     = UnitsOfMeasure.GetValueFromExpression(FlangeDiaOD, Inventor.UnitsTypeEnum.kMillimeterLengthUnits);
            DiaID     = UnitsOfMeasure.GetValueFromExpression(FlangeDiaID, Inventor.UnitsTypeEnum.kMillimeterLengthUnits);
            Thickness = UnitsOfMeasure.GetValueFromExpression(FlangeThickness, Inventor.UnitsTypeEnum.kMillimeterLengthUnits);

            TransientGeometry = InvApp.TransientGeometry;
            WorkPoint         = PartDocument.ComponentDefinition.WorkPoints[1];
            BaseWorkPlane     = GetPartDocumentWorkPlane(ref PartDocument, "XY");

            Sketch              = PartDocument.ComponentDefinition.Sketches.Add(BaseWorkPlane, false);
            SketchEntity        = Sketch.AddByProjectingEntity(WorkPoint);
            SketchCircle        = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), DiaOD / 2);
            RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false);
            Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint);

            RadiusDimConstraint = null;
            SketchCircle        = null;
            SketchCircle        = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), DiaID / 2);
            RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false);
            Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint);
            SketchObjectCollection.Add(SketchCircle);

            Profile           = Sketch.Profiles.AddForSolid(true, SketchObjectCollection);
            ExtrudeDefinition = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(Profile, Inventor.PartFeatureOperationEnum.kNewBodyOperation);
            ExtrudeDefinition.SetDistanceExtent(Thickness, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

            ExtrudeFeature      = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.Add(ExtrudeDefinition);
            ExtrudeFeature.Name = "FlangeBase";

            return(ExtrudeFeature);
        }
Exemplo n.º 23
0
        private static bool CreateRectangle(DataRow iRow, Sheet iSheet, DrawingSketch iSketch, TransientGeometry tg)
        {
            bool isRectangleCreated = false;

            try
            {
                string   tempCoord = iRow.ItemArray[4].ToString();
                string[] coord     = tempCoord.Split(',');
                Double   initX     = Double.Parse(coord[0]);
                Double   initY     = Double.Parse(coord[1]);
                Double   height    = Double.Parse(iRow.ItemArray[1].ToString());
                Double   width     = Double.Parse(iRow.ItemArray[2].ToString());
                iSketch.Edit();
                Point2d    pt1 = tg.CreatePoint2d(initX, initY);
                Point2d    pt2 = tg.CreatePoint2d(initX + width, initY);
                Point2d    pt3 = tg.CreatePoint2d(initX + width, initY + height);
                Point2d    pt4 = tg.CreatePoint2d(initX, initY + height);
                SketchLine l1  = iSketch.SketchLines.AddByTwoPoints(pt1, pt2);
                SketchLine l2  = iSketch.SketchLines.AddByTwoPoints(pt2, pt3);
                iSketch.SketchLines.AddByTwoPoints(pt3, pt4);
                iSketch.SketchLines.AddByTwoPoints(pt4, pt1);
                iSketch.ExitEdit();
                GeometryIntent         oGeo1  = iSheet.CreateGeometryIntent(l1, null);
                GeometryIntent         oGeo2  = iSheet.CreateGeometryIntent(l2, null);
                LinearGeneralDimension iDim   = iSheet.DrawingDimensions.GeneralDimensions.AddLinear(pt1, oGeo1);
                DimensionStyle         iStyle = iDim.Style;
                iStyle.PartOffset        = 45.0;
                iStyle.ShowDimensionLine = true;
                iSheet.DrawingDimensions.GeneralDimensions.AddLinear(pt2, oGeo2).Style = iStyle;
                isRectangleCreated = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(isRectangleCreated);
        }
Exemplo n.º 24
0
        internal override void DrawGeom(TransientGeometry TG, ref PlanarSketch sketch, ref List <SketchLine> lines)
        {
            try
            {
                if (!First)
                {
                    if (Radius == var_es._list[Position - 1].Radius)
                    {
                        var_es._list[Position - 1].Same_as_next = true;
                    }

                    lines.RemoveAt(lines.Count - 1);
                    sketch.SketchLines[sketch.SketchLines.Count].Delete();
                    if (var_es._list[Position].Radius == var_es._list[Position - 1].Radius)
                    {
                        SideLine = sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X + Length, Radius));
                        lines.Add(SideLine);
                        lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X, 0)));
                    }
                    else
                    {
                        lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X, var_es._list[Position].Radius)));
                        SideLine = sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X + Length, Radius));
                        lines.Add(SideLine);
                        lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(lines[lines.Count - 1].EndSketchPoint.Geometry.X, 0)));
                    }
                }
                else if (First)
                {
                    lines.Add(sketch.SketchLines.AddByTwoPoints(TG.CreatePoint2d(), TG.CreatePoint2d(0, Radius)));
                    SideLine = sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(Length, Radius));
                    lines.Add(SideLine);
                    lines.Add(sketch.SketchLines.AddByTwoPoints(lines[lines.Count - 1].EndSketchPoint, TG.CreatePoint2d(Length)));
                }
            }
            catch { }
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
0
        private Inventor.ExtrudeFeature Extrude_FlangeBody(ref Inventor.PartDocument PartDocument)
        {
            Inventor.TransientGeometry   TransientGeometry;
            Inventor.SketchCircle        SketchCircle;
            Inventor.RadiusDimConstraint RadiusDimConstraint = null;
            Inventor.Profile             SketchProfile;
            Inventor.ExtrudeDefinition   ExtrudeDefinition;
            Inventor.ExtrudeFeature      ExtrudeFeature = null;

            Inventor.PlanarSketch Sketch;
            Inventor.SketchEntity SketchEntity;
            PartDocument = AddSketchProjectCenterPoint(PartDocument, out Sketch, out SketchEntity);

            TransientGeometry   = InvApp.TransientGeometry;
            SketchCircle        = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), FlangeDiaOD / 2);
            RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false);
            Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint);

            RadiusDimConstraint = null;
            SketchCircle        = null;
            Inventor.ObjectCollection SketchObjectCollection;
            SketchObjectCollection = InvApp.TransientObjects.CreateObjectCollection();

            SketchCircle = Sketch.SketchCircles.AddByCenterRadius(TransientGeometry.CreatePoint2d(0, 0), FlangeDiaID / 2);

            RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, TransientGeometry.CreatePoint2d(0, 0), false);
            Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint);
            SketchObjectCollection.Add(SketchCircle);

            SketchProfile     = Sketch.Profiles.AddForSolid(true, SketchObjectCollection);
            ExtrudeDefinition = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(SketchProfile, Inventor.PartFeatureOperationEnum.kNewBodyOperation);
            ExtrudeDefinition.SetDistanceExtent(FlangeThickness, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

            //Extrude The Sketch Profile
            ExtrudeFeature      = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.Add(ExtrudeDefinition);
            ExtrudeFeature.Name = "FlangeBody";

            return(ExtrudeFeature);
        }
Exemplo n.º 27
0
        static public void rect(SketchLine sl, SketchPoint mp, double a, double b)
        {
            TransientGeometry             tg  = Macros.StandardAddInServer.m_inventorApplication.TransientGeometry;
            PlanarSketch                  ps  = (PlanarSketch)sl.Parent;
            Point2d                       pt  = tg.CreatePoint2d(mp.Geometry.X, mp.Geometry.Y);
            SketchEntitiesEnumerator      en  = ps.SketchLines.AddAsThreePointRectangle(pt, tg.CreatePoint2d(pt.X + a, pt.Y), tg.CreatePoint2d(pt.X, pt.Y + b));
            SketchLine                    sl1 = (SketchLine)en[1];
            SketchLine                    sl2 = (SketchLine)en[2];
            SketchLine                    sl3;
            TwoPointDistanceDimConstraint tpdc = ps.DimensionConstraints.AddTwoPointDistance(sl1.StartSketchPoint, sl1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, sl1.Geometry.MidPoint);

            tpdc = ps.DimensionConstraints.AddTwoPointDistance(sl2.StartSketchPoint, sl2.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, sl2.Geometry.MidPoint);
            if ((int)(sl1.Length * 1000) <= (int)(a * 2000))
            {
                sl3 = midleLine((SketchLine)en[1], (SketchLine)en[3]);
            }
            else
            {
                sl3 = midleLine((SketchLine)en[2], (SketchLine)en[4]);
            }
            ps.GeometricConstraints.AddMidpoint(mp, sl3);
            ps.GeometricConstraints.AddParallel((SketchEntity)sl, (SketchEntity)sl3);
        }
Exemplo n.º 28
0
        void createPart1()
        {
            // create a new part

            PartDocument            oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject);
            PartComponentDefinition oDef = oDoc.ComponentDefinition;

            TransientGeometry oTG = mApp.TransientGeometry;

            // create sketch elements
            PlanarSketch oSketch = oDef.Sketches.Add(oDef.WorkPlanes[3]);
            SketchCircle oCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), 1);

            Profile oProfile = oSketch.Profiles.AddForSolid();

            // create a cylinder feature
            ExtrudeDefinition oExtrudDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation);

            oExtrudDef.SetDistanceExtent(5, PartFeatureExtentDirectionEnum.kPositiveExtentDirection);
            ExtrudeFeature oExtrudeF = oDef.Features.ExtrudeFeatures.Add(oExtrudDef);

            //add an attribute to cylinder face
            Face oFace = oExtrudeF.SideFaces[1];

            AttributeSet oAttSet = default(AttributeSet);

            Inventor.Attribute oAtt = null;
            oAttSet = oFace.AttributeSets.Add("demoAttset");
            oAtt    = oAttSet.Add("demoAtt", ValueTypeEnum.kStringType, "namedEdge");
            if (System.IO.File.Exists("c:\temp\test1.ipt"))
            {
                System.IO.File.Delete("c:\temp\test1.ipt");
            }

            oDoc.SaveAs("c:\\temp\\test1.ipt", false);
        }
Exemplo n.º 29
0
        public Inventor.ExtrudeFeature Extrude_FlangeBody()
        {
            Inventor.TransientGeometry   TransientGeometry;
            Inventor.SketchCircle        SketchCircle;
            Inventor.RadiusDimConstraint RadiusDiamension = null;
            Inventor.Profile             SketchProfile;
            Inventor.ExtrudeDefinition   ExtrudeDefinition;
            Inventor.ExtrudeFeature      ExtrudeFeature = null;
            Inventor.PlanarSketch        Sketch;
            Inventor.SketchEntity        SketchEntity;
            //Create Sketch on wp project 0,0,0 work point Geometry
            PartDocument = AddSketchProjectCenterPoint(PartDocument, out Sketch, out SketchEntity);
            //Get the Transient Geometry Object from Inventor
            TransientGeometry = InvApp.TransientGeometry;
            //Draw Outside Hole
            DrawCircle_Constrain_Diamension(TransientGeometry.CreatePoint2d(0, 0), out SketchCircle, out RadiusDiamension, Sketch, SketchEntity, FlangeDiaOD / 2);

            RadiusDiamension = null;           // reset for next use
            SketchCircle     = null;
            Inventor.ObjectCollection SketchObjectCollection;
            SketchObjectCollection = InvApp.TransientObjects.CreateObjectCollection();
            //Draw Inside Hole Add to sketch objects
            DrawCircle_Constrain_Diamension(TransientGeometry.CreatePoint2d(0, 0), out SketchCircle, out RadiusDiamension, Sketch, SketchEntity, FlangeDiaID / 2);
            //Add to sketch Collection ready for Extrude
            SketchObjectCollection.Add(SketchCircle);
            //Convert to profileing
            SketchProfile     = Sketch.Profiles.AddForSolid(true, SketchObjectCollection);
            ExtrudeDefinition = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(SketchProfile, Inventor.PartFeatureOperationEnum.kNewBodyOperation);
            ExtrudeDefinition.SetDistanceExtent(FlangeThickness, Inventor.PartFeatureExtentDirectionEnum.kPositiveExtentDirection);

            //Extrude The Sketch Profile
            ExtrudeFeature      = PartDocument.ComponentDefinition.Features.ExtrudeFeatures.Add(ExtrudeDefinition);
            ExtrudeFeature.Name = "FlangeBody";

            return(ExtrudeFeature);
        }
Exemplo n.º 30
0
 static public Point2d CP2d(double x = 0, double y = 0)
 {
     return(tg.CreatePoint2d(x, y));
 }
Exemplo n.º 31
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!");
                }
            }
        }