public void UT_CutBeamByPart() { // test 0: обрезаем балку ThisBeam балкой MainBeam //.. создаем балку [0, 1000 - 2000,1000] I20 и обрезает ее //.. балкой MainBeam [500,0 - 500, 1500] I50 Point p1 = new Point(0, 3000); Point p2 = new Point(2000, 3000); ThisBeam = _TS.CreateBeam("ThisBeam", "I20B1_20_93", p1, p2 , PositionDepth: (int)Position.DepthEnum.MIDDLE); Point cp1 = new Point(1000, 0); Point cp2 = new Point(1000, 4000); MainBeam = _TS.CreateBeam("MainBeam", "I50B1_20_93", cp1, cp2 , PositionDepth: (int)Position.DepthEnum.MIDDLE , Class: BooleanPart.BooleanOperativeClassName); ThisBeam = _TS.CutBeamByPart(ThisBeam, MainBeam, false); // стираем ThisBeam и MainBeam // ThisBeam.Delete(); // MainBeam.Delete(); // Model.CommitChanges(); // test 1: обрезаем балку ThisBeam пластиной Plate p1 = new Point(3000, 2000, 1000); p2 = new Point(5000, 1000, 0); ThisBeam = _TS.CreateBeam("ThisBeam", "I20B1_20_93", p1, p2); ContourPoint c1 = new ContourPoint(new Point(4000, 1000, 0), null); ContourPoint c2 = new ContourPoint(new Point(4000, 3000, 0), null); ContourPoint c3 = new ContourPoint(new Point(4000, 3000, 2000), null); ContourPoint c4 = new ContourPoint(new Point(4000, 1000, 2000), null); var Plate = new ContourPlate(); Plate.AddContourPoint(c1); Plate.AddContourPoint(c2); Plate.AddContourPoint(c3); Plate.AddContourPoint(c4); Plate.Profile.ProfileString = "PL200"; Plate.Material.MaterialString = "C245"; Plate.Class = "2"; Plate.Name = "PLATE"; Plate.Insert(); Model.CommitChanges(); ThisBeam = _TS.CutBeamByPart(ThisBeam, Plate, false); // ThisBeam.Delete(); Plate.Delete(); Model.CommitChanges(); }
/// <summary> /// Adds the cut for the wallshoe components /// </summary> /// <param name="variables">List of doubles with dimensions of the component</param> /// <param name="p1">The point which gives the x position of the component on fatherpart</param> /// <param name="minY">Fatherparts solids miminum Y position</param> /// <param name="maxY">Fatherparts solids miminum Y position</param> /// <param name="changeDirection">Boolean to give the direction</param> /// <param name="fatherpart">Part to insert the cut to</param> private bool AddWallShoeCut(double[] variables, Point p1, double minY, double maxY, bool changeDirection, Part fatherpart) { try { ContourPlate cutpart = new ContourPlate(); BooleanPart bPart = new BooleanPart(); cutpart.Name = "Leikkaus"; cutpart.Position.Depth = Position.DepthEnum.MIDDLE; cutpart.Position.Plane = Position.PlaneEnum.MIDDLE; cutpart.Class = BooleanPart.BooleanOperativeClassName; cutpart.Material.MaterialString = "Reikä"; cutpart.Profile.ProfileString = "PL135"; cutpart.Profile.ProfileString = "PL" + variables[4]; if (!changeDirection) { cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - variables[0], p1.Z + variables[1]), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - variables[0], p1.Z + variables[1] + variables[2]), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + variables[1] + variables[2] + (Math.Tan(variables[3] * Math.PI / 180) * ((maxY - minY) / 2 + variables[0]))), null)); } else { cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y + variables[0], p1.Z + variables[1]), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y + variables[0], p1.Z + variables[1] + variables[2]), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + variables[1] + variables[2] + (Math.Tan(variables[3] * Math.PI / 180) * ((minY - maxY) / 2 + variables[0]))), null)); } cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + variables[1]), null)); cutpart.Insert(); bPart.Father = fatherpart; bPart.SetOperativePart(cutpart); if (!bPart.Insert()) { WriteLog("Leikkauksen (1) tekeminen epäonnistui!"); } cutpart.Delete(); } catch (Exception ex) { WriteLog(ex.Message + "\n" + ex.StackTrace); return(false); } return(true); }
public static ContourPlate InsertCutPlate(ContourPlate cuttedPlate, ArrayList points, string profileString, string materialString, Chamfer chamfer = null) { var cp = new ContourPlate(); foreach (Point point in points) { cp.AddContourPoint(point, chamfer); } cp.Profile.ProfileString = profileString; cp.Material.MaterialString = materialString; cp.Class = BooleanPart.BooleanOperativeClassName; cp.Insert(); var bp = new BooleanPart { Type = BooleanPart.BooleanTypeEnum.BOOLEAN_CUT, Father = cuttedPlate }; bp.SetOperativePart(cp); bp.Insert(); cp.Delete(); return(cp); }
public override bool Run(List <InputDefinition> Input) { try { GetValuesFromDialog(); WorkPlaneHandler wph = Model.GetWorkPlaneHandler(); TransformationPlane tp = wph.GetCurrentTransformationPlane(); TransformationPlane tppart = null; BoltGroup bg = Model.SelectModelObject((Identifier)Input[0].GetInput()) as BoltGroup; bg.Select(); List <Part> parts = new List <Part>(); parts.Add(bg.PartToBeBolted); parts.Add(bg.PartToBoltTo); foreach (Part p in bg.OtherPartsToBolt) { parts.Add(p); } #region Clear List <Part> _part = new List <Part>(); foreach (Part p in parts) { bool flag = false; foreach (Part pp in _part) { if (pp.Identifier.ID == p.Identifier.ID) { flag = true; } } if (!flag) { _part.Add(p); } } parts.Clear(); parts = _part; #endregion foreach (Part p in parts) { if (p is Beam) { Beam b = p as Beam; b.Select(); double k = 0.0; b.GetReportProperty("PROFILE.FLANGE_SLOPE_RATIO", ref k); if (k == 0) { continue; } tppart = new TransformationPlane(p.GetCoordinateSystem()); wph.SetCurrentTransformationPlane(tppart); bg.Select(); foreach (Point pb in bg.BoltPositions) { Point _pb = new Point(pb); #region Уклон полок - точки через солид GeometricPlane gp = new GeometricPlane( _pb, new Vector(0, 1, 0), new Vector(0, 0, 1)); List <List <Point> > lp = IntersectSolid(p.GetSolid(), gp); List <LineSegment> ls = new List <LineSegment>(); for (int i = 0; i < lp[0].Count - 1; i++) { Point p1 = lp[0][i]; Point p2 = lp[0][i + 1]; Vector v = new Vector(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z); v.Normalize(1.0); if (v.Y != 0 && v.Z != 0) { ControlLine cl = new ControlLine(); cl.Line.Point1 = p1; cl.Line.Point2 = p2; // cl.Insert(); ls.Add(new LineSegment(p1, p2)); } } Point _p1 = lp[0][0]; Point _p2 = lp[0][lp[0].Count - 1]; Vector _v = new Vector(_p2.X - _p1.X, _p2.Y - _p1.Y, _p2.Z - _p1.Z); if (_v.Y != 0 && _v.Z != 0) { ls.Add(new LineSegment(_p1, _p2)); ControlLine cl = new ControlLine(); cl.Line.Point1 = _p1; cl.Line.Point2 = _p2; // cl.Insert(); } #endregion #region Точки для построения пластины double diam = bg.BoltSize; double tol = GOST_10906_78[diam][0]; double _b = GOST_10906_78[diam][1]; double t1 = GOST_10906_78[diam][2]; double t2 = GOST_10906_78[diam][3]; int kf = (_pb.Z <= ((Point)b.GetReferenceLine(false)[0]).Z ? -1 : 1); _pb.Z += kf * _b * 0.5; double h = double.MaxValue; LineSegment lsb = ls[0]; foreach (LineSegment lsi in ls) { double t = Distance.PointToLineSegment(_pb, lsi); if (h >= t) { h = t; lsb = lsi; } } //ControlLine cli = new ControlLine(); //cli.Line.Point1 = lsb.Point1; //cli.Line.Point2 = lsb.Point2; //cli.Insert(); Point pb1 = new Point(_pb.X, _pb.Y + 1000, _pb.Z); Point pbi = Intersection.LineToLine( new Line(lsb), new Line(_pb, pb1)).Point1; //cli.Line.Point1 = _pb; //cli.Line.Point2 = pbi; //cli.Insert(); #endregion ContourPlate cp = new ContourPlate(); Contour cr = new Contour(); cr.AddContourPoint(new ContourPoint(new Point(pbi.X - _b * 0.5, pbi.Y, pbi.Z), null)); cr.AddContourPoint(new ContourPoint(new Point(pbi.X + _b * 0.5, pbi.Y, pbi.Z), null)); cr.AddContourPoint(new ContourPoint(new Point(pbi.X + _b * 0.5, pbi.Y, pbi.Z - kf * _b), null)); cr.AddContourPoint(new ContourPoint(new Point(pbi.X - _b * 0.5, pbi.Y, pbi.Z - kf * _b), null)); cp.Contour = cr; cp.Profile.ProfileString = "PL" + t1.ToString(); cp.AssemblyNumber.Prefix = prefix_asm; cp.AssemblyNumber.StartNumber = start_part; cp.PartNumber.Prefix = prefix_part; cp.PartNumber.StartNumber = start_part; cp.Name = name; cp.Material.MaterialString = material; cp.Finish = finish; if (kf == -1 && pbi.Y > 0) { cp.Position.Depth = Position.DepthEnum.FRONT; } else if (kf == -1 && pbi.Y < 0) { cp.Position.Depth = Position.DepthEnum.BEHIND; } else if (kf == 1 && pbi.Y > 0) { cp.Position.Depth = Position.DepthEnum.BEHIND; } else if (kf == 1 && pbi.Y < 0) { cp.Position.Depth = Position.DepthEnum.FRONT; } cp.Insert(); if (weight != 0.0 && us_prop_weight != "") { cp.SetUserProperty(us_prop_weight, weight); cp.Modify(); } BooleanPart bp = new BooleanPart(); ContourPlate cp2 = new ContourPlate(); Contour cr2 = new Contour(); cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y, pbi.Z), null)); cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y, pbi.Z - kf * _b), null)); cr2.AddContourPoint(new ContourPoint(new Point(pbi.X, pbi.Y + (pbi.Y > 0 ? -1 * (t1 - t2) : (t1 - t2)), pbi.Z - kf * _b), null)); cp2.Contour = cr2; cp2.Profile.ProfileString = "PL" + (_b + 10).ToString(); cp2.Class = BooleanPart.BooleanOperativeClassName; cp2.Insert(); bp.Father = cp; bp.OperativePart = cp2; bp.Insert(); cp2.Delete(); BoltArray ba = new BoltArray(); ba.FirstPosition = pb; ba.SecondPosition = new Point(pb.X + 100, pb.Y, pb.Z); ba.BoltStandard = bg.BoltStandard; ba.Position.Rotation = Position.RotationEnum.TOP; ba.BoltType = bg.BoltType; ba.BoltSize = bg.BoltSize; ba.Tolerance = tol; ba.Bolt = false; ba.AddBoltDistX(0); ba.AddBoltDistY(0); ba.PartToBeBolted = cp; ba.PartToBoltTo = cp; ba.Insert(); } } } wph.SetCurrentTransformationPlane(tp); } catch (Exception Exc) { MessageBox.Show(Exc.ToString()); } return(true); }
public void createconnection(Part main, ArrayList secondries) { foreach (Identifier secondry in secondries) { Part part1 = main; Part part2 = (Part)this.myModel.SelectModelObject(secondry); List <Beam> beamList = new List <Beam>(); this.myModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(new TransformationPlane(part1.GetCoordinateSystem())); Tekla.Structures.Model.Solid solid1 = part1.GetSolid(); Point maximumPoint = solid1.MaximumPoint; Point minimumPoint = solid1.MinimumPoint; Tekla.Structures.Model.Solid solid2 = part2.GetSolid(); double num = 0.0; Type type = part1.GetType(); if (type.Name == "Beam") { num = solid2.MaximumPoint.X; } else if (type.Name == "ContourPlate") { num = solid2.MaximumPoint.Y; } Assembly assembly = part2.GetAssembly(); assembly.SetMainPart(part2); ArrayList secondaries = assembly.GetSecondaries(); Point point1 = new Point(); Point point2 = new Point(); Point point3 = new Point(); Point point4 = new Point(); if (type.Name == "Beam") { point1 = new Point(num, maximumPoint.Y + this.data.positive_Y + this.data.Plate_h, maximumPoint.Z + this.data.negative_X + this.data.Plate_h); point2 = new Point(num, maximumPoint.Y + this.data.positive_Y + this.data.Plate_h, minimumPoint.Z + this.data.positive_X * -1.0 - this.data.Plate_h); point3 = new Point(num, minimumPoint.Y + this.data.negative_Y * -1.0 - this.data.Plate_h, minimumPoint.Z + this.data.positive_X * -1.0 - this.data.Plate_h); point4 = new Point(num, minimumPoint.Y + this.data.negative_Y * -1.0 - this.data.Plate_h, maximumPoint.Z + this.data.negative_X + this.data.Plate_h); } else if (type.Name == "ContourPlate") { point1 = new Point(maximumPoint.X + this.data.positive_Y + this.data.Plate_h, num, maximumPoint.Z + this.data.negative_X + this.data.Plate_h); point2 = new Point(maximumPoint.X + this.data.positive_Y + this.data.Plate_h, num, minimumPoint.Z + this.data.positive_X * -1.0 - this.data.Plate_h); point3 = new Point(minimumPoint.X + this.data.negative_Y * -1.0 - this.data.Plate_h, num, minimumPoint.Z + this.data.positive_X * -1.0 - this.data.Plate_h); point4 = new Point(minimumPoint.X + this.data.negative_Y * -1.0 - this.data.Plate_h, num, maximumPoint.Z + this.data.negative_X + this.data.Plate_h); } for (int index = 0; index < secondaries.Count; ++index) { if (secondaries[index].GetType().Name == "PolyBeam") { secondaries.RemoveAt(secondaries.IndexOf(secondaries[index])); if (index >= 0) { --index; continue; } if (secondaries.Count == 0) { break; } } Part Part_To_Be_Cut = (Part)secondaries[index]; if (Part_To_Be_Cut.Class != "211") { this.CreateCut(point1, point2, point3, point4, Part_To_Be_Cut).Delete(); } } ContourPlate cut = this.CreateCut(point1, point2, point3, point4, part2); OBB obb1 = new OBB(); OBB obb2 = this.CreateObb((Part)cut); foreach (LineSegment lineSegment in this.Get_Lower_face_edge(part2)) { if (obb2.Intersects(lineSegment)) { try { LineSegment obb3 = Intersection.LineSegmentToObb(lineSegment, obb2); Beam beam = this.insert_toeplate(obb3.Point1, obb3.Point2); this.insert_weld(part2, (Part)beam); beamList.Add(beam); } catch (Exception) { } } } cut.Delete(); for (int index = 0; index < beamList.Count; ++index) { try { this.part_cut((Part)beamList[index], (Part)beamList[index + 1]); } catch (Exception) { } } try { this.part_cut((Part)beamList[beamList.Count - 1], (Part)beamList[0]); } catch (Exception) { } for (int index = 0; index < secondaries.Count; ++index) { if (secondaries[index] is Beam beam && beam.Class == "211") { secondaries.Remove((object)beam); index = -1; } } foreach (Part GPart in secondaries) { foreach (LineSegment lineSegment in this.Get_Lower_face_edge(GPart)) { if (obb2.Intersects(lineSegment)) { try { LineSegment obb3 = Intersection.LineSegmentToObb(lineSegment, obb2); Beam beam = this.insert_toeplate(obb3.Point1, obb3.Point2); beamList.Add(beam); } catch (Exception) { } } } } for (int index1 = 0; index1 <= beamList.Count - 1; ++index1) { Beam beam1 = beamList[index1]; for (int index2 = index1 + 1; index2 <= beamList.Count - 1; ++index2) { Beam beam2 = beamList[index2]; this.combine_beams_have_same_vector((Part)beam1, (Part)beam2); } } } }
private void InsertComponents(ModelObject mObj, List <TSM.Component> components) { TransformationPlane originalTransformationplane = null; try { lock (wHandler) { originalTransformationplane = wHandler.GetCurrentTransformationPlane(); } ComponentInput compInput = new ComponentInput(); Part fatherpart = mObj as Part; Assembly assembly = fatherpart.GetAssembly(); // Get the transformationplane from objects coordinate systems vectors and because objects coordinate system is not the same XY plane as of models, // so cross product needs to be made for the Y-axis TransformationPlane fatherpartsTransformationPlane = new TransformationPlane(fatherpart.GetCoordinateSystem().Origin, fatherpart.GetCoordinateSystem().AxisX, Vector.Cross(fatherpart.GetCoordinateSystem().AxisY, fatherpart.GetCoordinateSystem().AxisX)); lock (wHandler) { wHandler.SetCurrentTransformationPlane(fatherpartsTransformationPlane); } double minX = fatherpart.GetSolid().MinimumPoint.X; double minY = fatherpart.GetSolid().MinimumPoint.Y; double minZ = fatherpart.GetSolid().MinimumPoint.Z; double maxX = fatherpart.GetSolid().MaximumPoint.X; double maxY = fatherpart.GetSolid().MaximumPoint.Y; double maxZ = fatherpart.GetSolid().MaximumPoint.Z; Solid s = fatherpart.GetSolid(); FaceEnumerator fEnum = s.GetFaceEnumerator(); StringBuilder sb = new StringBuilder(); while (fEnum.MoveNext()) { sb.AppendLine(fEnum.Current.Normal.ToString()); } Point p1 = null; Point p2 = null; List <Point> cutPartPoints = new List <Point>() { new Point(), new Point(), new Point(), new Point() }; ContourPlate cutpart = null; for (int i = 0; i < components.Count; i++) { cutpart = new ContourPlate(); cutpart.Name = "Leikkaus"; cutpart.Position.Depth = Position.DepthEnum.MIDDLE; cutpart.Position.Plane = Position.PlaneEnum.MIDDLE; cutpart.Class = BooleanPart.BooleanOperativeClassName; cutpart.Material.MaterialString = "Reikä"; cutpart.Profile.ProfileString = "PL135"; BooleanPart bPart = new BooleanPart(); compInput = new ComponentInput(); switch (i) { case 0: p1 = new Point(minX + 300, 0, minZ); p2 = new Point(minX + 300, maxY, minZ); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 40), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 161.68), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 161.68 + (Math.Tan(9.88 * Math.PI / 180) * ((maxY - minY) / 2 + 52))), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 40), null)); cutpart.Insert(); bPart.Father = fatherpart; bPart.SetOperativePart(cutpart); if (!bPart.Insert()) { SetInfoText("Leikkauksen (1) tekeminen epäonnistui!"); } cutpart.Delete(); break; case 1: p1 = new Point(maxX - 300, 0, minZ); p2 = new Point(maxX - 300, maxY, minZ); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 40), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, p1.Y - 52, p1.Z + 161.68), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 161.68 + (Math.Tan(9.88 * Math.PI / 180) * ((maxY - minY) / 2 + 52))), null)); cutpart.AddContourPoint(new ContourPoint(new Point(p1.X, maxY, p1.Z + 40), null)); cutpart.Insert(); bPart.Father = fatherpart; bPart.SetOperativePart(cutpart); if (!bPart.Insert()) { SetInfoText("Leikkauksen (2) tekeminen epäonnistui!"); } cutpart.Delete(); break; case 2: p1 = new Point(minX + 300, 0, maxZ + 135); p2 = new Point(minX + 300, maxY, maxZ + 135); break; case 3: p1 = new Point(maxX - 300, 0, maxZ + 135); p2 = new Point(maxX - 300, maxY, maxZ + 135); break; } compInput.AddOneInputPosition(p1); compInput.AddOneInputPosition(p2); components[i].SetComponentInput(compInput); if (!components[i].Insert()) { SetInfoText("Komponentin laittaminen epäonnistui!"); } } foreach (TSM.Component c in components) { assembly.Add(c); assembly.Modify(); } } catch (Exception ex) { ExceptionOccured(ex.Message, ex.StackTrace); SetInfoText("Komponentin asettamisessa tapahtui virhe!"); } finally { lock (wHandler) { wHandler.SetCurrentTransformationPlane(originalTransformationplane); } } }
public void CK09_PolygonCut() { // Current Workplane. Reminder how the user had the model before you did stuff. TransformationPlane CurrentPlane = Model.GetWorkPlaneHandler().GetCurrentTransformationPlane(); Picker Picker = new Picker(); Beam PickedPart = null; try { PickedPart = (Beam)Picker.PickObject(Picker.PickObjectEnum.PICK_ONE_PART); } catch { PickedPart = null; } if (PickedPart != null) { // Change the workplane to the coordinate system of the Beam var psk = new TransformationPlane(PickedPart.GetCoordinateSystem()); Model.GetWorkPlaneHandler().SetCurrentTransformationPlane(psk); ContourPlate ContourPlateObject = new ContourPlate(); ContourPlateObject.AssemblyNumber.Prefix = "XX"; ContourPlateObject.AssemblyNumber.StartNumber = 1; ContourPlateObject.Name = "CUT"; ContourPlateObject.PartNumber.Prefix = "xx"; ContourPlateObject.Profile.ProfileString = "200"; ContourPlateObject.Material.MaterialString = "ANTIMATERIAL"; ContourPlateObject.Finish = ""; // This is the Important Part! ContourPlateObject.Class = BooleanPart.BooleanOperativeClassName; ContourPlateObject.Position.Depth = Position.DepthEnum.MIDDLE; // when doing a polygon cut make sure you don't do roght alone edge //..or sometimes you maight get a solid error and your part will disappeared ContourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(-10, -10, 0), null)); ContourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(100, -10, 0), null)); ContourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(100, 100, 0), null)); ContourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(-10, 100, 0), null)); if (!ContourPlateObject.Insert()) { Tekla.Structures.Model.Operations.Operation.DisplayPrompt("Plate wasn't created."); // SetWorkPlane back to what user had before Model.GetWorkPlaneHandler().SetCurrentTransformationPlane(CurrentPlane); } else { BooleanPart PolygonCut = new BooleanPart(); PolygonCut.Father = PickedPart; PolygonCut.OperativePart = ContourPlateObject; PolygonCut.Type = BooleanPart.BooleanTypeEnum.BOOLEAN_CUT; if (!PolygonCut.Insert()) { // SetWorkPlane back to what user had before Model.GetWorkPlaneHandler().SetCurrentTransformationPlane(CurrentPlane); } else { // We don't need the phisical part in the model anymore. ContourPlateObject.Delete(); // SetWorkPlane back to what user had before Model.GetWorkPlaneHandler().SetCurrentTransformationPlane(CurrentPlane); // Show the fitting in the model but the user //..will never see the workplane change Model.CommitChanges(); } } } }
private void btnPolygonCut_Click(object sender, EventArgs e) { // Current Workplane. Remember how the user had model before you made changes TransformationPlane currentPlane = currentModel.GetWorkPlaneHandler().GetCurrentTransformationPlane(); TSMUI.Picker myPicker = new TSMUI.Picker(); Part pickedPart = null; try { pickedPart = myPicker.PickObject(Tekla.Structures.Model.UI.Picker.PickObjectEnum.PICK_ONE_PART) as Part; } catch { pickedPart = null; } if (pickedPart != null) { // Change the workplane to the coordinate system of the part currentModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(new TransformationPlane(pickedPart.GetCoordinateSystem())); // Apply polygon cut ContourPlate contourPlateObject = new ContourPlate(); contourPlateObject.AssemblyNumber.Prefix = "XX"; contourPlateObject.AssemblyNumber.StartNumber = 1; contourPlateObject.PartNumber.Prefix = "xx"; contourPlateObject.PartNumber.StartNumber = 1; contourPlateObject.Name = "CUT"; contourPlateObject.Profile.ProfileString = "200"; contourPlateObject.Material.MaterialString = "ANTIMATERIAL"; contourPlateObject.Finish = ""; // THIS IS THE IMPORTANT PART!!! contourPlateObject.Class = BooleanPart.BooleanOperativeClassName; contourPlateObject.Position.Depth = Position.DepthEnum.MIDDLE; // When doing a polygon cut make sure you don't do it right along edge // or sometimes you might et a solid error and your part will disappear. contourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(-10, -10, 0), null)); contourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(100, -10, 0), null)); contourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(100, 100, 0), null)); contourPlateObject.AddContourPoint(new ContourPoint(new T3D.Point(-10, 100, 0), null)); if (!contourPlateObject.Insert()) { Tekla.Structures.Model.Operations.Operation.DisplayPrompt("Plate was ot created"); // Set workplane to what user had before currentModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane); } else { // We don't need the physical part in the model anymore. contourPlateObject.Delete(); // Set workplane to what user had before currentModel.GetWorkPlaneHandler().SetCurrentTransformationPlane(currentPlane); // Show the fitting in the model, the user will never see the workplane change. currentModel.CommitChanges(); } } }