/// <summary>
        /// 检查放电面积
        /// </summary>
        /// <param name="csys"></param>
        /// <param name="eleCt"></param>
        private void AskSetVaule(CartesianCoordinateSystem csys, ElectrodeSetValueInfo setValue, Component eleCt, ref List <string> err)
        {
            Part    elePart  = eleCt.Prototype as Part;
            Point3d setPoint = new Point3d(setValue.EleSetValue[0], setValue.EleSetValue[1], setValue.EleSetValue[2]);
            Point   pt       = GetSetPoint(elePart);

            if (pt == null)
            {
                err.Add(elePart.Name + "-" + setValue.Positioning + "               无法找到设定点!");
            }
            else if (!UMathUtils.IsEqual(setPoint, GetSetWorkPoint3d(pt, eleCt)))
            {
                err.Add(elePart.Name + "-" + setValue.Positioning + "                   设定值错误!");
            }
            Body     eleBody = GetOccsInBods(eleCt);
            BodyInfo info    = GetDischargeFace(csys, eleBody);

            if (info != null)
            {
                double newArea = info.GetProjectedArea(csys, work.Info.Matr);
                if (setValue.ProjectedArea >= 2 * newArea)
                {
                    setValue.ProjectedArea = newArea;
                    setValue.ContactArea   = info.ContactArea;
                    setValue.SetAttribute(eleCt);
                }
            }
        }
Beispiel #2
0
        private void GetBoundingBox()
        {
            Point3d     centerPt = new Point3d();
            Point3d     disPt    = new Point3d();
            Part        workPart = Session.GetSession().Parts.Work;
            List <Body> bodys    = new List <Body>();

            //  NXOpen.Assemblies.Component ct = AssmbliesUtils.GetPartComp(workPart, part)[0];
            foreach (NXOpen.Assemblies.Component ct in AssmbliesUtils.GetPartComp(workPart, part))
            {
                if (!ct.IsSuppressed)
                {
                    foreach (Body body in this.part.Bodies.ToArray())
                    {
                        bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, body.Tag) as Body);
                    }
                }
            }
            Matrix4 invers = workMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, workMatr, ref centerPt, ref disPt);
            LayerUtils.MoveDisplayableObject(201, bodys.ToArray());
            this.CenterPt = centerPt;
            this.DisPt    = disPt;
        }
Beispiel #3
0
        /// <summary>
        /// 保存坐标
        /// </summary>
        /// <param name="asm"></param>
        /// <returns></returns>
        public bool SaveCsys(Part asm)
        {
            UFSession theUFSession = UFSession.GetUFSession();

            try
            {
                PartUtils.SetPartDisplay(asm);
                List <NXOpen.Assemblies.Component> ct = AssmbliesUtils.GetPartComp(asm, this.PartTag);
                CsysUtils.SetWcsOfCenteAndMatr(this.Info.Matr.GetCenter(), this.Info.Matr.GetMatrix3());
                PartUtils.SetPartWork(ct[0]);
                CartesianCoordinateSystem csys = asm.WCS.Save();
                string name   = "WORK" + this.Info.WorkNumber.ToString();
                Tag    objTag = Tag.Null;
                theUFSession.Obj.CycleByName(name, ref objTag);
                if (objTag != Tag.Null)
                {
                    theUFSession.Obj.DeleteObject(objTag);
                }
                csys.Name  = name;
                csys.Layer = 200;
                csys.Color = 186;
                PartUtils.SetPartWork(null);
                CsysUtils.SetWcsToAbs();
                return(true);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("创建坐标错误" + ex.Message);
                return(false);
            }
        }
        /// <summary>
        /// 获取电极头在Work坐标系下得外形点
        /// </summary>
        protected void GetHeadBounbingBox()
        {
            Matrix4 workInv = workMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, workInv);

            BoundingBoxUtils.GetBoundingBoxInLocal(eleHead.ToArray(), csys, workMatr, ref centerPt, ref disPt);
        }
 public ComputeDischargeFace(Body eleBody, Body toolBody, Matrix4 matr, CartesianCoordinateSystem csys)
 {
     this.eleBody  = eleBody;
     this.toolBody = toolBody;
     this.matr     = matr;
     this.csys     = csys;
 }
