ElecManage.ElectrodeInfo GetElecInfo(Snap.NX.Body b) { ElecManage.ElectrodeInfo info = null; if (SpecialshapedElec) { var xkElec = ElecManage.Electrode.GetElectrode(b); if (xkElec != null) { info = xkElec.GetElectrodeInfo(); _elecNameLst.Add(info.Elec_Name); } } else { var xkElec = ElecManage.Electrode.GetElectrode(b); if (xkElec != null) { info = xkElec.GetElectrodeInfo(); } else { info = new ElecManage.ElectrodeInfo(b); } } return(info); }
public override void Apply() { var steel = selectSteel.SelectedObjects.FirstOrDefault() as Snap.NX.Body; switch (selectTemplate0.Value) { case 0: { for (int i = txtDrfLayer.Value; i <= txtDrfEndLayer.Value; i++) { var selectedObj = Snap.Globals.WorkPart.Bodies.Where(u => i == u.Layer && !string.IsNullOrEmpty(u.Name)).FirstOrDefault(); if (selectedObj != null) { CreateDrawingSheet(selectedObj, steel); } } } break; default: { Snap.NX.Body selectedObj = selectCuprum.SelectedObjects.FirstOrDefault() as Snap.NX.Body; CreateDrawingSheet(selectedObj, steel); } break; } }
public void CreateDrawingSheet(List <PositioningInfo> positionings, Snap.NX.Body steel) { var workPart = Snap.Globals.WorkPart; if (_ConfigData.Edition == 4 || _ConfigData.Edition == 2) { var electrode = positionings.First().Electrode; workPart.NXOpenPart.DrawingSheets.ToArray().Where(u => u.Name.ToUpper().Contains(electrode.ElecBody.Name.ToUpper())).ToList().ForEach(u => { u.Open(); var result = EdmDraw.Helper.ExportPDF(u, electrode.ElecBody.Name); var info = electrode.GetElectrodeInfo(); CommonInterface.FtpHelper.FtpUpload("EDM2D", new ElecManage.MouldInfo { MODEL_NUMBER = string.IsNullOrEmpty(info.EACT_MODELNO) ? "UNKOWN_MODELNO" : info.EACT_MODELNO }, result, info.Elec_Name, _ConfigData); }); } else { var mark = Snap.Globals.SetUndoMark(Snap.Globals.MarkVisibility.Invisible, "CreateDrawingSheet"); try { CreateDrawingSheet(positionings, steel, true); } catch (Exception ex) { throw ex; } finally { Snap.Globals.UndoToMark(mark, "CreateDrawingSheet"); } } }
void CreateDrawingSheet(Snap.NX.Body selectedObj, Snap.NX.Body steel) { //获取电极信息 var positionings = new List <ElecManage.PositioningInfo>(); Snap.Globals.WorkPart.Bodies.Where(u => selectedObj.Layer == u.Layer && selectedObj.Name == u.Name).ToList().ForEach(u => { var info = ElecManage.Electrode.GetElectrode(u); if (info != null) { var positioning = new ElecManage.PositioningInfo(); positioning.Electrode = info; var pos = info.GetElecBasePos(); pos = Snap.NX.CoordinateSystem.MapAcsToWcs(pos); positioning.X = Math.Round(pos.X, 4); positioning.Y = Math.Round(pos.Y, 4); positioning.Z = Math.Round(pos.Z, 4); positioning.QuadrantType = info.GetQuadrantType(); positionings.Add(positioning); } }); if (positionings.Count <= 0) { throw new Exception("无法识别该电极!"); } positionings = positionings.OrderBy(u => u.C).ToList(); foreach (var item in positionings) { item.N = string.Format("C{0}", positionings.IndexOf(item) + 1); } CreateDrawingSheet(positionings, steel, false); }
/// <summary> /// 创建基本视图 /// </summary> /// <returns></returns> public static BaseView CreateBaseView(DrawingSheet ds, Snap.NX.Body body) { //UFUN创建基本视图函数 var workPart = NXOpen.Session.GetSession().Parts.Work; var theUFSession = NXOpen.UF.UFSession.GetUFSession(); var modelView = workPart.ModelingViews.FindObject("FRONT"); var draw_view_tag = CreateView(ds, body, modelView.Tag, new Snap.Position(ds.Length / 2, ds.Height / 2)); Tag top = Tag.Null; var topFace = body.Faces.FirstOrDefault(u => u.GetAttributeInfo().Where(m => m.Title == "ATTR_NAME_MARK" && u.GetStringAttribute("ATTR_NAME_MARK") == "BASE_BOT").Count() > 0); top = topFace.NXOpenTag; var box = body.Box; var min = new Snap.Position((box.MinX + box.MaxX) / 2, (box.MinY + box.MaxY) / 2, box.MinZ); var plane = new Snap.Geom.Surface.Plane(min, topFace.GetFaceDirection()); var bottomFace = body.Faces.OrderBy(u => Snap.Compute.Distance(min, u) ).FirstOrDefault(); Tag bottom = Tag.Null; //theUFSession.Obj.CycleByName("BOTTOMEDGE", ref bottom); bottom = bottomFace.NXOpenTag; CreateVerticalDim(draw_view_tag, top, bottom, new Snap.Position((ds.Length / 2) + GetBorderSize(draw_view_tag).X / 2, ds.Height / 2, 0)); return(null); }
public override void Apply() { if (string.IsNullOrEmpty(sMODELNUMBER.Value)) { ShowMessage("模具编号不能为空!"); return; } if (string.IsNullOrEmpty(sMRNUMBER.Value)) { ShowMessage("钢件编号不能为空!"); return; } if (eMATERAL.SelectedIndex < 0) { ShowMessage("钢件材质不能为空!"); return; } Snap.NX.Body steel = GetSteel(); steel.SetStringAttribute("MODEL_NUMBER", sMODELNUMBER.Value); steel.SetStringAttribute("MR_NUMBER", sMRNUMBER.Value); steel.SetStringAttribute("MR_MATERAL", _items[eMATERAL.SelectedIndex]); MouldInfo = EactBom.EactBomBusiness.Instance.GetMouldInfo(steel); if (enum0.SelectedItem == "指定") { MouldInfo.Origin = coord_system0.SpecifiedCsys.Origin; MouldInfo.Orientation = coord_system0.SpecifiedCsys.Orientation; } else if (enum0.SelectedItem == "绝对") { MouldInfo.Origin = new Snap.Position(); MouldInfo.Orientation = Snap.Orientation.Identity; } else if (enum0.SelectedItem == "工作") { MouldInfo.Origin = Snap.Globals.Wcs.Origin; MouldInfo.Orientation = Snap.Globals.Wcs.Orientation; } else //TODO 默认 { var box = steel.Box; MouldInfo.Orientation = Snap.Orientation.Identity; MouldInfo.Origin = new Snap.Position((box.MinX + box.MaxX) / 2, (box.MinY + box.MaxY) / 2, box.MaxZ); } //Snap.Globals.Wcs.Origin = MouldInfo.Origin; NXOpen.UF.UFSession.GetUFSession().Csys.SetOrigin(Snap.Globals.Wcs.NXOpenTag, MouldInfo.Origin.Array); Snap.Globals.WcsOrientation = MouldInfo.Orientation; Result = System.Windows.Forms.DialogResult.OK; }
public override void Apply() { Snap.NX.Body selectedObj = selectCuprum.GetSelectedObjects().FirstOrDefault() as NXOpen.Body; var steel = selectSteel.GetSelectedObjects().FirstOrDefault() as NXOpen.Body; var workPart = Snap.Globals.WorkPart; var templateName = _paramFileList.Where(u => u.Contains(selectTemplate0.ValueAsString)).FirstOrDefault(); InitModelingView(); //EdmDraw.DrawBusiness.InitPreferences(3, 2, .8, .1); EdmDraw.DrawBusiness.InitPreferences("blockfont", 2, .8, .1); CreateDrawingSheet(selectedObj, steel, templateName); }
/// <summary> /// 寻找隐藏图层 /// </summary> int FindLayer(Snap.NX.Body body) { int r = 1; for (int i = 1; i <= 256; i++) { if (i != body.Layer && i != Snap.Globals.WorkLayer) { r = i; break; } } return(r); }
public override void Update(NXOpen.BlockStyler.UIBlock block) { if (block.Name == selection0.Name) { Snap.NX.Body body = selection0.SelectedObjects.FirstOrDefault() as Snap.NX.Body; if (!SnapEx.Helper.IsEactElecBody(body) || body.GetAttributeInfo().Where(u => u.Title == EACT_POSITIONING_DATE).Count() > 0) { selection0.SelectedObjects = new List <Snap.NX.NXObject>().ToArray(); } } RefreshUI(); Perform(true); }
/// <summary> /// 设置镜像属性 /// </summary> void SetGeomcopyAttr(Snap.NX.Body body, NXOpen.Plane plane, bool isJC) { if (isJC) { return; } var electrode = ElecManage.Electrode.GetElectrode(body); if (electrode == null) { return; } electrode.InitAllFace(); //var transRef = Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal)); Snap.NX.Face preXFace = null, preYFace = null; body.Faces.ToList().ForEach(u => { if (u.GetAttributeInfo().Where(m => m.Title == "EACT_ELECT_X_FACE").Count() > 0) { u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_X_FACE"); u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_Y_FACE"); preXFace = u; } else if (u.GetAttributeInfo().Where(m => m.Title == "EACT_ELECT_Y_FACE").Count() > 0) { u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_X_FACE"); u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_Y_FACE"); preYFace = u; } }); //if (preXFace == null || preYFace == null) return; var topDir = -electrode.BaseFace.GetFaceDirection(); var orientation = ElecManage.Electrode.GetSidelongOrientation(new Snap.Orientation(topDir)); var xFace = electrode.BaseSideFaces.FirstOrDefault(u => SnapEx.Helper.Equals(orientation.AxisX, u.GetFaceDirection())); var yFace = electrode.BaseSideFaces.FirstOrDefault(u => SnapEx.Helper.Equals(orientation.AxisY, u.GetFaceDirection())); if (xFace != null && yFace != null) { xFace.SetStringAttribute("EACT_ELECT_X_FACE", "1"); yFace.SetStringAttribute("EACT_ELECT_Y_FACE", "1"); } body.SetStringAttribute("EACT_EDM_OPERATE_DIR", ElecManage.Electrode.GetCNC_DIRECTION(topDir)); body.SetStringAttribute("EACT_ELEC_QUADRANT_OF_CHAMFER", ((int)electrode.GetQuadrantType(orientation) + 1).ToString()); }
/// <summary> /// 设置钢件电极隐藏(优化出图速度) /// </summary> void SetIsHidden(List <PositioningInfo> positionings, Snap.NX.Body steel, bool IsHidden = true) { if (IsHidden) { foreach (var item in positionings) { if (item.Electrode.ElecBody.NXOpenTag == steel.NXOpenTag) { IsHidden = false; break; } } } steel.IsHidden = IsHidden; //positionings.ForEach(u => { // u.Electrode.ElecBody.IsHidden = IsHidden; //}); }
public static NXOpen.Tag CreateView(DrawingSheet ds, Snap.NX.Body body, NXOpen.Tag modelViewTag, Snap.Position point) { //UFUN创建基本视图函数 var workPart = NXOpen.Session.GetSession().Parts.Work; Snap.NX.Part snapWorkPart = workPart; var theUFSession = NXOpen.UF.UFSession.GetUFSession(); NXOpen.UF.UFDraw.ViewInfo view_info; theUFSession.Draw.InitializeViewInfo(out view_info); double[] dwg_point = { point.X, point.Y }; Tag draw_view_tag; theUFSession.Draw.ImportView(ds.Tag, modelViewTag, dwg_point, ref view_info, out draw_view_tag); string viewName; theUFSession.Obj.AskName(draw_view_tag, out viewName); workPart.Bodies.ToArray().ToList().ForEach(u => { if (u.Tag != body.NXOpenTag) { SnapEx.Ex.UC6400(viewName, u.Tag); } }); workPart.Points.ToArray().ToList().ForEach(u => { if (u.Tag != body.NXOpenTag) { SnapEx.Ex.UC6400(viewName, u.Tag); } }); SnapEx.Ex.UC6400(viewName, workPart.WCS.Tag); //更新视图 theUFSession.Draw.UpdateOneView(ds.Tag, draw_view_tag); theUFSession.Draw.MoveView(draw_view_tag, dwg_point); //更新视图 theUFSession.Draw.UpdateOneView(ds.Tag, draw_view_tag); return(draw_view_tag); }
public void CreateEdmDraw(Snap.NX.Body elecBody, Snap.NX.Body steel) { var workPart = Snap.Globals.WorkPart; var members = new List <string>(); var path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template"); if (System.IO.Directory.Exists(path)) { _paramFileList = System.IO.Directory.GetFiles(path).ToList(); _paramFileList.ForEach(u => { members.Add(System.IO.Path.GetFileNameWithoutExtension(u)); }); } InitModelingView(); EdmDraw.DrawBusiness.InitPreferences("blockfont", 2, .8, .1); CreateDrawingSheet(elecBody, steel, _paramFileList.First()); }
/// <summary> /// 设置基准角相关属性 /// </summary> void SetJZJAttr(Snap.NX.Face _horizontalDatumFace, Snap.NX.Body body) { if (!toggle0.Value) { body.Faces.ToList().ForEach(u => { if (u.GetAttributeInfo().Where(m => m.Title == "EACT_ELECT_X_FACE").Count() > 0) { u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_X_FACE"); u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_Y_FACE"); u.SetStringAttribute("EACT_ELECT_Y_FACE", "1"); } else if (u.GetAttributeInfo().Where(m => m.Title == "EACT_ELECT_Y_FACE").Count() > 0) { u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_X_FACE"); u.DeleteAttributes(Snap.NX.NXObject.AttributeType.String, "EACT_ELECT_Y_FACE"); u.SetStringAttribute("EACT_ELECT_X_FACE", "1"); } }); } }
void SetEactElec(Snap.NX.Body body, Snap.NX.Face baseFace = null, Snap.NX.Face topFace = null, Snap.NX.Point basePoint = null) { selectBaseFace.SelectedObjects = new Snap.NX.NXObject[] { }; selectTopFace.SelectedObjects = new Snap.NX.NXObject[] { }; selectBaseFacePointEx.Position = new Snap.Position(); var pos = new Snap.Position(); ElecManage.Electrode.GetEactElectrode(body, ref topFace, ref baseFace, ref basePoint, ref pos); if (baseFace != null) { selectBaseFace.SelectedObjects = new Snap.NX.NXObject[] { baseFace }; } if (topFace != null) { selectTopFace.SelectedObjects = new Snap.NX.NXObject[] { topFace }; } selectBaseFacePointEx.Position = pos; if (baseFace != null && topFace != null) { //更新尺寸 var info = GetElecInfo(body); if (info != null) { strElecSize.Value = info.ElecSize; strElecCuttingSize.Value = info.ElecCuttingSize(_configData, EactConfig.MatchJiaju.GetMatchJiajuValue(_configData, cbbChuckType.SelectedIndex)); } else if (groupSElec.Show) //异形电极 { var tempInfo = new ElecManage.ElectrodeInfo(body); var tempOri = new Snap.Orientation(-baseFace.GetFaceDirection()); strElecSize.Value = tempInfo.GetElecSize(tempOri); strElecCuttingSize.Value = tempInfo.ElecCuttingSize(_configData, EactConfig.MatchJiaju.GetMatchJiajuValue(_configData, cbbChuckType.SelectedIndex), tempOri); } else { strElecSize.Value = string.Empty; strElecCuttingSize.Value = string.Empty; } } }
public override void Apply() { var faces = new List <NXOpen.Face>(); face_select0.GetSelectedObjects().ToList().ForEach(u => { var face = u as NXOpen.Face; if (face != null) { faces.Add(face); } }); var ds = new List <double>(); if (enum0.ValueAsString == OffsetType.ALL) { for (int i = 0; i < 6; i++) { ds.Add(expressionALL.Value); } } else { ds.Add(expressionXPositive.Value); ds.Add(expressionXNegative.Value); ds.Add(expressionYPositive.Value); ds.Add(expressionYNegative.Value); ds.Add(expressionZPositive.Value); ds.Add(expressionZNegative.Value); } var nxObject = SnapEx.Create.Box(faces, ds[0], ds[1], ds[2], ds[3], ds[4], ds[5]); Snap.NX.Body body = nxObject.Bodies.FirstOrDefault(); Snap.NX.Face snapFace = faces.FirstOrDefault(); var trimBody = Snap.Create.TrimBody(body, snapFace, true); trimBody.Orphan(); }
void UpdateEactElec(Snap.NX.Body body) { Snap.NX.Face topFace = null; Snap.NX.Face baseFace = null; Snap.NX.Point basePoint = null; Snap.Position pos = new Snap.Position(); ElecManage.Electrode.GetEactElectrode(body, ref topFace, ref baseFace, ref basePoint, ref pos); topFace = selectTopFace.SelectedObjects.FirstOrDefault() as Snap.NX.Face; baseFace = selectBaseFace.SelectedObjects.FirstOrDefault() as Snap.NX.Face; pos = selectBaseFacePointEx.Position; if (basePoint == null) { basePoint = Snap.Create.Point(pos); basePoint.Layer = body.Layer; basePoint.Color = System.Drawing.Color.Green; } else { basePoint.Position = pos; } ElecManage.Electrode.SetEactElectrode(body, ref topFace, ref baseFace, ref basePoint); }
Snap.NX.Body ImportPart(string fileName) { Snap.NX.Body result = null; NXOpen.UF.ImportPartModes modes = new NXOpen.UF.ImportPartModes(); //坐标系 double[] dest_csys = new double[6]; //基准点 double[] dest_point = new double[3]; dest_csys[0] = 1; //坐标系X轴的矢量 dest_csys[1] = 0; dest_csys[2] = 0; dest_csys[3] = 0; //坐标系Y轴的矢量 dest_csys[4] = 1; dest_csys[5] = 0; dest_point[0] = 0.0; //基准点【导入到点坐标】 dest_point[1] = 0.0; dest_point[2] = 0.0; //导入对象比例缩放 double scale = 1.0; NXOpen.Tag group; NXOpen.UF.UFSession.GetUFSession().Part.Import(fileName, ref modes, dest_csys, dest_point, scale, out group); foreach (var m in Snap.Globals.WorkPart.Bodies) { var axisFace = m.Faces.FirstOrDefault(u => u.Name == SnapEx.ConstString.CMM_INSPECTION_AXISPOINT); if (axisFace != null) { result = m; break; } } return(result); }
void GeomcopyJiaju(bool isPreview, NXOpen.Plane plane) { if (!isPreview) { if (toggleJiaju.Value) { var x = expressionX.Value; var y = expressionY.Value; var z = expressionZ.Value; var trans = Snap.Geom.Transform.CreateTranslation(new Snap.Vector(x, y, z)); selectionJiaju.SelectedObjects.ToList().ForEach(u => { Snap.NX.Body snapU = Snap.NX.Body.Wrap(u.NXOpenTag); if (snapU != null) { var jiaju = snapU.Copy(); var firstPos = new Snap.Position((jiaju.Box.MinX + jiaju.Box.MaxX) / 2, (jiaju.Box.MinY + jiaju.Box.MaxY) / 2, (jiaju.Box.MinZ + jiaju.Box.MaxZ) / 2); var twoPos = firstPos.Copy(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); jiaju.Move(Snap.Geom.Transform.CreateTranslation(twoPos - firstPos)); //if (toggle0.Value) //继承 //{ // var firstPos = new Snap.Position((jiaju.Box.MinX + jiaju.Box.MaxX) / 2, (jiaju.Box.MinY + jiaju.Box.MaxY) / 2, (jiaju.Box.MinZ + jiaju.Box.MaxZ) / 2); // var twoPos = firstPos.Copy(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); // jiaju.Move(Snap.Geom.Transform.CreateTranslation(twoPos - firstPos)); //} //else //{ // jiaju.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); //} jiaju.SetStringAttribute("EACT_MIRROR_ELECT", "Y"); jiaju.Move(trans); snapU.Delete(); } }); } } }
void Apply() { Snap.NX.Body selectedObj = bodySelect0.GetSelectedObjects().FirstOrDefault() as NXOpen.Body; var workPart = Snap.Globals.WorkPart; selectedObj.SetStringAttribute("2323", "3333"); var templateName = _paramFileList.Where(u => u.Contains(selectTemplate0.ValueAsString)).FirstOrDefault(); //新建图纸页 var ds = SnapEx.Create.DrawingSheet("test_dds", templateName); //var baseView = SnapEx.Create.BaseView(Snap.Globals.WorkPart, new NXOpen.Point2d(expressionX.Value, expressionY.Value)); CreateBaseView(ds, selectedObj); //解决位置固定问题 var topView1 = CreateView(ds, Snap.Globals.WorkPart.Bodies.Where(u => u.NXOpenTag != selectedObj.NXOpenTag).FirstOrDefault(), workPart.NXOpenPart.ModelingViews.FindObject("TOP").Tag, new Snap.Position(40, 60)); var size = GetBorderSize(topView1); var theUFSession = NXOpen.UF.UFSession.GetUFSession(); theUFSession.Draw.SetViewScale(topView1, 40 / size.X); theUFSession.Draw.UpdateOneView(ds.Tag, topView1); Test(ds); }
NXOpen.DisplayableObject GeomcopyElec(bool isPreview, NXOpen.Body body, NXOpen.Plane plane) { Snap.NX.Body SnapBody = body; var oldWorkPart = theSession.Parts.Work; var objs = new List <NXOpen.NXObject> { body }; Snap.NX.Body newBody = null; if (body.OwningComponent != null && body.Prototype != null) { //析出 SnapEx.Create.ExtractObject(objs, oldWorkPart.FullPath, false, false); newBody = oldWorkPart.Bodies.ToArray().FirstOrDefault(u => u.Name == body.Name); } else { newBody = SnapBody.Copy(); } if (newBody == null) { return(newBody); } var guid = Guid.NewGuid().ToString(); var tempElecOrigin = SnapEx.Helper.GetElecMidPosition(oldWorkPart, body); if (tempElecOrigin == null) { theUI.NXMessageBox.Show("提示", NXOpen.NXMessageBox.DialogType.Information, "该电极未发现基准点!"); return(null); } var transRef = Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal)); var topFace = SnapEx.Helper.GetTopFace(newBody); var bottomFace = SnapEx.Helper.GetBottomFace(newBody); var minU = topFace.BoxUV.MinU; var minV = topFace.BoxUV.MinV; var maxU = topFace.BoxUV.MaxU; var maxV = topFace.BoxUV.MaxV; var centerPosition = (Snap.Position)tempElecOrigin; var movePosition = centerPosition.Copy(transRef); bool isJC = toggle0.Value && topFace.NXOpenTag != bottomFace.NXOpenTag; if (isJC) //继承 { var markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "reflectionBody"); var normal = topFace.Normal(minU, minV); var point = topFace.Position(minU, minV); var datumPlane = Snap.Create.DatumPlane(point, normal); var splitBody = Snap.Create.SplitBody(newBody, datumPlane); var topBody = splitBody.Bodies.FirstOrDefault(b => SnapEx.Helper.GetTopFace(b) == null).Copy(); var reflectionBody = splitBody.Bodies.FirstOrDefault(b => SnapEx.Helper.GetTopFace(b) != null).Copy(); splitBody.Delete(); newBody.Delete(); topBody.Move(transRef); reflectionBody.Move(Snap.Geom.Transform.CreateTranslation(movePosition - centerPosition)); var result = Snap.Create.Unite(reflectionBody, topBody); result.Orphan(); datumPlane.Delete(); theSession.UpdateManager.DoUpdate(markId1); theSession.DeleteUndoMark(markId1, null); newBody = reflectionBody; } else { newBody.Move(transRef); } var x = expressionX.Value; var y = expressionY.Value; var z = expressionZ.Value; var trans = Snap.Geom.Transform.CreateTranslation(new Snap.Vector(x, y, z)); newBody.Move(trans); if (!isPreview) { newBody.SetStringAttribute("EACT_MIRROR_ELECT", "Y"); if (topFace != null) { //SetJZJAttr(topFace, newBody); SetGeomcopyAttr(newBody, plane, isJC); } var oldPoint = SnapEx.Helper.GetElecMidPointInPart(Snap.Globals.WorkPart, body); var newPoint = SnapEx.Helper.GetElecMidPoint(Snap.Globals.WorkPart, body); if (newPoint != null) { //newPoint.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid); newPoint.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); newPoint.Move(trans); } if (body.OwningComponent != null && body.Prototype != null) { } else { if (oldPoint != null) { oldPoint.Delete(); } SnapBody.Delete(); } } return(newBody); }
public override void Apply() { if (string.IsNullOrEmpty(sMODELNUMBER.Value)) { ShowMessage("模具编号不能为空!"); return; } if (string.IsNullOrEmpty(sMRNUMBER.Value)) { ShowMessage("钢件编号不能为空!"); return; } if (eMATERAL.SelectedIndex < 0) { ShowMessage("钢件材质不能为空!"); return; } Snap.NX.Body steel = GetSteel(); steel.SetStringAttribute("MODEL_NUMBER", sMODELNUMBER.Value.Trim().ToUpper()); steel.SetStringAttribute("MR_NUMBER", sMRNUMBER.Value.Trim().ToUpper()); steel.SetStringAttribute("MR_MATERAL", _items[eMATERAL.SelectedIndex]); MouldInfo = EactBom.EactBomBusiness.Instance.GetMouldInfo(steel); if (enum0.SelectedItem == "指定") { MouldInfo.Origin = coord_system0.SpecifiedCsys.Origin; MouldInfo.Orientation = coord_system0.SpecifiedCsys.Orientation; } else if (enum0.SelectedItem == "绝对") { MouldInfo.Origin = new Snap.Position(); MouldInfo.Orientation = Snap.Orientation.Identity; } else if (enum0.SelectedItem == "工作") { MouldInfo.Origin = Snap.Globals.Wcs.Origin; MouldInfo.Orientation = Snap.Globals.Wcs.Orientation; } else //TODO 默认 { var box = steel.Box; MouldInfo.Orientation = Snap.Orientation.Identity; MouldInfo.Origin = new Snap.Position((box.MinX + box.MaxX) / 2, (box.MinY + box.MaxY) / 2, box.MaxZ); } if (toggleSInsert.Value) { if (integerSInsertLayer.Show) { var bodies = Snap.Globals.WorkPart.Bodies.Where(u => u.Layer == integerSInsertLayer.Value).ToList(); bodies = bodies.Where(u => u.NXOpenTag != steel.NXOpenTag).ToList(); //foreach (var item in bodies.ToList()) //{ // var distance = Snap.Compute.Distance(steel, item); // bool isContact = distance <= SnapEx.Helper.Tolerance; // if (!isContact) // { // bodies.RemoveAll(u=>u.NXOpenTag==item.NXOpenTag); // } //} MouldInfo.SInsertBodies = bodies; } else { MouldInfo.SInsertBodies = Enumerable.Select(selectionSInsert.SelectedObjects, u => Snap.NX.Body.Wrap(u.NXOpenTag)).ToList(); } } if (groupElec.Show) { MouldInfo.ElecBodies = Enumerable.Select(selectElec.SelectedObjects, u => Snap.NX.Body.Wrap(u.NXOpenTag)).ToList(); } else if (groupElecLayer.Show) { MouldInfo.ElecBodies = Snap.Globals.WorkPart.Bodies.Where(u => u.Layer >= integerElecStartLayer.Value && u.Layer <= integerElecEndLayer.Value).ToList(); } NXOpen.UF.UFSession.GetUFSession().Csys.SetOrigin(Snap.Globals.Wcs.NXOpenTag, MouldInfo.Origin.Array); Snap.Globals.WcsOrientation = MouldInfo.Orientation; ElecManage.Entry.Instance.DefaultQuadrantType = (QuadrantType)enumSelectedXX.SelectedIndex; ElecManage.Entry.Instance.IsDistinguishSideElec = EactBom.EactBomBusiness.Instance.ConfigData.IsDistinguishSideElec; ElecManage.Entry.Edition = EactBom.EactBomBusiness.Instance.ConfigData.Edition; steel.SetIntegerAttribute(EactBom.EactBomBusiness.EACT_DEFAULTQUADRANTTYPE, enumSelectedXX.SelectedIndex); Result = System.Windows.Forms.DialogResult.OK; }
public void CreateDrawingSheet(List <PositioningInfo> positionings, Snap.NX.Body steel, bool isAutoMode) { var edmConfig = EdmDraw.UCEdmConfig.GetInstance(); var templateName = edmConfig.GetEdmTemplate(); if (string.IsNullOrEmpty(templateName)) { return; } ElecManage.Electrode electrode = positionings.FirstOrDefault().Electrode; var selectedObj = electrode.ElecBody; electrode.InitAllFace(); InitModelingView(edmConfig, electrode, isAutoMode); SetIsHidden(positionings, steel); EdmDraw.DrawBusiness.InitPreferences(edmConfig); var workPart = Snap.Globals.WorkPart; var dsName = selectedObj.Name; var list = new List <NXOpen.TaggedObject>(); list.Add(steel); list.Add(selectedObj); workPart.NXOpenPart.DrawingSheets.ToArray().Where(u => u.Name == dsName).ToList().ForEach(u => { Snap.NX.NXObject.Delete(u); }); //图纸显示 EdmDraw.DrawBusiness.SetShowLayers(new List <int> { 1 }, edmConfig.EdmDrfLayer); //新建图纸页 var ds = SnapEx.Create.DrawingSheet(selectedObj.Name, templateName); EdmDraw.DrawBusiness.SetDrawSheetLayer(ds, edmConfig.EdmDrfLayer); var draftViewLocations = edmConfig.DraftViewLocations ?? new List <EdmDraw.EdmConfig.DraftViewLocation>(); EdmDraw.EdmConfig.DraftViewLocation ViewTypeEACT_TOP = null; EdmDraw.EdmConfig.DraftViewLocation ViewTypeEACT_FRONT = null; foreach (var item in draftViewLocations) { var viewType = EdmDraw.DrawBusiness.GetEumnViewType(item.ViewType); switch (viewType) { case EdmDraw.ViewType.EACT_TOP: { ViewTypeEACT_TOP = item; } break; case EdmDraw.ViewType.EACT_FRONT: { ViewTypeEACT_FRONT = item; } break; case EdmDraw.ViewType.EACT_BOTTOM_FRONT: { CreateEACT_BOTTOM_FRONTView( ds, new List <TaggedObject> { selectedObj }, new Snap.Position(item.LocationX, item.LocationY), new Snap.Position(item.SizeX, item.SizeY), electrode, edmConfig ); } break; case EdmDraw.ViewType.EACT_BOTTOM: { CreateEACT_BOTTOMView( ds, new List <TaggedObject> { selectedObj }, new Snap.Position(item.LocationX, item.LocationY), new Snap.Position(item.SizeX, item.SizeY), electrode, edmConfig ); } break; case EdmDraw.ViewType.EACT_BOTTOM_ISOMETRIC: { CreateEACT_BOTTOM_ISOMETRICView( ds, new List <TaggedObject> { selectedObj }, new Snap.Position(item.LocationX, item.LocationY), new Snap.Position(item.SizeX, item.SizeY) , edmConfig ); } break; case EdmDraw.ViewType.EACT_ISOMETRIC: { CreateEACT_ISOMETRICView( ds, new List <TaggedObject> { steel }, new Snap.Position(item.LocationX, item.LocationY), new Snap.Position(item.SizeX, item.SizeY) , edmConfig ); } break; } } CreateNodeInfo(electrode, edmConfig); var ps = new List <List <PositioningInfo> >(); if (edmConfig.PageCount <= 0) { ps.Add(positionings); } else { var ceiling = Math.Ceiling((double)(positionings.Count * 1.0 / edmConfig.PageCount)); var tempV = positionings.Count % edmConfig.PageCount; for (int i = 0; i < ceiling; i++) { ps.Add(positionings.Skip(i * edmConfig.PageCount).Take( i == ceiling - 1 && tempV != 0 ? tempV : edmConfig.PageCount ).ToList()); } } foreach (var item in ps) { SetIsHidden(positionings, steel); var pdfName = ds.Name; if (ps.Count > 1) { pdfName += "_" + (ps.IndexOf(item) + 1); } var deleteObj = new List <NXOpen.Tag>(); if (ViewTypeEACT_TOP != null) { var topView = CreateEACT_TOPView( ds, steel, new Snap.Position(ViewTypeEACT_TOP.LocationX, ViewTypeEACT_TOP.LocationY), new Snap.Position(ViewTypeEACT_TOP.SizeX, ViewTypeEACT_TOP.SizeY), item, edmConfig ); deleteObj.Add(topView.Tag); } if (ViewTypeEACT_FRONT != null) { var itemE = item.First().Electrode; var frontView = CreateEACT_FRONTView( ds, new List <NXOpen.TaggedObject> { steel, itemE.ElecBody }, new Snap.Position(ViewTypeEACT_FRONT.LocationX, ViewTypeEACT_FRONT.LocationY), new Snap.Position(ViewTypeEACT_FRONT.SizeX, ViewTypeEACT_FRONT.SizeY), itemE, edmConfig ); deleteObj.Add(frontView.Tag); } deleteObj.AddRange(CreateTable(edmConfig, item)); SetIsHidden(positionings, steel, false); ds.GetDraftingViews().ToList().ForEach(u => { var ufSession = NXOpen.UF.UFSession.GetUFSession(); ufSession.Draw.UpdateOneView(ds.Tag, u.Tag); }); var result = EdmDraw.Helper.ExportPDF(ds, pdfName); var info = electrode.GetElectrodeInfo(); CommonInterface.FtpHelper.FtpUpload("EDM2D", new ElecManage.MouldInfo { MODEL_NUMBER = string.IsNullOrEmpty(info.EACT_MODELNO)? "UNKOWN_MODELNO" : info.EACT_MODELNO }, result, info.Elec_Name, _ConfigData); if (ps.Count > 1) { deleteObj.ForEach(u => { Snap.NX.NXObject.Wrap(u).Delete(); }); } } //if (isAutoMode) //{ // Snap.NX.NXObject.Wrap(ds.Tag).Delete(); //} }
NXOpen.DisplayableObject GeomcopyElec(bool isPreview, NXOpen.Body body, NXOpen.Plane plane, int order) { Snap.NX.Body SnapBody = body; var oldWorkPart = theSession.Parts.Work; var objs = new List <NXOpen.NXObject> { body }; Snap.NX.Body newBody = null; if (body.OwningComponent != null && body.Prototype != null) { //析出 SnapEx.Create.ExtractObject(objs, oldWorkPart.FullPath, false, false); newBody = oldWorkPart.Bodies.ToArray().FirstOrDefault(u => u.Name == body.Name); } else { newBody = SnapBody.Copy(); } if (newBody == null) { return(newBody); } var tempElecOrigin = SnapEx.Helper.GetElecMidPosition(oldWorkPart, body); if (tempElecOrigin == null) { theUI.NXMessageBox.Show("提示", NXOpen.NXMessageBox.DialogType.Information, "该电极未发现基准点!"); return(null); } var guid = Guid.NewGuid().ToString(); //TODO 修改名称 修改属性 newBody.Name = GetElecName(order - 1); newBody.SetStringAttribute("EACT_ELEC_NAME", newBody.Name); newBody.SetStringAttribute("EACT_ELECT_GROUP", guid); newBody.Layer = order; Snap.Globals.LayerStates[order] = isPreview ? Snap.Globals.LayerState.Visible : Snap.Globals.LayerState.Selectable; var transRef = Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal)); var topFace = SnapEx.Helper.GetTopFace(newBody); var bottomFace = SnapEx.Helper.GetBottomFace(newBody); var minU = topFace.BoxUV.MinU; var minV = topFace.BoxUV.MinV; var maxU = topFace.BoxUV.MaxU; var maxV = topFace.BoxUV.MaxV; var centerPosition = (Snap.Position)tempElecOrigin; var movePosition = centerPosition.Copy(transRef); bool isJC = toggle0.Value && topFace.NXOpenTag != bottomFace.NXOpenTag; if (isJC) //继承 { var markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "reflectionBody"); var normal = topFace.Normal(minU, minV); var point = topFace.Position(minU, minV); var datumPlane = Snap.Create.DatumPlane(point, normal); var splitBody = Snap.Create.SplitBody(newBody, datumPlane); var topBody = splitBody.Bodies.FirstOrDefault(b => SnapEx.Helper.GetTopFace(b) == null).Copy(); var reflectionBody = splitBody.Bodies.FirstOrDefault(b => SnapEx.Helper.GetTopFace(b) != null).Copy(); splitBody.Delete(); newBody.Delete(); topBody.Move(transRef); reflectionBody.Move(Snap.Geom.Transform.CreateTranslation(movePosition - centerPosition)); var result = Snap.Create.Unite(reflectionBody, topBody); result.Orphan(); datumPlane.Delete(); theSession.UpdateManager.DoUpdate(markId1); theSession.DeleteUndoMark(markId1, null); newBody = reflectionBody; } else { newBody.Move(transRef); } var x = expressionX.Value; var y = expressionY.Value; var z = expressionZ.Value; var trans = Snap.Geom.Transform.CreateTranslation(new Snap.Vector(x, y, z)); newBody.Move(trans); if (!isPreview) { newBody.SetStringAttribute("EACT_MIRROR_ELECT", "Y"); topFace = SnapEx.Helper.GetTopFace(newBody); if (topFace != null) { SetGeomcopyAttr(newBody, plane, isJC); } var newPoint = SnapEx.Helper.GetElecMidPoint(Snap.Globals.WorkPart, body); if (newPoint != null) { newPoint.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid); newPoint.Layer = order; newPoint.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); newPoint.Move(trans); } if (toggleJiaju.Value && selectionJiaju.Show) { var tempJiaju = selectionJiaju.SelectedObjects.FirstOrDefault(); Snap.NX.Body jiaju = tempJiaju == null ? null : Snap.NX.Body.Wrap(tempJiaju.NXOpenTag); if (jiaju != null) { jiaju = jiaju.Copy(); jiaju.Layer = order; jiaju.Move(Snap.Geom.Transform.CreateTranslation(movePosition - centerPosition)); //if (toggle0.Value) //继承 //{ // var firstPos = new Snap.Position((jiaju.Box.MinX + jiaju.Box.MaxX) / 2, (jiaju.Box.MinY + jiaju.Box.MaxY) / 2, (jiaju.Box.MinZ + jiaju.Box.MaxZ) / 2); // var twoPos = firstPos.Copy(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); // jiaju.Move(Snap.Geom.Transform.CreateTranslation(twoPos - firstPos)); //} //else //{ // jiaju.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); //} jiaju.SetStringAttribute("EACT_MIRROR_ELECT", "Y"); jiaju.Move(trans); } } } return(newBody); }
NXOpen.DisplayableObject GeomcopyElec(bool isPreview, NXOpen.Body body, NXOpen.Plane plane, int order) { Snap.NX.Body SnapBody = body; var oldWorkPart = theSession.Parts.Work; var objs = new List <NXOpen.NXObject> { body }; Snap.NX.Body newBody = null; if (body.OwningComponent != null && body.Prototype != null) { //析出 SnapEx.Create.ExtractObject(objs, oldWorkPart.FullPath, false, false); newBody = oldWorkPart.Bodies.ToArray().FirstOrDefault(u => u.Name == body.Name); } else { newBody = Snap.NX.Body.Wrap(oldWorkPart.Bodies.ToArray().FirstOrDefault(u => u.Name == body.Name).Tag).Copy(); } if (newBody == null) { return(newBody); } var guid = Guid.NewGuid().ToString(); //TODO 修改名称 修改属性 newBody.Name = GetElecName(order - 1); newBody.SetStringAttribute("EACT_ELEC_NAME", newBody.Name); newBody.SetStringAttribute("EACT_ELECT_GROUP", guid); newBody.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); newBody.Layer = order; Snap.Globals.LayerStates[order] = isPreview ? Snap.Globals.LayerState.Visible : Snap.Globals.LayerState.Selectable; if (toggle0.Value) //继承 { var markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "reflectionBody"); var topFace = SnapEx.Helper.GetTopFace(newBody); var minU = topFace.BoxUV.MinU; var minV = topFace.BoxUV.MinV; var maxU = topFace.BoxUV.MaxU; var maxV = topFace.BoxUV.MaxV; var centerPosition = topFace.Position((minU + maxU) / 2, (minV + maxV) / 2); var normal = topFace.Normal(minU, minV); var point = topFace.Position(minU, minV); var datumPlane = Snap.Create.DatumPlane(point, normal); var splitBody = Snap.Create.SplitBody(newBody, datumPlane); var topBody = splitBody.Bodies.FirstOrDefault(b => SnapEx.Helper.GetTopFace(b) == null); var reflectionBody = splitBody.Bodies.FirstOrDefault(b => SnapEx.Helper.GetTopFace(b) != null); var newDatumPlane = Snap.Create.DatumPlane(centerPosition, new Snap.Orientation(normal).AxisY); reflectionBody.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(centerPosition, newDatumPlane.Normal))); var result = Snap.Create.Unite(reflectionBody, topBody); result.Orphan(); datumPlane.Delete(); newDatumPlane.Delete(); theSession.UpdateManager.DoUpdate(markId1); theSession.DeleteUndoMark(markId1, null); newBody = reflectionBody; } var x = expressionX.Value; var y = expressionY.Value; var z = expressionZ.Value; var trans = Snap.Geom.Transform.CreateTranslation(new Snap.Vector(x, y, z)); newBody.Move(trans); if (!isPreview) { newBody.SetStringAttribute("EACT_MIRROR_ELECT", "Y"); var topFace = SnapEx.Helper.GetTopFace(newBody); if (topFace != null) { SetJZJAttr(topFace, newBody); } var newPoint = SnapEx.Helper.GetElecMidPoint(Snap.Globals.WorkPart, body); if (newPoint != null) { newPoint.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid); newPoint.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); newPoint.Move(trans); } if (toggleJiaju.Value && selectionJiaju.Show) { Snap.NX.Body jiaju = selectionJiaju.GetSelectedObjects().FirstOrDefault() as NXOpen.Body; if (jiaju != null) { jiaju = jiaju.Copy(); jiaju.Layer = order; jiaju.Move(Snap.Geom.Transform.CreateReflection(new Snap.Geom.Surface.Plane(plane.Origin, plane.Normal))); jiaju.SetStringAttribute("EACT_MIRROR_ELECT", "Y"); jiaju.Move(trans); } } } return(newBody); }
void Perform(bool isHighlighted = false) { var workPart = theSession.Parts.Work; var body = selection0.SelectedObjects.FirstOrDefault() as Snap.NX.Body; var jiajuBody = selectionJiaju.SelectedObjects.FirstOrDefault() as Snap.NX.Body; tempObjs.ForEach(u => { Snap.NX.NXObject snapU = u; snapU.Delete(); }); tempObjs.Clear(); if (body != null) { Snap.NX.Body snapBody = body; //电极原点 var tempElecOrigin = SnapEx.Helper.GetElecMidPosition(workPart, body); if (tempElecOrigin == null) { theUI.NXMessageBox.Show("提示", NXOpen.NXMessageBox.DialogType.Information, "该电极未发现基准点!"); return; } var elecOrgin = (Snap.Position)tempElecOrigin; if (isHighlighted) { SnapEx.Create.DisplayModification(tempObjs); } bool isPatter = false; if (enum01.SelectedItem == "平移") { isPatter = toggleMovePatter.Value; } else { isPatter = toggleRotationPatter.Value; } int sum = 0; if (isPatter) { sum = (int)(expressionPatterSum.Value < 0?0:expressionPatterSum.Value); } double distance = expressionPatterDistance.Value; var vector = Snap.Vector.Unit(vectorPatter.Direction); if (body.NXOpenBody.OwningComponent != null && snapBody.Prototype != null) { var snapComponent = snapBody.OwningComponent;; NXOpen.Assemblies.Component component = snapComponent; var transForm = GetTransform(elecOrgin); for (int i = 0; i < sum + 1; i++) { Snap.NX.Component newComponent = workPart.ComponentAssembly.CopyComponents(new List <NXOpen.Assemblies.Component> { component }.ToArray()).First(); newComponent.Prototype.Bodies.First().SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now); tempObjs.Add(newComponent); //平移旋转 var trans = transForm.Matrix; Matrix3x3 matrix = new Matrix3x3(); matrix.Xx = trans[0]; matrix.Xy = trans[4]; matrix.Xz = trans[8]; matrix.Yx = trans[1]; matrix.Yy = trans[5]; matrix.Yz = trans[9]; matrix.Zx = trans[2]; matrix.Zy = trans[6]; matrix.Zz = trans[10]; workPart.ComponentAssembly.MoveComponent(newComponent, new Vector3d(trans[3], trans[7], trans[11]), matrix); if (i != 0) { workPart.ComponentAssembly.MoveComponent(newComponent, (distance * i) * vector, new Snap.Orientation()); } } } else { NXOpen.Point point = null; if (!isHighlighted) { var tempPoint = SnapEx.Helper.GetElecMidPointInPart(Snap.Globals.WorkPart, snapBody); if (tempPoint != null) { point = tempPoint; } } for (int i = 0; i < sum + 1; i++) { var newBody = snapBody.Copy(); var guid = Guid.NewGuid().ToString(); newBody.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid); newBody.SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now); tempObjs.Add(newBody); var transForm = GetTransform(elecOrgin); if (i != 0) { transForm = Snap.Geom.Transform.Composition(transForm, Snap.Geom.Transform.CreateTranslation((distance * i) * vector)); } newBody.Move(transForm); if (point != null) { Snap.NX.Point newPoint = Snap.NX.Point.Wrap(point.Tag).Copy(); newPoint.SetStringAttribute(SnapEx.EactConstString.EACT_ELECT_GROUP, guid); newPoint.Move(transForm); } } } if (toggleJiaju.Value && jiajuBody != null) { for (int i = 0; i < sum + 1; i++) { Snap.NX.Body snapJiajuBody = jiajuBody; var newJiajuBody = snapJiajuBody.Copy(); var guid = Guid.NewGuid().ToString(); newJiajuBody.Layer = body.Layer; newJiajuBody.SetDateTimeAttribute(EACT_POSITIONING_DATE, DateTime.Now); tempObjs.Add(newJiajuBody); elecOrgin = new Snap.Position((snapBody.Box.MaxX + snapBody.Box.MinX) / 2, (snapBody.Box.MaxY + snapBody.Box.MinY) / 2, snapBody.Box.MinZ); var transForm = GetTransform(elecOrgin); if (i != 0) { transForm = Snap.Geom.Transform.Composition(transForm, Snap.Geom.Transform.CreateTranslation((distance * i) * vector)); } newJiajuBody.Move(transForm); } } if (isHighlighted) { SnapEx.Create.DisplayModification(tempObjs); } } }
void CreateDrawingSheet(Snap.NX.Body selectedObj, Snap.NX.Body steel, string templateName) { var workPart = Snap.Globals.WorkPart; var dsName = selectedObj.Name; var list = new List <NXOpen.TaggedObject>(); list.Add(steel); list.Add(selectedObj); workPart.NXOpenPart.DrawingSheets.ToArray().Where(u => u.Name == dsName).ToList().ForEach(u => { Snap.NX.NXObject.Delete(u); }); //新建图纸页 var ds = SnapEx.Create.DrawingSheet(selectedObj.Name, templateName); EdmDraw.DrawBusiness.SetDrawSheetLayer(ds, 254); //获取电极信息 var electrode = ElecManage.Electrode.GetElectrode(selectedObj); if (electrode == null) { throw new Exception("无法识别该电极!"); } electrode.InitAllFace(); var topFace = electrode.TopFace; var baseFace = electrode.BaseFace; //BASE_SIDE var baseSideFaces = electrode.BaseSideFaces; //ELECTRODE_FACE var electrodeFaces = electrode.ElecHeadFaces; var topView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_TOP).Tag, list, new Snap.Position(56, 72), new Snap.Position(90, 90)); var frontView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_FRONT).Tag, list, new Snap.Position(56, 155), new Snap.Position(90, 40)); var bottomFrontView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM_FRONT).Tag, new List <TaggedObject> { selectedObj }, new Snap.Position(154, 155), new Snap.Position(40, 40)); var bottomView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM).Tag, new List <TaggedObject> { selectedObj }, new Snap.Position(154, 100), new Snap.Position(60, 60)); var bottomIsometricView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM_ISOMETRIC).Tag, new List <TaggedObject> { selectedObj }, new Snap.Position(154, 50), new Snap.Position(60, 60)); var isometricView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_ISOMETRIC).Tag, new List <NXOpen.TaggedObject> { steel }, new Snap.Position(220, 58), new Snap.Position(60, 60)); var originPoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(Snap.Globals.Wcs.Origin)); }, frontView.Tag); var elecBasePoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(electrode.GetElecBasePos())); }, frontView.Tag); var bottomFrontViewBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomFrontView, selectedObj); var bottomFrontViewTopPoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomFrontViewBorderPoints[3])); }, bottomFrontView.Tag); var bottomFrontViewBottomPoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomFrontViewBorderPoints[2])); }, bottomFrontView.Tag); var bottomViewBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomView, selectedObj); var yPlusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewBorderPoints[1])); }, bottomFrontView.Tag); var yMinusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewBorderPoints[0])); }, bottomFrontView.Tag); var xPlusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewBorderPoints[0], bottomViewBorderPoints[1])); }, bottomFrontView.Tag); var xMinusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewBorderPoints[2], bottomViewBorderPoints[3])); }, bottomFrontView.Tag); var bottomViewElecHeadBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomView, electrodeFaces); var yPlusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewElecHeadBorderPoints[1])); }, bottomFrontView.Tag); var yMinusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewElecHeadBorderPoints[0])); }, bottomFrontView.Tag); var xPlusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewElecHeadBorderPoints[0], bottomViewElecHeadBorderPoints[1])); }, bottomFrontView.Tag); var xMinusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewElecHeadBorderPoints[2], bottomViewElecHeadBorderPoints[3])); }, bottomFrontView.Tag); //电极前视图 EdmDraw.DrawBusiness.CreateVerticalDim( bottomFrontView.Tag, bottomFrontViewTopPoint.NXOpenTag, bottomFrontViewBottomPoint.NXOpenTag, new Snap.Position(bottomFrontView.GetDrawingReferencePoint().X + (EdmDraw.DrawBusiness.GetBorderSize(bottomFrontView.Tag).X / 2), bottomFrontView.GetDrawingReferencePoint().Y)); EdmDraw.DrawBusiness.CreateVerticalDim(bottomFrontView.Tag, baseFace.NXOpenTag, bottomFrontViewBottomPoint.NXOpenTag, new Snap.Position(bottomFrontView.GetDrawingReferencePoint().X - (EdmDraw.DrawBusiness.GetBorderSize(bottomFrontView.Tag).X / 2), bottomFrontView.GetDrawingReferencePoint().Y)); //电极仰视图 EdmDraw.DrawBusiness.CreateVerticalDim(bottomView.Tag, yPlusSideFace.NXOpenTag, yMinusSideFace.NXOpenTag, new Snap.Position(bottomView.GetDrawingReferencePoint().X + (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).X / 2), bottomView.GetDrawingReferencePoint().Y, 0)); EdmDraw.DrawBusiness.CreatePerpendicularDim(bottomView.Tag, xPlusSideFace.NXOpenTag, xMinusSideFace.NXOpenTag, new Snap.Position(bottomView.GetDrawingReferencePoint().X, bottomView.GetDrawingReferencePoint().Y + (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).Y / 2), 0)); EdmDraw.DrawBusiness.CreateVerticalDim(bottomView.Tag, yPlusElectrodeEdge.NXOpenTag, yMinusElectrodeEdge.NXOpenTag, new Snap.Position(bottomView.GetDrawingReferencePoint().X - (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).X / 2), bottomView.GetDrawingReferencePoint().Y, 0)); EdmDraw.DrawBusiness.CreatePerpendicularDim(bottomView.Tag, xPlusElectrodeEdge.NXOpenTag, xMinusElectrodeEdge.NXOpenTag, new Snap.Position(bottomView.GetDrawingReferencePoint().X, bottomView.GetDrawingReferencePoint().Y - (EdmDraw.DrawBusiness.GetBorderSize(bottomView.Tag).Y / 2), 0)); var frontViewTopMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Right, frontView); var tempMap = new double[] { 0, 0 }; var ufSession = NXOpen.UF.UFSession.GetUFSession(); ufSession.View.MapModelToDrawing(frontView.Tag, elecBasePoint.Position.Array, tempMap); var basePointMTD = tempMap.ToArray(); ufSession.View.MapModelToDrawing(frontView.Tag, originPoint.Position.Array, tempMap); var originPointMTD = tempMap.ToArray(); var distance = Snap.Compute.Distance(new Snap.Position(tempMap.First(), tempMap.Last()), frontViewTopMargin); EdmDraw.DrawBusiness.CreatePerpendicularOrddimension( frontView.Tag, originPoint.NXOpenTag, frontViewTopMargin.NXOpenTag, originPoint.NXOpenTag ); //TODO 坐标尺寸位置问题 var configData = 8; Snap.Vector v = new Snap.Vector(distance, 0); Snap.Vector v1 = new Snap.Vector(distance, configData); var angle = Snap.Vector.Angle(v, v1); Snap.Position?origin = null; if (basePointMTD.Last() > originPointMTD.Last()) { var line = frontViewTopMargin as Snap.NX.Line; origin = new Snap.Position(line.StartPoint.X, originPointMTD.Last() + (configData * 2)); } var frontViewOrddimension = EdmDraw.DrawBusiness.CreatePerpendicularOrddimension( frontView.Tag, originPoint.NXOpenTag, frontViewTopMargin.NXOpenTag, elecBasePoint.NXOpenTag, angle, origin ); EdmDraw.DrawBusiness.SetToleranceType(frontViewOrddimension); var topViewRightMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Right, topView); var topViewTopMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Top, topView); var topViewRightElecBasePoint = EdmDraw.DrawBusiness.CreatePerpendicularOrddimension( topView.Tag, originPoint.NXOpenTag, topViewRightMargin.NXOpenTag, elecBasePoint.NXOpenTag ); EdmDraw.DrawBusiness.SetToleranceType(topViewRightElecBasePoint); EdmDraw.DrawBusiness.CreatePerpendicularOrddimension( topView.Tag, originPoint.NXOpenTag, topViewRightMargin.NXOpenTag, originPoint.NXOpenTag ); var topViewTopElecBasePoint = EdmDraw.DrawBusiness.CreateVerticalOrddimension( topView.Tag, originPoint.NXOpenTag, topViewTopMargin.NXOpenTag, elecBasePoint.NXOpenTag ); EdmDraw.DrawBusiness.SetToleranceType(topViewTopElecBasePoint); EdmDraw.DrawBusiness.CreateVerticalOrddimension( topView.Tag, originPoint.NXOpenTag, topViewTopMargin.NXOpenTag, originPoint.NXOpenTag ); EdmDraw.DrawBusiness.GetBorderPoint(topView, steel).ForEach(u => { var tempU = EdmDraw.DrawBusiness.CreateNxObject <Snap.NX.Point>(() => { return(Snap.Create.Point(u)); }, topView.Tag); EdmDraw.DrawBusiness.CreateVerticalOrddimension( topView.Tag, originPoint.NXOpenTag, topViewTopMargin.NXOpenTag, tempU.NXOpenTag ); EdmDraw.DrawBusiness.CreatePerpendicularOrddimension( topView.Tag, originPoint.NXOpenTag, topViewRightMargin.NXOpenTag, tempU.NXOpenTag ); }); var borderSize = topView.GetBorderSize(); var refPoint = topView.GetDrawingReferencePoint(); EdmDraw.DrawBusiness.CreateIdSymbol("C1", new Snap.Position(refPoint.X - (borderSize.X / 2), refPoint.Y), new Snap.Position(), topView.Tag, elecBasePoint.NXOpenTag); //注释 EdmDraw.DrawBusiness.CreateNode(selectedObj.Name, new Snap.Position(35, 19)); //表格 EdmDraw.DrawBusiness.CreateTabnot(new Snap.Position(216, ds.Height - 1.5), 2, 4, 15, 15); EdmDraw.DrawBusiness.CreatePentagon(new Snap.Position(223, ds.Height - 1.5 - 2), QuadrantType.Four); }
BaseView CreateEACT_TOPView(NXOpen.Drawings.DrawingSheet ds, Snap.NX.Body steel, Snap.Position pos, Snap.Position size, List <ElecManage.PositioningInfo> positionings, EdmDraw.EdmConfig edmConfig) { var ufSession = NXOpen.UF.UFSession.GetUFSession(); var selections = new List <TaggedObject>(); selections.Add(steel); positionings.ForEach(p => { selections.Add(p.Electrode.ElecBody); }); var topView = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_TOP).Tag, selections, pos, size, edmConfig); var topViewRightMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Right, topView) as Snap.NX.Line; var topViewTopMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Top, topView) as Snap.NX.Line; var topViewLeftMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Left, topView) as Snap.NX.Line; var topViewBottomMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Bottom, topView) as Snap.NX.Line; var originPoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(Snap.Globals.Wcs.Origin)); }, topView.Tag); var drawBorderPoints = EdmDraw.DrawBusiness.GetDrawBorderPoint(topView, steel); var originPointMTD = EdmDraw.DrawBusiness.MapModelToDrawing(topView.Tag, originPoint.Position); var listY = new List <double>(); var listX = new List <double>(); var temPoints = new List <Snap.Position>(); temPoints.Add(originPointMTD); temPoints.AddRange(drawBorderPoints); temPoints.OrderByDescending(u => u.Y).ToList().ForEach(u => { listY.Add(u.Y); }); temPoints.OrderBy(u => u.X).ToList().ForEach(u => { listX.Add(u.X); }); listY = listY.Distinct().ToList(); listX = listX.Distinct().ToList(); listX.ForEach(u => { var tempModel = new double[] { 0, 0, 0 }; ufSession.View.MapDrawingToModel(topView.Tag, new double[] { u, listY.Min() }, tempModel); var tempU = EdmDraw.DrawBusiness.CreateNxObject <Snap.NX.Point>(() => { return(Snap.Create.Point(tempModel)); }, topView.Tag); EdmDraw.DrawBusiness.CreateVerticalOrddimension( topView.Tag, originPoint.NXOpenTag, topViewBottomMargin.NXOpenTag, tempU.NXOpenTag ); }); listY.ForEach(u => { var tempModel = new double[] { 0, 0, 0 }; ufSession.View.MapDrawingToModel(topView.Tag, new double[] { listX.Min(), u }, tempModel); var tempU = EdmDraw.DrawBusiness.CreateNxObject <Snap.NX.Point>(() => { return(Snap.Create.Point(tempModel)); }, topView.Tag); EdmDraw.DrawBusiness.CreatePerpendicularOrddimension( topView.Tag, originPoint.NXOpenTag, topViewLeftMargin.NXOpenTag, tempU.NXOpenTag ); }); var tempDic = new Dictionary <ElecManage.PositioningInfo, Snap.NX.Point>(); var tempMTDDic = new Dictionary <ElecManage.PositioningInfo, Snap.Position>(); positionings.ForEach(p => { var electrode = p.Electrode; var elecBasePoint = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(p.X, p.Y, p.Z)); }, topView.Tag); tempDic.Add(p, elecBasePoint); }); positionings.ForEach(p => { var positioningMTD = EdmDraw.DrawBusiness.MapModelToDrawing(topView.Tag, tempDic[p].Position.Array); tempMTDDic.Add(p, positioningMTD); }); var tempVar = 3; var psY = positionings.OrderByDescending(p => tempMTDDic[p].Y).ToList(); double tempY = psY.Count > 0 ? tempMTDDic[psY.First()].Y : 0; psY.ForEach(p => { var elecBasePoint = tempDic[p]; var elecBasePointMTD = tempMTDDic[p]; var line = topViewTopMargin as Snap.NX.Line; if (elecBasePointMTD.Y < tempY || Math.Abs(elecBasePointMTD.Y - (edmConfig.DimensionMpr32 * 2 + tempY)) <= SnapEx.Helper.Tolerance) { tempY = elecBasePointMTD.Y; } Snap.Position origin = new Snap.Position(line.StartPoint.X, tempY); var minP = new Snap.Position(line.StartPoint.X, elecBasePointMTD.Y); var newElecBasePointMTD = new Snap.Position(line.StartPoint.X - tempVar, elecBasePointMTD.Y); var angle = Snap.Vector.Angle(newElecBasePointMTD - minP, newElecBasePointMTD - origin); var topViewRightElecBasePoint = EdmDraw.DrawBusiness.CreatePerpendicularOrddimension( topView.Tag, originPoint.NXOpenTag, topViewRightMargin.NXOpenTag, elecBasePoint.NXOpenTag , angle , origin , Snap.Compute.Distance(newElecBasePointMTD, topViewRightMargin) ); EdmDraw.DrawBusiness.SetToleranceType(topViewRightElecBasePoint); tempY -= edmConfig.DimensionMpr32 * 2; }); var psX = positionings.OrderByDescending(p => tempMTDDic[p].X).ToList(); double tempX = psX.Count > 0 ? tempMTDDic[psX.First()].X : 0; psX.ForEach(p => { var index = positionings.IndexOf(p); var elecBasePoint = tempDic[p]; var elecBasePointMTD = tempMTDDic[p]; var line = topViewTopMargin as Snap.NX.Line; var distance = Snap.Compute.Distance(elecBasePointMTD, topViewTopMargin); if (elecBasePointMTD.X < tempX || Math.Abs(elecBasePointMTD.X - (edmConfig.DimensionMpr32 * 2 + tempX)) <= SnapEx.Helper.Tolerance) { tempX = elecBasePointMTD.X; } Snap.Position origin = new Snap.Position(tempX, line.StartPoint.Y); var minP = new Snap.Position(elecBasePointMTD.X, line.StartPoint.Y); var newElecBasePointMTD = new Snap.Position(elecBasePointMTD.X, line.StartPoint.Y - tempVar); var angle = Snap.Vector.Angle(newElecBasePointMTD - minP, newElecBasePointMTD - origin); var topViewTopElecBasePoint = EdmDraw.DrawBusiness.CreateVerticalOrddimension( topView.Tag, originPoint.NXOpenTag, topViewTopMargin.NXOpenTag, elecBasePoint.NXOpenTag , angle , origin , Snap.Compute.Distance(newElecBasePointMTD, topViewTopMargin) ); EdmDraw.DrawBusiness.SetToleranceType(topViewTopElecBasePoint); tempX -= edmConfig.DimensionMpr32 * 2; }); if (positionings.Count > 1) { positionings.ForEach(p => { var elecBasePoint = tempDic[p]; var bps = EdmDraw.DrawBusiness.GetDrawBorderPoint(topView, p.Electrode.ElecBody); var bpXs = Enumerable.Select(bps, u => u.X); var bpYs = Enumerable.Select(bps, u => u.Y); var bpX = Math.Abs(bpXs.Max() - bpXs.Min()) * 2 / 3; var bpY = Math.Abs(bpYs.Max() - bpYs.Min()) * 2 / 3; var elecBasePointMTD = tempMTDDic[p]; var borderSize = topView.GetBorderSize(); var refPoint = topView.GetDrawingReferencePoint(); EdmDraw.DrawBusiness.CreateLabel(p.N, new Snap.Position(elecBasePointMTD.X - bpX, elecBasePointMTD.Y - bpY), new Snap.Position(), topView.Tag, elecBasePoint.NXOpenTag); }); } return(topView); }