public Engine(string filePath, Inventor.PlanarSketch oSketch, Inventor.Application oApp, double slotHeight, double slotWidth) { _engine = Python.CreateEngine(new Dictionary <string, object>() { { "Frames", true }, { "FullFrames", true } }); _runtime = _engine.Runtime; Assembly invAssembly = Assembly.LoadFile(@"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_17.0.0.0__d84147f8b4276564\Autodesk.Inventor.interop.dll"); _runtime.LoadAssembly(invAssembly); _scope = _engine.CreateScope(); //Make variable names visible within the python file. These string names will be used an arguments in the python file. _scope.SetVariable("oPlanarSketch", oSketch); _scope.SetVariable("oApp", oApp); _scope.SetVariable("slotHeight", slotHeight); _scope.SetVariable("slotWidth", slotWidth); ScriptSource _script = _engine.CreateScriptSourceFromFile(filePath); _code = _script.Compile(); }
private Inventor.ObjectCollection CreateHoleSketch(ref Inventor.PartDocument PartDocument, ref Inventor.ExtrudeFeature ExtrudeFeature, string PCD, string PCDAngle) { Inventor.UnitsOfMeasure UnitsOfMeasure; Inventor.PlanarSketch Sketch = null; Inventor.WorkPoint WorkPoint = null; Inventor.SketchEntity CenterPointSketchEntity = null; Inventor.SketchArc pcdSketchArc = null; Inventor.SketchLine AngleSketchLine = null; Inventor.SketchLine CenterSketchLine = null; Inventor.SketchPoint SketchPoint = null; Inventor.TransientGeometry TransientGeometry; Inventor.RadiusDimConstraint RadiusDimConstraint = null; Inventor.TwoLineAngleDimConstraint TwoLineAngleDimConstraint = null; Inventor.ObjectCollection ObjectCollection = null; Inventor.ModelParameter ModelParameter = null; ObjectCollection = InvApp.TransientObjects.CreateObjectCollection(); double pcdDia = 0, pcdAngle = 0.0; UnitsOfMeasure = PartDocument.UnitsOfMeasure; pcdDia = UnitsOfMeasure.GetValueFromExpression(PCD, Inventor.UnitsTypeEnum.kMillimeterLengthUnits); pcdAngle = UnitsOfMeasure.GetValueFromExpression(PCDAngle, Inventor.UnitsTypeEnum.kDegreeAngleUnits); WorkPoint = PartDocument.ComponentDefinition.WorkPoints[1]; TransientGeometry = InvApp.TransientGeometry; foreach (Inventor.Face Face in ExtrudeFeature.EndFaces) { if (Face.SurfaceType == Inventor.SurfaceTypeEnum.kPlaneSurface) { Sketch = PartDocument.ComponentDefinition.Sketches.Add(Face, false); CenterPointSketchEntity = Sketch.AddByProjectingEntity(WorkPoint); CenterSketchLine = Sketch.SketchLines.AddByTwoPoints(TransientGeometry.CreatePoint2d(0, 0), TransientGeometry.CreatePoint2d(0, pcdDia / 2)); CenterSketchLine.Construction = true; AngleSketchLine = Sketch.SketchLines.AddByTwoPoints(CenterSketchLine.StartSketchPoint, TransientGeometry.CreatePoint2d(20, pcdDia / 2)); AngleSketchLine.Construction = true; Sketch.GeometricConstraints.AddCoincident(CenterPointSketchEntity, (Inventor.SketchEntity)CenterSketchLine.StartSketchPoint); Sketch.GeometricConstraints.AddEqualLength(CenterSketchLine, AngleSketchLine); pcdSketchArc = Sketch.SketchArcs.AddByCenterStartEndPoint(CenterSketchLine.StartSketchPoint, CenterSketchLine.EndSketchPoint, AngleSketchLine.EndSketchPoint, false); pcdSketchArc.Construction = true; Sketch.GeometricConstraints.AddVertical((Inventor.SketchEntity)CenterSketchLine, false); Sketch.GeometricConstraints.AddCoincident(CenterPointSketchEntity, (Inventor.SketchEntity)pcdSketchArc.CenterSketchPoint); SketchPoint = Sketch.SketchPoints.Add(TransientGeometry.CreatePoint2d(0, 0), true); Sketch.GeometricConstraints.AddCoincident((Inventor.SketchEntity)SketchPoint, (Inventor.SketchEntity)AngleSketchLine.EndSketchPoint); RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)pcdSketchArc, pcdSketchArc.Geometry.Center, false); if (RadiusDimConstraint.Parameter.ParameterType == Inventor.ParameterTypeEnum.kModelParameter) { ModelParameter = (Inventor.ModelParameter)RadiusDimConstraint.Parameter; if (ModelParameter.BuiltIn) { ModelParameter.Name = "PCD"; ModelParameter.Value = pcdDia / 2; } } TwoLineAngleDimConstraint = Sketch.DimensionConstraints.AddTwoLineAngle(CenterSketchLine, AngleSketchLine, TransientGeometry.CreatePoint2d(1, 1), false); if (TwoLineAngleDimConstraint.Parameter.ParameterType == Inventor.ParameterTypeEnum.kModelParameter) { ModelParameter = null; ModelParameter = (Inventor.ModelParameter)TwoLineAngleDimConstraint.Parameter; if (ModelParameter.BuiltIn) { ModelParameter.Name = "Angle"; ModelParameter.Value = pcdAngle / 2; } } ObjectCollection.Add(SketchPoint); } PartDocument.Update(); } return(ObjectCollection); }
private void DrawCircle_Constrain_Diamension(Inventor.Point2d CenterPoint, out Inventor.SketchCircle SketchCircle, out Inventor.RadiusDimConstraint RadiusDimConstraint, Inventor.PlanarSketch Sketch, Inventor.SketchEntity SketchEntity, double Radius) { //Draw SketchCircle = Sketch.SketchCircles.AddByCenterRadius(CenterPoint, Radius); //Dim RadiusDimConstraint = Sketch.DimensionConstraints.AddRadius((Inventor.SketchEntity)SketchCircle, CenterPoint, false); //Anchor Sketch.GeometricConstraints.AddCoincident(SketchEntity, (Inventor.SketchEntity)SketchCircle.CenterSketchPoint); }
private Inventor.PartDocument AddSketchProjectCenterPoint(Inventor.PartDocument PartDocument, out Inventor.PlanarSketch Sketch, out Inventor.SketchEntity SketchEntity) { Inventor.WorkPlane BaseWorkPlane; Inventor.WorkPoint WorkPoint; WorkPoint = PartDocument.ComponentDefinition.WorkPoints[1]; BaseWorkPlane = GetWorkPlane(ref PartDocument); Sketch = PartDocument.ComponentDefinition.Sketches.Add(BaseWorkPlane, false); SketchEntity = Sketch.AddByProjectingEntity(WorkPoint); return(PartDocument); }