Example #1
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);
        }
Example #2
0
        //------------------------------------------------------------------------------
        //Callback Name: apply_cb
        //------------------------------------------------------------------------------
        public int apply_cb()
        {
            int errorCode = 0;

            try
            {
                //---- Enter your callback code here -----

                if (this.selectPart != null)
                {
                    CoordinateSystem wcs  = workPart.WCS.CoordinateSystem;
                    Matrix4          matr = new Matrix4();
                    matr.Identity();
                    Part          temp = this.seleCt.Prototype as Part;
                    List <string> err  = new List <string>();
                    if (WorkModel.IsWork(temp))
                    {
                        WorkModel wm = new WorkModel(temp);
                        if (!this.addOrModify.Value)
                        {
                            matr.TransformToCsys(wcs, ref matr);
                            if (!this.AlterWork(wm, matr))
                            {
                                theUI.NXMessageBox.Show("错误", NXMessageBox.DialogType.Error, "修改设定坐标错误!");
                            }
                        }
                        else
                        {
                            AddWorkBuilder add           = new AddWorkBuilder(asmModel, this.seleCt);
                            string         workpieceName = this.GetWorkpieceNumber(this.workNumber.ValueAsString, wm);
                            if (wm.Info.MoldInfo.WorkpieceNumber.Equals(workpieceName, StringComparison.CurrentCultureIgnoreCase))
                            {
                                err.AddRange(add.CopWork(user.CreatorUser));
                            }
                            else
                            {
                                err.AddRange(add.CopOtherWork(user.CreatorUser, this.workNumber.ValueAsString));
                            }
                        }
                    }
                    else
                    {
                        if (!this.addOrModify.Value)
                        {
                            matr.TransformToCsys(wcs, ref matr);
                        }
                        else
                        {
                            matr = GetParentWorkMatr(seleCt);
                        }

                        AddWorkBuilder add = new AddWorkBuilder(asmModel, this.seleCt.Parent.Parent);
                        err.AddRange(add.CreateWork(user.CreatorUser, this.seleCt, matr));
                    }
                    if (err.Count > 0)
                    {
                        ClassItem.Print(err.ToArray());
                    }
                    if (points.Count != 0)
                    {
                        DeleteObject.Delete(this.points.ToArray());
                    }
                    CsysUtils.SetWcsToAbs();
                    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);
        }