Beispiel #6
0
        /// <summary>
        /// 创建外形点
        /// </summary>
        /// <returns></returns>
        private Point[] CreateMinAndMaxPt()
        {
            UFSession theUFSession = UFSession.GetUFSession();

            Point[] pt       = new Point[2];
            Point3d centerPt = new Point3d();
            Point3d disPt    = new Point3d();

            List <Body> bodys = new List <Body>();

            foreach (Body body in this.workpiece.Bodies.ToArray())
            {
                bodys.Add(AssmbliesUtils.GetNXObjectOfOcc(this.workpieceComp.Tag, body.Tag) as Body);
            }
            //  Body[] bodys = this.workpiece.Bodies.ToArray();
            Matrix4 invers = this.work.WorkMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(this.work.WorkMatr, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, this.work.WorkMatr, ref centerPt, ref disPt);
            this.CenterPt = centerPt;
            this.DisPt    = disPt;
            Point3d minPt = new Point3d(centerPt.X - disPt.X, centerPt.Y - disPt.Y, centerPt.Z - disPt.Z);
            Point3d maxPt = new Point3d(centerPt.X + disPt.X, centerPt.Y + disPt.Y, centerPt.Z + disPt.Z);

            invers.ApplyPos(ref maxPt);
            invers.ApplyPos(ref minPt);
            // PartUtils.SetPartWork(workpieceComp);
            pt[0] = PointUtils.CreatePoint(minPt);
            theUFSession.Obj.SetLayer(pt[0].Tag, 254);
            pt[1] = PointUtils.CreatePoint(maxPt);
            theUFSession.Obj.SetLayer(pt[1].Tag, 254);
            // PartUtils.SetPartWork(null);
            return(pt);
        }
        /// <summary>
        /// 移动
        /// </summary>
        /// <param name="vec"></param>
        /// <returns></returns>
        public bool MovePositionBuilder(Vector3d vec)
        {
            try
            {
                Matrix4 inv = this.work.Info.Matr.GetInversMatrix();
                CartesianCoordinateSystem csys        = BoundingBoxUtils.CreateCoordinateSystem(this.work.Info.Matr, inv);
                ElectrodeSetValueInfo     setValue    = ElectrodeSetValueInfo.GetAttribute(eleComp);
                ElectrodeSetValueInfo     newSetValue = setValue.Clone() as ElectrodeSetValueInfo;

                AssmbliesUtils.MoveCompPart(eleComp, vec, work.Info.Matr);
                NXObject instance = AssmbliesUtils.GetOccOfInstance(eleComp.Tag);
                BodyInfo info     = GetDischargeFace(csys, eleComp);
                newSetValue.EleSetValue[0]    = setValue.EleSetValue[0] + vec.X;
                newSetValue.EleSetValue[1]    = setValue.EleSetValue[1] + vec.Y;
                newSetValue.EleSetValue[2]    = setValue.EleSetValue[2] + vec.Z;
                newSetValue.Positioning       = GetPositionName();
                newSetValue.PositioningRemark = "设定值改变";
                if (info != null)
                {
                    newSetValue.ContactArea   = info.ContactArea;
                    newSetValue.ProjectedArea = info.GetProjectedArea(csys, this.work.Info.Matr);
                }
                newSetValue.SetAttribute(instance);
                return(true);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile("电极跑位错误!" + ex.Message);
                return(false);
            }
        }
Beispiel #8
0
        public static CartesianCoordinateSystem CreateCoordinateSystem(Point3d ori, Vector3d xVec, Vector3d yVec, Vector3d zVec)
        {
            NXOpen.Session theSession = NXOpen.Session.GetSession();
            NXOpen.Part    workPart   = theSession.Parts.Work;

            Matrix3x3 mat = new Matrix3x3();

            mat.Xx = xVec.X;
            mat.Xy = xVec.Y;
            mat.Xz = xVec.Z;

            mat.Yx = yVec.X;
            mat.Yy = yVec.Y;
            mat.Yz = yVec.Z;

            //Vector3d zVec = UMathUtils.VectorCross(xVec, yVec);

            mat.Zx = zVec.X;
            mat.Zy = zVec.Y;
            mat.Zz = zVec.Z;

            try
            {
                return(workPart.CoordinateSystems.CreateCoordinateSystem(ori, mat, true));
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("BoundingBoxUtils.CreateCoordinateSystem 矩阵不是正交!" + ex.Message);
                CartesianCoordinateSystem cas = workPart.CoordinateSystems.CreateCoordinateSystem(ori, xVec, yVec);
                cas.Blank();
                return(cas);
            }
        }
