static public TwoPointDistanceDimConstraint addTwoPointDist(SketchLine sl, string name, double offset = 0, double scale = 1) { mp = u.midPt(sl.StartSketchPoint.Geometry, sl.EndSketchPoint.Geometry, offset, 0, scale); val = ps.DimensionConstraints.AddTwoPointDistance(sl.StartSketchPoint, sl.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, mp); addName <TwoPointDistanceDimConstraint>(name); return(val as TwoPointDistanceDimConstraint); }
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); }
public SketchOp(PartDocument doc) { this.doc = doc; if (doc.ActivatedObject is PlanarSketch) { ps = doc.ActivatedObject as PlanarSketch; sl1 = addLine(); sl2 = findLine(sl1); //sl2.Construction = true; SketchLine tmp = findLine(sl2); // tmp.Construction = true; // tmp = findLine(tmp); // tmp.Construction = true; //addMidConsraint(sl); sl = addPerpendicular(sl1, sl2); //addMidConsraint(sl2); sl3 = addPerpendicular(sl2, sl1, sl); //ps.GeometricConstraints.AddCoincident(sl.EndSketchPoint as SketchEntity, sl3.EndSketchPoint as SketchEntity); //sp = ps.SketchPoints.Add(sl.Geometry.MidPoint); sp = addPoint(sl1, sl2); addDimConstr(sp, sl, Macros.StandardAddInServer.data.parX); addDimConstr(sp, sl3, Macros.StandardAddInServer.data.parY); addAttr(doc as Document, sl1, sp, tmp.Construction); //doc.Update(); } }
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); } }
//Скетч внешнего кольца public PlanarSketch OutsideRing() { PlanarSketch sketch = partCompDef.Sketches.Add(partCompDef.WorkPlanes[3]); SketchPoints points_ = sketch.SketchPoints; SketchArcs arcs_ = sketch.SketchArcs; SketchLines lines_ = sketch.SketchLines; points_.Add(transGeom.CreatePoint2d(0, D / 2)); points_.Add(transGeom.CreatePoint2d(B / 2 - r, D / 2)); points_.Add(transGeom.CreatePoint2d(B / 2 - r, D / 2 - r)); points_.Add(transGeom.CreatePoint2d(B / 2, D / 2 - r)); points_.Add(transGeom.CreatePoint2d(B / 2, D / 2 - r - 0.3 * D / 6.2)); points_.Add(transGeom.CreatePoint2d(B / 2 - 0.1 * B / 2, D / 2 - r - 0.4 * D / 6.2)); points_.Add(transGeom.CreatePoint2d(Dw / 2, (D / 2 - d / 2) / 2 + d / 2 + Dw / 2)); points_.Add(transGeom.CreatePoint2d(-Dw / 2, (D / 2 - d / 2) / 2 + d / 2 + Dw / 2)); lines_.AddByTwoPoints(points_[1], points_[2]); arcs_.AddByCenterStartEndPoint(points_[3], points_[2], points_[4], false); for (int i = 4; i < 6; i++) { lines_.AddByTwoPoints(points_[i], points_[i + 1]); } arcs_.AddByCenterStartEndPoint(transGeom.CreatePoint2d(0, 0), points_[8], points_[6], false); lines_[3].EndSketchPoint.Merge(arcs_[2].StartSketchPoint); lines_.AddByTwoPoints(arcs_[2].EndSketchPoint, points_[1]); center_line = sketch.SketchLines.AddByTwoPoints(transGeom.CreatePoint2d(-1, 0), transGeom.CreatePoint2d(1, 0)); return(sketch); }
public void addDimConstr(SketchPoint p, SketchLine sl, Parameter par = null) { Vector2d v = ut.normal(sl.StartSketchPoint.Geometry, sl.EndSketchPoint.Geometry), v1 = p.Geometry.VectorTo(sl.StartSketchPoint.Geometry); if (v.AngleTo(v1) > Math.PI / 2) { v.ScaleBy(-1); } pt = p.Geometry.Copy(); pt.TranslateBy(v); ObjectsEnumerator en = sl.Geometry.IntersectWithCurve(I.tg.CreateLineSegment2d(p.Geometry, pt), 0.1); if (en != null && en.Count != 0) { pt = en[1] as Point2d; } OffsetDimConstraint offs = ps.DimensionConstraints.AddOffset(sl, p as SketchEntity, ut.midPt(p.Geometry, pt, p.Geometry.DistanceTo(pt) / 5, 0), false); if (par != null) { offs.Parameter.Expression = par.Name; } else { offs.Parameter.Value = 0; } }
public void addMidConsraint(SketchLine line) { pt = line.Geometry.MidPoint; SketchPoint s = ps.SketchPoints.Add(pt, false); ps.GeometricConstraints.AddMidpoint(s, sl); }
public Line(SketchLine segment) { start = new Point(segment.GetStartPoint2()); end = new Point(segment.GetEndPoint2()); dir = new Vector(end.X - start.X, end.Y - start.Y, end.Z - start.Z); len = Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y + dir.Z * dir.Z); }
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); }
internal Circle(double distance, double diametr, double width, char side, SketchLine side_line) { Distance = distance; Radius = 0.5 * diametr; Width = width; Side = side; SideLine = side_line; empty = false; }
// 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); }
public static void Build(InventorAPI api, string formName) { PlanarSketch[] sketch = new PlanarSketch[4]; Profile[] profile = new Profile[4]; SketchPoint[] point = new SketchPoint[4]; SketchLine[] line = new SketchLine[4]; RevolveFeature[] revolve = new RevolveFeature[4]; // Создание цилиндра sketch[0] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[0], 0, 0); point[1] = api.Point(sketch[0], 0, H / 10); point[2] = api.Point(sketch[0], D1 / 10 / 2, H / 10); point[3] = api.Point(sketch[0], D1 / 10 / 2, 0); line[0] = api.Line(sketch[0], point[0], point[1]); line[1] = api.Line(sketch[0], point[1], point[2]); line[2] = api.Line(sketch[0], point[2], point[3]); line[3] = api.Line(sketch[0], point[3], point[0]); profile[0] = api.Profile(sketch[0]); revolve[0] = api.Revolve(profile[0], line[0], 0); // Создание пружины sketch[1] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[1], D1 / 10 / 2, 0); point[1] = api.Point(sketch[1], D / 10 / 2, 0); point[3] = api.Point(sketch[1], D1 / 10 / 2, T / 10); line[0] = api.Line(sketch[1], point[0], point[1]); line[1] = api.Line(sketch[1], point[1], point[3]); line[2] = api.Line(sketch[1], point[3], point[0]); profile[1] = api.Profile(sketch[1]); var coil = api.GetCompDef().Features.CoilFeatures.AddByPitchAndHeight(profile[1], api.GetCompDef().WorkAxes[2], H1 / 10, H2 / 10, PartFeatureOperationEnum.kJoinOperation, false, false, 0, false, 0, 0, true); // Верхняя граница пружины sketch[2] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[2], 0, H2 / 10); point[1] = api.Point(sketch[2], 0, H2 / 10 + T / 10); point[2] = api.Point(sketch[2], D / 10 / 2, H2 / 10 + T / 10); point[3] = api.Point(sketch[2], D / 10 / 2, H2 / 10); line[0] = api.Line(sketch[2], point[0], point[1]); line[1] = api.Line(sketch[2], point[1], point[2]); line[2] = api.Line(sketch[2], point[2], point[3]); line[3] = api.Line(sketch[2], point[3], point[0]); profile[2] = api.Profile(sketch[2]); revolve[2] = api.Revolve(profile[2], line[0], 0); // Крепление sketch[3] = api.Sketch(api.GetCompDef().WorkPlanes[3]); point[0] = api.Point(sketch[3], 0, H3 / 10); point[1] = api.Point(sketch[3], 0, H3 / 10 + A / 10); point[2] = api.Point(sketch[3], D / 10 / 2, H3 / 10 + A / 10); point[3] = api.Point(sketch[3], D / 10 / 2, H3 / 10); line[0] = api.Line(sketch[3], point[0], point[1]); line[1] = api.Line(sketch[3], point[1], point[2]); line[2] = api.Line(sketch[3], point[2], point[3]); line[3] = api.Line(sketch[3], point[3], point[0]); profile[3] = api.Profile(sketch[3]); revolve[3] = api.Revolve(profile[3], line[0], 0); System.Windows.Forms.MessageBox.Show(formName + " завершено.", formName); }
public void NewLine() { print("Created new line."); var lineObj = Instantiate(LinePrefab, transform); lineObj.transform.localPosition = Vector3.zero; currentLine = lineObj.GetComponent <SketchLine>(); currentLine.Color = CurrentColor; lines.Add(currentLine); }
public SketchPoint addPoint(SketchLine sl1, SketchLine sl2) { Vector2d v1 = addVec(sp, sl1), v2 = addVec(sp, sl2); pt = sp.Geometry.Copy(); v1.AddVector(v2); v1.ScaleBy(0.4); pt.TranslateBy(v1); return(ps.SketchPoints.Add(pt)); }
public void dimConstr() { SketchArc arc = ent as SketchArc; SketchLine sl = ps.SketchLines.AddByTwoPoints(arc.EndSketchPoint, arc.CenterSketchPoint); sl.Construction = true; SketchLine sl1 = ps.SketchLines.AddByTwoPoints(arc.StartSketchPoint, arc.CenterSketchPoint); sl1.Construction = true; RadiusDimConstraint r = constraints.addRadius(ent, sl.StartSketchPoint, sl1.StartSketchPoint, name); constraints.addTwoLineAngle(sl, sl1, arc.CenterSketchPoint, name); r.TextPoint = u.midPt(sl.StartSketchPoint.Geometry, sl.EndSketchPoint.Geometry, 0.4); }
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); }
/// <summary> /// 创建多个加强筋 /// </summary> /// <param name="osketch"></param> /// <param name="line"></param> private void CreateRibs(PlanarSketch osketch, SketchLine line) { double distance = (parCylinder.Length - parCylinder.RibFirstDistance) / parCylinder.RibNumber; for (int i = 0; i < parCylinder.RibNumber; i++) { SketchLine L; CreateRib(osketch, out L); osketch.GeometricConstraints.AddCollinear((SketchEntity)line, (SketchEntity)L); CreateTwoPointDistanceConstraint(osketch, line.EndSketchPoint, L.EndSketchPoint, distance * i + parCylinder.RibFirstDistance); } }
static public SketchLine midleLine(SketchLine sl1, SketchLine sl2) { PlanarSketch ps = (PlanarSketch)sl1.Parent; SketchPoint sp1 = ps.SketchPoints.Add(sl1.Geometry.MidPoint, false); SketchPoint sp2 = ps.SketchPoints.Add(sl2.Geometry.MidPoint, false); SketchLine sl3 = ps.SketchLines.AddByTwoPoints(sp1, sp2); MidpointConstraint mpc = ps.GeometricConstraints.AddMidpoint(sp1, sl1); mpc = ps.GeometricConstraints.AddMidpoint(sp2, sl2); sl3.Construction = true; return(sl3); }
/// <summary> /// select a SketchLine and SketchCircle and get their intersect points /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button2_Click(object sender, EventArgs e) { if (((mApp.ActiveDocument != null))) { if ((mApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject)) { PartDocument oDoc = mApp.ActiveDocument as PartDocument; if ((oDoc.SelectSet.Count == 2)) { if (((oDoc.SelectSet[1]) is SketchLine & (oDoc.SelectSet[2]) is SketchCircle)) { SketchLine oSketchLine = oDoc.SelectSet[1] as SketchLine; SketchCircle oSketchCircle = oDoc.SelectSet[2] as SketchCircle; Line2d oLine2d = mApp.TransientGeometry.CreateLine2d(oSketchLine.Geometry.StartPoint, oSketchLine.Geometry.Direction); Circle2d oCircle2d = oSketchCircle.Geometry; ObjectsEnumerator objectsEnum = oLine2d.IntersectWithCurve(oCircle2d, 0.0001); if ((objectsEnum == null)) { System.Windows.Forms.MessageBox.Show("No intersection between extended Line and Circle", "BRep Sample"); return; } string strResult = "Intersection point(s): \n"; int i = 0; for (i = 1; i <= objectsEnum.Count; i++) { Point2d oPoint = objectsEnum[i] as Point2d; strResult += "[" + oPoint.X.ToString("F2") + ", " + oPoint.Y.ToString("F2") + "]" + "\n"; } System.Windows.Forms.MessageBox.Show(strResult, "BRep Sample"); return; } else { System.Windows.Forms.MessageBox.Show("Entity 1 must be a SketchLine, Entity 2 must be a SketchCircle", "BRep Sample"); return; } } else { System.Windows.Forms.MessageBox.Show("Incorrect selection of sketch entities", "BRep Sample"); return; } } } }
void setCenter(SketchLine sl) { Vector2d v = sl.Geometry.Direction.AsVector(); double a = ang < 0 ? -Math.PI / 2: Math.PI / 2; u.rotate(v, sl.EndSketchPoint.Geometry, a); v.ScaleBy(R); Point2d pt = sl.EndSketchPoint.Geometry; pt.TranslateBy(v); x = pt.X; y = pt.Y; cen = u.createPoint2d(x, y); }
static public TwoLineAngleDimConstraint addTwoLineAngle(SketchLine sl1, SketchLine sl2, SketchPoint sp = null, string name = "", double w = 0.5) { if (sp != null) { mp = u.midPt(sp.Geometry, mp, w); } else { mp = u.midPt(sl1.StartSketchPoint.Geometry, sl2.EndSketchPoint.Geometry, w); } val = ps.DimensionConstraints.AddTwoLineAngle(sl1, sl2, mp); addName <TwoLineAngleDimConstraint>(name, "A"); return(val as TwoLineAngleDimConstraint); }
public Vector2d addVec(SketchPoint pt, SketchLine dir) { Vector2d v; if (ut.eq(sp.Geometry, dir.StartSketchPoint.Geometry)) { v = dir.StartSketchPoint.Geometry.VectorTo(dir.EndSketchPoint.Geometry); } else { v = dir.EndSketchPoint.Geometry.VectorTo(dir.StartSketchPoint.Geometry); } return(v); }
public SketchLine findLine(SketchLine sl) { sp = sl.StartSketchPoint; SketchLine line = findPoint(sp, sl); if (line != null) { return(line); } else { sp = sl.EndSketchPoint; return(findPoint(sp, sl)); } }
public SketchLine findPoint(SketchPoint sp, SketchLine sl) { foreach (CoincidentConstraint item in sp.Constraints) { if (item.EntityOne is SketchLine && !item.EntityOne.Equals(sl)) { return(item.EntityOne as SketchLine); } if (item.EntityTwo is SketchLine && !item.EntityTwo.Equals(sl)) { return(item.EntityTwo as SketchLine); } } return(null); }
public void DrawArrow(float x, float y, float angle, float arrowLength, float length = 0.5f, float arrowAngle = 20, float lineWeight = 0.01f) { //рисует стрелку. менять ничего не надо и вызывать ее тоже не надо angle = (float)(angle * Math.PI / 180); this.sketch.Edit(); Point2d endPoint = this.transGeom.CreatePoint2d(x, y); Point2d startPoint = this.transGeom.CreatePoint2d(endPoint.X - arrowLength * Math.Cos(angle), endPoint.Y - arrowLength * Math.Sin(angle)); SketchLine arrowLine = this.sketch.SketchLines.AddByTwoPoints(endPoint, startPoint); arrowLine.LineWeight = lineWeight; this.sketch.ExitEdit(); this.DrawEndArrow(endPoint, angle, length, arrowAngle); }
//Зеркальное отражение детали 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); }
public void addAttr(Document doc, SketchLine sl, SketchPoint sp, bool contstr) { VariableData vd = new VariableData(doc as Document); UnitVector vec = sl.Geometry3d.Direction; AttributeSet attSet = vd.AttribSetAdd(sp, "dir"); attSet.Add("X", ValueTypeEnum.kDoubleType, vec.X); attSet.Add("Y", ValueTypeEnum.kDoubleType, vec.Y); attSet.Add("Z", ValueTypeEnum.kDoubleType, vec.Z); if (contstr) { string val = ut.getRefkey <SketchLine>(doc, sl, 0); vd.AttribAdd <SketchPoint, string>(sp, "SL", val, ValueTypeEnum.kStringType); } }
public LineInv(SketchLine line, bool f = false, bool close = false) : base(entTypes.Line) { L = line.Length * 10; dir = line.Geometry.Direction.AsVector(); if (line.Constraints.OfType <TangentSketchConstraint>().Count() != 0) { con = cType.t; } Point2d pt = line.StartSketchPoint.Geometry; if (f) { x = pt.X; y = pt.Y; first = true; } }
void select(int index, string point) { if (index < 0) { index = (iSegments - 1) - abs(index); } SketchLine line = (SketchLine)Segments[index]; if (point == "a" || point == "A") { ((SketchPoint)line.GetStartPoint2()).Select(true); } if (point == "b" || point == "B") { ((SketchPoint)line.GetEndPoint2()).Select(true); } }
public static void DimensionWith(this SketchLine l1, SketchLine l2, double value, string linkName, SldWorks swApp) { ModelDoc2 swDoc = (ModelDoc2)swApp.ActiveDoc; bool bl = false; swDoc.ClearSelection2(true); bl = ((SketchSegment)l1).Select(false); bl = ((SketchSegment)l2).Select(true); Point textPoint = new Point((l1.toLine().Start.X + l2.toLine().Start.X) / 2, (l1.toLine().Start.Y + l2.toLine().Start.Y) / 2, (l1.toLine().Start.Z + l2.toLine().Start.Z) / 2); swDoc.AddDimension2(textPoint.X, textPoint.Y, 0); swDoc.ClearSelection2(true); }
protected override void ButtonDefinition_OnExecute(NameValueMap context) { try { //check to make sure a sketch is active if (InventorApplication.ActiveEditObject is PlanarSketch) { //if same session, combobox definitions will already exist ComboBoxDefinition slotWidthComboBoxDefinition; slotWidthComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotWidthCboBox"]; ComboBoxDefinition slotHeightComboBoxDefinition; slotHeightComboBoxDefinition = (Inventor.ComboBoxDefinition)InventorApplication.CommandManager.ControlDefinitions["Autodesk:SimpleAddIn:SlotHeightCboBox"]; //get the selected width from combo box double slotWidth; slotWidth = slotWidthComboBoxDefinition.ListIndex; //get the selected height from combo box double slotHeight; slotHeight = slotHeightComboBoxDefinition.ListIndex; if (slotWidth > 0 && slotHeight > 0) { //draw the sketch for the slot PlanarSketch planarSketch; planarSketch = (PlanarSketch)InventorApplication.ActiveEditObject; SketchLine[] lines = new SketchLine[2]; SketchArc[] arcs = new SketchArc[2]; TransientGeometry transientGeometry; transientGeometry = InventorApplication.TransientGeometry; //start a transaction so the slot will be within a single undo step Transaction createSlotTransaction; createSlotTransaction = InventorApplication.TransactionManager.StartTransaction(InventorApplication.ActiveDocument, "Create Slot"); //draw the lines and arcs that make up the shape of the slot lines[0] = planarSketch.SketchLines.AddByTwoPoints(transientGeometry.CreatePoint2d(0, 0), transientGeometry.CreatePoint2d(slotWidth, 0)); arcs[0] = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(slotWidth, slotHeight / 2.0), lines[0].EndSketchPoint, transientGeometry.CreatePoint2d(slotWidth, slotHeight), true); lines[1] = planarSketch.SketchLines.AddByTwoPoints(arcs[0].EndSketchPoint, transientGeometry.CreatePoint2d(0, slotHeight)); arcs[1] = planarSketch.SketchArcs.AddByCenterStartEndPoint(transientGeometry.CreatePoint2d(0, slotHeight / 2.0), lines[1].EndSketchPoint, lines[0].StartSketchPoint, true); //create the tangent constraints between the lines and arcs planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[0], null); planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[0], null); planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[1], (SketchEntity)arcs[1], null); planarSketch.GeometricConstraints.AddTangent((SketchEntity)lines[0], (SketchEntity)arcs[1], null); //create a parallel constraint between the two lines planarSketch.GeometricConstraints.AddParallel((SketchEntity)lines[0], (SketchEntity)lines[1], true, true); //end the transaction createSlotTransaction.End(); } else { //valid width/height was not specified MessageBox.Show("Please specify valid slot width and height"); } } else { //no sketch is active, so display an error MessageBox.Show("A sketch must be active for this command"); } } catch(Exception e) { MessageBox.Show(e.ToString()); } }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// //// //// //// Use: Lab solution. Creation of an iPart from scratch /////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateiPart() { PartDocument oPartDoc; oPartDoc = (PartDocument)_InvApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, _InvApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), true); oPartDoc.SaveAs("c:\\Temp\\APIiPart.ipt", false); TransientGeometry oTG; oTG = _InvApplication.TransientGeometry; PartComponentDefinition oCompDef; oCompDef = oPartDoc.ComponentDefinition; Point2d[] oPoints = new Point2d[3]; oPoints[0] = oTG.CreatePoint2d(0, 0); oPoints[1] = oTG.CreatePoint2d(5, 0); oPoints[2] = oTG.CreatePoint2d(5, 5); oPoints[3] = oTG.CreatePoint2d(0, 5); PlanarSketch oSketch; oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[1]); SketchLine[] oLines = new SketchLine[3]; 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, oLines[0].StartSketchPoint); Profile oProfile; oProfile = oSketch.Profiles.AddForSolid(); ExtrudeFeature oExtrude; oExtrude = oCompDef.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, 15, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, 0); oExtrude.FeatureDimensions[1].Parameter.Name = "Length"; oExtrude.FeatureDimensions[2].Parameter.Name = "TaperAngle"; iPartFactory oFactory; oFactory = oCompDef.CreateFactory(); Microsoft.Office.Interop.Excel.Worksheet oWS; oWS = oFactory.ExcelWorkSheet; oWS.Cells[1, 1] = "Member<defaultRow>1</defaultRow><filename></filename>"; oWS.Cells[1, 2] = "Part Number [Project]"; oWS.Cells[1, 3] = "Length<free>150 mm</free>"; oWS.Cells[1, 4] = "TaperAngle"; oWS.Cells[2, 1] = "APIiPart-01"; oWS.Cells[2, 2] = "APIiPart-01"; oWS.Cells[2, 3] = "150 mm"; oWS.Cells[2, 4] = "0 deg"; oWS.Cells[3, 1] = "APIiPart-02"; oWS.Cells[3, 2] = "APIiPart-02"; oWS.Cells[3, 3] = "100 mm"; oWS.Cells[3, 4] = "5 deg"; oWS.Cells[4, 1] = "APIiPart-03"; oWS.Cells[4, 2] = "APIiPart-03"; oWS.Cells[4, 3] = "50 mm"; oWS.Cells[4, 4] = "10 deg"; Microsoft.Office.Interop.Excel.Workbook oWB; oWB = oWS.Parent; oWB.Save(); oWB.Close(); oPartDoc.Update(); oPartDoc.Save(); }
private void Button1_Click(object sender, EventArgs e) { PartDocument oDoc = mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject, mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject, SystemOfMeasureEnum.kDefaultSystemOfMeasure, DraftingStandardEnum.kDefault_DraftingStandard, null), true) as PartDocument; // Get the XZ Plane WorkPlane oWorkPlane = oDoc.ComponentDefinition.WorkPlanes[2]; PlanarSketch oSketch = oDoc.ComponentDefinition.Sketches.Add(oWorkPlane, false); TransientGeometry oTG = mApp.TransientGeometry; //Create some transient points used for defining the lines (see BRep Module) Point2d[] oPoints = new Point2d[5]; oPoints[0] = oTG.CreatePoint2d(0, 0); oPoints[1] = oTG.CreatePoint2d(-10, 0); oPoints[2] = oTG.CreatePoint2d(-10, -10); oPoints[3] = oTG.CreatePoint2d(5, -10); oPoints[4] = oTG.CreatePoint2d(5, -5); //Add the sketchlines, coincident constraints will be created automatically //since the "Line.EndSketchPoint" are provided each time we create a new line SketchLine[] oLines = new SketchLine[5]; oLines[0] = oSketch.SketchLines.AddByTwoPoints(oPoints[0], oPoints[1]); oLines[1] = oSketch.SketchLines.AddByTwoPoints(oLines[0].EndSketchPoint, oPoints[2]); oLines[2] = oSketch.SketchLines.AddByTwoPoints(oLines[1].EndSketchPoint, oPoints[3]); oLines[3] = oSketch.SketchLines.AddByTwoPoints(oLines[2].EndSketchPoint, oPoints[4]); oSketch.SketchArcs.AddByCenterStartEndPoint(oTG.CreatePoint2d(0, -5), oLines[3].EndSketchPoint, oLines[0].StartSketchPoint, true); //Create a profile for the extrusion, here no need to worry since there is only //a single profile that is possible Profile oProfile = oSketch.Profiles.AddForSolid(true, null, null); //this is the old way, i.e. create the extrude feature directly. it is still supported for backward compatibility //ExtrudeFeature oExtrude = oDoc.ComponentDefinition.Features.ExtrudeFeatures.AddByDistanceExtent(oProfile, // 5.0, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, PartFeatureOperationEnum.kNewBodyOperation, 0.0); // Definition Way: PartComponentDefinition oPartDocDef = oDoc.ComponentDefinition; // get ExtrudeFeatures collection ExtrudeFeatures extrudes = oPartDocDef.Features.ExtrudeFeatures; // Create an extrude definition in the new surface body ExtrudeDefinition extrudeDef = extrudes.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation); // Modify the extent and taper angles. extrudeDef.SetDistanceExtent(8, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); extrudeDef.SetDistanceExtentTwo(20); extrudeDef.TaperAngle = "-2 deg"; extrudeDef.TaperAngleTwo = "-10 deg"; // Create the extrusion. ExtrudeFeature extrude = extrudes.Add(extrudeDef); //Fit the view programmatically Camera oCamera = mApp.ActiveView.Camera; oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation; oCamera.Apply(); mApp.ActiveView.Fit(true); }