Beispiel #9
0
 /// <summary>
 /// Get the local coordinate system of the element at this vertex
 /// </summary>
 /// <param name="allowFlip">If true, the coordinate system may be aligned
 /// to point towards the centre of the element.  Otherwise, it will be the
 /// 'real' coordinate system</param>
 /// <returns></returns>
 public CartesianCoordinateSystem GetLocalCoordinateSystem(bool allowFlip = true)
 {
     if (Element is LinearElement)
     {
         var lEl = (LinearElement)Element;
         if (Description == "End")
         {
             var result = lEl.LocalCoordinateSystem(1);
             if (allowFlip)
             {
                 result = result.ReverseXY();
             }
             return(result);
         }
         else if (Description == "Start")
         {
             return(lEl.LocalCoordinateSystem());
         }
     }
     else if (Element is PanelElement)
     {
         var pEl    = (PanelElement)Element;
         var result = pEl.LocalCoordinateSystem();
         result = new CartesianCoordinateSystem(result, Position);
         //TODO: Align panel element vertices?
         return(result);
     }
     return(null);
 }
        /// <summary>
        /// 给齿上颜色
        /// </summary>
        private void SetHeadColour()
        {
            Matrix4 matr = new Matrix4();

            matr.Identity();
            Matrix4 inv = matr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(matr, inv);
            List <Body> bodys     = Session.GetSession().Parts.Work.Bodies.ToArray().ToList();
            var         toolhList = bodys.GroupBy(a => AttributeUtils.GetAttrForString(a, "ToolhName"));
            List <ElectrodeToolhInfo[, ]> toolhInfos = new List <ElectrodeToolhInfo[, ]>();

            try
            {
                foreach (var toolh in toolhList)
                {
                    ElectrodeToolhInfo[,] toolhInfo = pitch.GetToolhInfosForAttribute(toolh.ToList(), matr, csys);
                    toolhInfos.Add(toolhInfo);
                }
                if (toolhInfos.Count != 0)
                {
                    gapValue.SetERToolh(toolhInfos);
                }
            }
            catch (Exception ex)
            {
                ClassItem.WriteLogFile("设置颜色错误!" + ex.Message);
            }
        }
        /// <summary>
        /// 获取工件在Work坐标系下得外形点
        /// </summary>
        protected void GetWorkpieceBounbingBox(Part workpiecePart, out Point3d workpieceCenterPt, out Point3d workpieceDisPt)
        {
            workpieceDisPt    = new Point3d();
            workpieceCenterPt = new Point3d();
            Matrix4 workInv = workMatr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMatr, workInv);

            BoundingBoxUtils.GetBoundingBoxInLocal(workpiecePart.Bodies.ToArray(), csys, workMatr, ref workpieceCenterPt, ref workpieceDisPt);
        }
Beispiel #12
0
        /// <summary>
        /// 通过边界盒获得最大外形(相对Matr)
        /// </summary>
        /// <param name="centerPt"></param>
        /// <param name="disPt"></param>
        public void GetFaceBoundingBox(out Point3d centerPt, out Point3d disPt)
        {
            centerPt = new Point3d();
            disPt    = new Point3d();
            NXObject[] obj  = { this.Data.Face };
            Matrix4    inve = this.Matr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(this.Matr, inve);

            BoundingBoxUtils.GetBoundingBoxInLocal(obj, csys, this.Matr, ref centerPt, ref disPt);
        }
        public void GetQuadrant_PassCoordinate_ReturnQuadrant(int x, int y, CartesianQuadrant expectedQuadrant)
        {
            // Arrange
            var coordinateSystem = new CartesianCoordinateSystem();

            // Act
            var quadrant = coordinateSystem.GetQuadrant(x, y);

            // Assert
            quadrant.Should().Be(expectedQuadrant);
        }
Beispiel #14
0
 public BodyPitchClassify(List <Body> bodys, Matrix4 matr, CartesianCoordinateSystem csys, int xNum, int yNum)
 {
     this.xNum = xNum;
     this.yNum = yNum;
     foreach (Body bt in bodys)
     {
         info.Add(new BodyBoundingBoxInfo(bt, matr, csys));
     }
     classifyBodys = new Body[xNum, yNum];
     Classify();
 }
        /// <summary>
        /// 获取中心点
        /// </summary>
        private void GetHeadAttr()
        {
            Point3d centerPt = new Point3d();
            Point3d disPt    = new Point3d();
            Matrix4 matr     = this.conditionModel.Work.WorkMatr;
            Matrix4 invers   = matr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(matr, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(this.conditionModel.Bodys.ToArray(), csys, this.conditionModel.Work.WorkMatr, ref centerPt, ref disPt);
            this.DisPt    = disPt;
            this.CenterPt = centerPt;
        }
        /// <summary>
        /// 获取全部投影面积
        /// </summary>
        /// <returns></returns>
        public double GetProjectedArea(Matrix4 matr)
        {
            double  all = 0;
            Matrix4 inv = matr.GetInversMatrix();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(matr, inv);

            foreach (BodyInfo bi in this.BodyInfos)
            {
                all += bi.GetProjectedArea(csys, matr);
            }
            return(all);
        }
Beispiel #17
0
        internal static Snap.NX.DatumCsys CreateDatumCsys(Position origin, Snap.NX.Matrix matrix)
        {
            NXOpen.Part workPart = (NXOpen.Part)Globals.WorkPart;
            NXOpen.Features.DatumCsysBuilder featureBuilder = workPart.Features.CreateDatumCsysBuilder(null);
            Xform xform = workPart.Xforms.CreateXform((Point3d)origin, (Vector3d)matrix.AxisX, (Vector3d)matrix.AxisY, SmartObject.UpdateOption.WithinModeling, 1.0);
            CartesianCoordinateSystem system = workPart.CoordinateSystems.CreateCoordinateSystem(xform, SmartObject.UpdateOption.WithinModeling);

            featureBuilder.Csys = system;
            NXOpen.Features.DatumCsys datumCsys = (NXOpen.Features.DatumCsys)Snap.NX.Feature.CommitFeature(featureBuilder);
            featureBuilder.Destroy();
            return(new Snap.NX.DatumCsys(datumCsys));
        }
Beispiel #18
0
        public void CreateLineAndOrinig()
        {
            Point3d centerPt               = new Point3d();
            Point3d disPt                  = new Point3d();
            Matrix4 workMat                = this.DraModel.Work.WorkMatr;
            Matrix4 invers                 = workMat.GetInversMatrix();
            Part    workpiecePart          = GetWorkpiecePart();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMat, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(workpiecePart.Bodies.ToArray(), csys, workMat, ref centerPt, ref disPt);
            this.DraModel.Work.CreatePointAndCenterLine(centerPt, disPt);
        }
Beispiel #19
0
        /// <summary>
        /// 获取投影面积
        /// </summary>
        /// <returns></returns>
        public double GetProjectedArea(CartesianCoordinateSystem csys, Matrix4 matr)
        {
            if (this.DischargeFace.Count == 0)
            {
                return(0);
            }
            Point3d center = new Point3d();
            Point3d dis    = new Point3d();

            BoundingBoxUtils.GetBoundingBoxInLocal(this.DischargeFace.ToArray(), csys, matr, ref center, ref dis);
            return(2 * (dis.X * dis.Y));
        }
        //------------------------------------------------------------------------------
        //Callback Name: apply_cb
        //------------------------------------------------------------------------------
        public int apply_cb()
        {
            int errorCode = 0;

            try
            {
                //---- Enter your callback code here -----
                List <Body> toolBodys = new List <Body>();
                List <Body> eleBodys  = new List <Body>();
                Matrix4     mat       = new Matrix4();
                mat.Identity();
                Matrix4 inv = mat.GetInversMatrix();
                CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(mat, inv);
                List <string>             errs = new List <string>();
                foreach (TaggedObject tt in this.Selection.GetSelectedObjects())
                {
                    Body ttBody = tt as Body;
                    if (ttBody.Prototype != null)
                    {
                        ttBody = ttBody.Prototype as Body;
                    }
                    foreach (TaggedObject t0 in this.Selection1.GetSelectedObjects())
                    {
                        Body toBody = t0 as Body;
                        if (toBody.Prototype != null)
                        {
                            toBody = toBody.Prototype as Body;
                        }
                        if (!toBody.Equals(ttBody))
                        {
                            List <string>        err = new List <string>();
                            ComputeDischargeFace cf  = new ComputeDischargeFace(toBody, ttBody, mat, csys);
                            cf.GetBodyInfoForInterference(true, out err);
                            errs.AddRange(err);
                        }
                    }
                }
                if (errs.Count > 0)
                {
                    ClassItem.Print(errs.ToArray());
                }
            }
            catch (Exception ex)
            {
                //---- Enter your exception handling code here -----
                errorCode = 1;
                theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
            }
            return(errorCode);
        }
Beispiel #21
0
        public void GetBoundingBox()
        {
            Point3d     centerPt           = new Point3d();
            Point3d     disPt              = new Point3d();
            Matrix4     workMat            = this.DraModel.Work.WorkMatr;
            Matrix4     invers             = workMat.GetInversMatrix();
            List <Body> bodys              = GetBodys();
            CartesianCoordinateSystem csys = BoundingBoxUtils.CreateCoordinateSystem(workMat, invers);//坐标

            BoundingBoxUtils.GetBoundingBoxInLocal(bodys.ToArray(), csys, workMat, ref centerPt, ref disPt);
            this.CenterPt = centerPt;
            this.DisPt    = disPt;
            CreateLineAndOrinig();
        }
Beispiel #22
0
 /// <summary>
 /// 设置属性
 /// </summary>
 public bool SetAttribute(CartesianCoordinateSystem csys, Matrix4 matr)
 {
     try
     {
         AttributeUtils.AttributeOperation("ContactArea", this.ContactArea, this.Body);
         SetDischargeFaceAttr();
         return(true);
     }
     catch (NXException ex)
     {
         ClassItem.WriteLogFile("写入属性错误!" + ex.Message);
         return(false);
     }
 }
Beispiel #23
0
        public MoldBaseModel(Body body, Matrix4 mat, CartesianCoordinateSystem csys)
        {
            this.Body = body;
            this.matr = mat;

            NXObject[] obj    = { body };
            Point3d    center = new Point3d();
            Point3d    dis    = new Point3d();

            BoundingBoxUtils.GetBoundingBoxInLocal(obj, csys, mat, ref center, ref dis);
            this.CenterPt  = center;
            this.DisPt     = dis;
            this.Materials = "王牌";
        }
 public override bool Draw(RenderingParameters parameters)
 {
     if (parameters is RhinoRenderingParameters && _CoordinateSystem != null)
     {
         RhinoRenderingParameters rParams = (RhinoRenderingParameters)parameters;
         if (_CoordinateSystem is CartesianCoordinateSystem)
         {
             CartesianCoordinateSystem cSystem = (CartesianCoordinateSystem)_CoordinateSystem;
             rParams.Display.DrawDirectionArrow(ToRC.Convert(cSystem.Origin), ToRC.ConvertVector(cSystem.X), System.Drawing.Color.LightGray);
             rParams.Display.DrawDirectionArrow(ToRC.Convert(cSystem.Origin), ToRC.ConvertVector(cSystem.Y), System.Drawing.Color.Gray);
             rParams.Display.DrawDirectionArrow(ToRC.Convert(cSystem.Origin), ToRC.ConvertVector(cSystem.Z), System.Drawing.Color.Orange);
         }
         return(true);
     }
     return(false);
 }
        private BodyInfo GetDischargeFace(CartesianCoordinateSystem csys, Component ct)
        {
            List <string> err  = new List <string>();
            Part          host = work.GetHostWorkpiece();

            if (host == null)
            {
                return(null);
            }
            Body workBody           = host.Bodies.ToArray()[0];
            Body eleBody            = elePart.Bodies.ToArray()[0];
            Body comBody            = AssmbliesUtils.GetNXObjectOfOcc(ct.Tag, eleBody.Tag) as Body;
            ComputeDischargeFace cp = new ComputeDischargeFace(comBody, workBody, work.Info.Matr, csys);

            return(cp.GetBodyInfoForInterference(false, out err));
        }
        /// <summary>
        /// 得到放电面积
        /// </summary>
        /// <param name="bodys"></param>
        /// <param name="workpiece"></param>
        private void AskComputeDischargeFace(List <Body> bodys, Part workpiece)
        {
            List <string>             err           = new List <string>();
            Body                      workpieceBody = workpiece.Bodies.ToArray()[0];
            Matrix4                   inv           = this.work.Info.Matr.GetInversMatrix();
            CartesianCoordinateSystem csys          = BoundingBoxUtils.CreateCoordinateSystem(this.work.Info.Matr, inv);

            foreach (Body by in bodys)
            {
                if (!BodyInfo.IsContactArea(by))
                {
                    ComputeDischargeFace cdf = new ComputeDischargeFace(by, workpieceBody, this.work.Info.Matr, csys);
                    cdf.GetBodyInfoForInterference(false, out err);
                }
            }
        }
Beispiel #27
0
        public MoldBaseModel1(Body body, Matrix4 mat)
        {
            this.Body = body;
            this.matr = mat;
            Matrix4 inv = mat.GetInversMatrix();
            CartesianCoordinateSystem cs = BoundingBoxUtils.CreateCoordinateSystem(mat, inv);

            NXObject[] obj    = { body };
            Point3d    center = new Point3d();
            Point3d    dis    = new Point3d();

            BoundingBoxUtils.GetBoundingBoxInLocal(obj, cs, mat, ref center, ref dis);
            this.CenterPt  = center;
            this.DisPt     = dis;
            this.Materials = "王牌";
        }
        /// <summary>
        /// 分析放电面积
        /// </summary>
        /// <param name="csys"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        private BodyInfo GetDischargeFace(CartesianCoordinateSystem csys, Body eleCtBody)
        {
            List <string> err      = new List <string>();
            Component     hostComp = GetPartInOcc(hostPart);

            if (hostComp != null)
            {
                Body workBody = GetOccsInBods(hostComp);
                if (workBody != null)
                {
                    ComputeDischargeFace cp = new ComputeDischargeFace(eleCtBody, workBody, work.Info.Matr, csys);
                    return(cp.GetBodyInfoForInterference(false, out err));
                }
            }

            return(null);
        }
        /// <summary>
        /// 修改矩阵
        /// </summary>
        /// <param name="mat"></param>
        /// <param name="workNumber"></param>
        /// <returns></returns>
        public bool AlterMatr(Matrix4 mat, int workNumber)
        {
            WorkModel work = this.Model.Works.Find(x => x.WorkNumber == workNumber);

            if (work != null)
            {
                NXOpen.Assemblies.Component workComp = work.PartTag.OwningComponent.Parent;
                PartUtils.SetPartWork(workComp);
                work.AlterMatr(mat);
                CartesianCoordinateSystem csys = work.PartTag.WCS.Save();
                csys.Name  = "WORK" + workNumber.ToString();
                csys.Color = 186;
                csys.Layer = 200;
                return(true);
            }
            return(false);
        }
Beispiel #30
0
        //------------------------------------------------------------------------------
        //Callback Name: apply_cb
        //------------------------------------------------------------------------------
        public int apply_cb()
        {
            int errorCode = 0;

            try
            {
                //---- Enter your callback code here -----
                Part workPart = theSession.Parts.Work;

                CoordinateSystem wcs = workPart.WCS.CoordinateSystem;

                Matrix4 matr = new Matrix4();
                matr.Identity();
                matr.TransformToCsys(wcs, ref matr);
                string number = this.workNumber.ValueAsString.Substring(4);

                if (addOrModify.Value)
                {
                    AddWorkBuilder.CreateWork(matr, Convert.ToInt32(number), asmPart);
                }
                else
                {
                    AddWorkBuilder.AlterMatr(matr, Convert.ToInt32(number), asmPart);
                }
                CartesianCoordinateSystem csys = workPart.WCS.Save();

                csys.Name  = this.workNumber.ValueAsString;
                csys.Layer = 200;
                csys.Color = 186;

                PartUtils.SetPartDisplay(asmPart);
                CsysUtils.SetWcsToAbs();
                DeleteObject.Delete(this.points.ToArray());
                bool anyPartsModified1;
                NXOpen.PartSaveStatus partSaveStatus1;
                Session.GetSession().Parts.SaveAll(out anyPartsModified1, out partSaveStatus1);
            }
            catch (Exception ex)
            {
                //---- Enter your exception handling code here -----
                errorCode = 1;
                theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
            }
            return(errorCode);
        }