Example #1
0
        /// <summary>
        /// 主工件图
        /// </summary>
        /// <param name="workpiecePart"></param>
        private void HostWorkpieceDrawing(double scale)
        {
            Part workPart = Session.GetSession().Parts.Work;

            DrawingSheet[] st = workPart.DrawingSheets.ToArray();
            if (st.Length > 0)
            {
                DeleteObject.Delete(st);
            }
            this.originPoint = PointUtils.CreatePointFeature(this.work.Info.Matr.GetCenter());
            WorkpieceDrawing dra = new WorkpieceDrawing(hostDraw, work, workDra, this.originPoint);

            try
            {
                NXOpen.Drawings.DrawingSheet sheet = Basic.DrawingUtils.DrawingSheet(workpieceDrawTemplate, 297, 420, workDra.HostComp[0].Name);
                dra.CreateView(scale, GetFirstPoint(hostDraw, scale), this.workpieceTablePath);
                double[] plistOrigin = { 180, 120, 0 };
                Basic.DrawingUtils.CreatePlist(plistPath, plistOrigin);
                Basic.DrawingUtils.UpdateViews(sheet);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile(hostDraw.WorkpiecePart.Name + "创建图纸错误!         " + ex.Message);
                return;
            }
        }
Example #2
0
    void CreateEACT_BOTTOMView(NXOpen.Drawings.DrawingSheet ds, List <NXOpen.TaggedObject> selections, Snap.Position pos, Snap.Position size, ElecManage.Electrode electrode, EdmDraw.EdmConfig edmConfig)
    {
        var bottomView             = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM).Tag, selections, pos, size, edmConfig);
        var bottomViewBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomView, electrode.ElecBody);

        var yPlusSideFace  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewBorderPoints[1])); }, bottomView.Tag);
        var yMinusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewBorderPoints[0])); }, bottomView.Tag);
        var xPlusSideFace  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewBorderPoints[0], bottomViewBorderPoints[1])); }, bottomView.Tag);
        var xMinusSideFace = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewBorderPoints[2], bottomViewBorderPoints[3])); }, bottomView.Tag);

        //电极仰视图
        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));

        var bottomViewElecHeadBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomView, electrode.ElecHeadFaces);

        var yPlusElectrodeEdge  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewElecHeadBorderPoints[1])); }, bottomView.Tag);
        var yMinusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Point(bottomViewElecHeadBorderPoints[0])); }, bottomView.Tag);
        var xPlusElectrodeEdge  = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewElecHeadBorderPoints[0], bottomViewElecHeadBorderPoints[1])); }, bottomView.Tag);
        var xMinusElectrodeEdge = EdmDraw.DrawBusiness.CreateNxObject(() => { return(Snap.Create.Line(bottomViewElecHeadBorderPoints[2], bottomViewElecHeadBorderPoints[3])); }, bottomView.Tag);

        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));
    }
Example #3
0
        public static string ExportPDF(NXOpen.Drawings.DrawingSheet ds, string dsName)
        {
            if (Directory.Exists(_pdfFilePath))
            {
                Directory.Delete(_pdfFilePath, true);
            }
            Directory.CreateDirectory(_pdfFilePath);

            Session         theSession  = Session.GetSession();
            Part            workPart    = theSession.Parts.Work;
            Part            displayPart = theSession.Parts.Display;
            PrintPDFBuilder printPDFBuilder1;

            printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder();

            NXObject[] sheets1 = new NXObject[1];
            NXOpen.Drawings.DrawingSheet drawingSheet1 = ds;
            sheets1[0] = drawingSheet1;
            printPDFBuilder1.SourceBuilder.SetSheets(sheets1);
            var fileName = string.Format("{0}{1}", dsName, ".pdf");
            var result   = System.IO.Path.Combine(_pdfFilePath, fileName);

            printPDFBuilder1.Filename = result;

            NXObject nXObject1;

            nXObject1 = printPDFBuilder1.Commit();

            printPDFBuilder1.Destroy();

            return(result);
        }
Example #4
0
        private void CreateView()
        {
            double scale = GetScale();

            NXOpen.Drawings.DrawingSheet sheet = Basic.DrawingUtils.DrawingSheet(eleTemplate, 297, 420, draInfo.DraModel.AssembleName);
            Point3d origin      = GetViewOriginPt(scale);
            Point3d projectedPt = new Point3d(0, 0, 0);

            projectedPt.X = origin.X;
            projectedPt.Y = origin.Y - (draInfo.DisPt.Y + draInfo.DisPt.Z) * scale - 30;
            DraftingView topView = Basic.DrawingUtils.CreateView("TOP", origin, scale, draInfo.DraModel.Work.WorkMatr, draInfo.GetHideComp());
            DraftingView proView = Basic.DrawingUtils.CreateProjectedView(topView, projectedPt, scale);

            double eleScale = GetEleScale();

            int[]   pre             = draInfo.DraModel.Eles[0].EleInfo.Preparation;
            Point3d eleOrigin       = GetEleOrigin(eleScale);
            Point3d projectedElePt1 = new Point3d(eleOrigin.X, eleOrigin.Y + (pre[1] * eleScale / 2 + pre[2] * eleScale / 2 + 30), 0);
            Point3d projectedElePt2 = new Point3d(projectedElePt1.X - (pre[0] * eleScale / 2 + pre[1] * eleScale / 2 + 30), projectedElePt1.Y, 0);

            DraftingView topEleView = Basic.DrawingUtils.CreateView("TOP", eleOrigin, eleScale, draInfo.DraModel.Eles[0].EleMatr, draInfo.GetEleHideComp());

            Basic.DrawingUtils.SetWireframeColorSource(NXOpen.Preferences.GeneralWireframeColorSourceOption.FromFace, topEleView);
            DraftingView proEleView1 = Basic.DrawingUtils.CreateProjectedView(topEleView, projectedElePt1, eleScale);
            DraftingView proEleView2 = Basic.DrawingUtils.CreateProjectedView(proEleView1, projectedElePt2, eleScale);

            Matrix4 mat = new Matrix4(draInfo.DraModel.Eles[0].EleMatr);

            mat.RolateWithX(-2 * Math.PI / 5);
            mat.RolateWithY(Math.PI / 10);
            DraftingView topEleView2 = Basic.DrawingUtils.CreateView("Trimetric", new Point3d(240, 120, 0), eleScale, mat, draInfo.GetEleHideComp());

            List <Point> elePoint  = this.draInfo.DraModel.GetEleCompPint();
            Point        workPoint = this.draInfo.DraModel.GetWorkCompPoint();

            TopDimension(topView, origin, scale, workPoint, elePoint);
            ProViewDimension(proView, projectedPt, scale, workPoint, elePoint);

            List <Face> face = this.draInfo.EleFaceSort();

            // EleTopDimension(topEleView, eleOrigin, eleScale, face[0]);
            EleProViewDimension(proEleView2, projectedElePt2, eleScale, face[10], elePoint[0]);
            SetViewVisible(new DraftingView[6] {
                topView, proView, topEleView, proEleView1, proEleView2, topEleView2
            });

            if (this.draInfo.DraModel.EleInfo.IsPreparation)
            {
                Basic.DrawingUtils.SetNote(new Point3d(130, 20, 0), 6, "标准铜料");
            }
            else if (!this.draInfo.DraModel.EleInfo.IsPreparation)
            {
                Basic.DrawingUtils.SetNote(new Point3d(130, 20, 0), 6, "非标准铜料");
            }
            Basic.DrawingUtils.SetNote(new Point3d(130, 30, 0), 4, this.draInfo.EleModel.EleInfo.ElePresentation);
            Basic.DrawingUtils.UpdateViews(sheet);
        }
 /// <summary>
 /// 创建特征
 /// </summary>
 public void CreateBulider()
 {
     CreatDwgPart();
     NXOpen.Drawings.DrawingSheet sheet = CreateSetValueView();
     CreateEleView();
     SetLayer(201);
     SetNode();
     Basic.DrawingUtils.UpdateViews(sheet);
     Session.GetSession().ApplicationSwitchImmediate("UG_APP_DRAFTING");
     model.PartTag.Save(BasePart.SaveComponents.False, BasePart.CloseAfterSave.False);
 }
Example #6
0
        /// <summary>
        /// 更新视图
        /// </summary>
        public static void UpdateViews(NXOpen.Drawings.DrawingSheet sheet)
        {
            Part workPart = theSession.Parts.Work;
            List <NXOpen.Drawings.DraftingView> views = new List <DraftingView>();

            foreach (DraftingView dv in sheet.GetDraftingViews())
            {
                if (dv.IsOutOfDate)
                {
                    views.Add(dv);
                }
            }
            workPart.DraftingViews.UpdateViews(views.ToArray());
        }
        private void FixCreateBalloonDlg_Load(object sender, EventArgs e)
        {
            #region 系統環境
            Variables.Is_Local = Environment.GetEnvironmentVariable("UGII_ENV_FILE");
            if (Variables.Is_Local == null)
            {
                MessageBox.Show("請先使用系統後再執行!");
                this.Close();
                return;
            }
            #endregion

            //抓取目前圖紙數量和Tag
            //取得全部尺寸資料,並整理出尺寸落在的圖紙&尺寸設定的自定義泡泡再填入Panel中(當使用者點自定義時使用)
            int          SheetCount  = 0;
            NXOpen.Tag[] SheetTagAry = null;
            theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
            Dictionary <NXObject, Sheet_DefineNum> DicUserDefine = new Dictionary <NXObject, Sheet_DefineNum>();
            for (int i = 0; i < SheetCount; i++)
            {
                NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                CurrentSheet.Open();
                CurrentSheet.View.UpdateDisplay();
                NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                GetUserDefineData(SheetObj, CurrentSheet.Name, ref DicUserDefine);
            }

            NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]);
            DefaultSheet.Open();

            int     count = 0;
            GridRow row   = new GridRow();
            foreach (KeyValuePair <NXObject, Sheet_DefineNum> kvp in DicUserDefine)
            {
                row = new GridRow(new object[SGC.PrimaryGrid.Columns.Count]);
                SGC.PrimaryGrid.Rows.Add(row);
                count = count + 1;
                row.Cells["序號"].Value        = count;
                row.Cells["尺寸位置"].Value      = kvp.Value.sheet;
                row.Cells["自定泡泡號"].Value     = kvp.Value.defineNum;
                row.Cells["Dimension"].Value = kvp.Key;
            }
        }
Example #8
0
    void CreateEACT_BOTTOM_FRONTView(NXOpen.Drawings.DrawingSheet ds, List <NXOpen.TaggedObject> selections, Snap.Position pos, Snap.Position size, ElecManage.Electrode electrode, EdmDraw.EdmConfig edmConfig)
    {
        var bottomFrontView             = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_BOTTOM_FRONT).Tag, selections, pos, size, edmConfig);
        var baseFace                    = electrode.BaseFace;
        var bottomFrontViewBorderPoints = EdmDraw.DrawBusiness.GetBorderPoint(bottomFrontView, electrode.ElecBody);

        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);

        //电极前视图
        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));
    }
Example #9
0
        /// <summary>
        /// 更新视图
        /// </summary>
        public static void UpdateViews(NXOpen.Drawings.DrawingSheet sheet)
        {
            Part workPart = theSession.Parts.Work;
            List <NXOpen.Drawings.DraftingView> views = new List <DraftingView>();

            foreach (DraftingView dv in sheet.GetDraftingViews())
            {
                if (dv.IsOutOfDate)
                {
                    views.Add(dv);
                }
            }
            try
            {
                workPart.DraftingViews.UpdateViews(views.ToArray());
            }
            catch (NXException ex)
            {
                LogMgr.WriteLog("DrawingUtils:UpdateViews" + ex.Message);
                throw ex;
            }
        }
        /// <summary>
        /// 创建设定图
        /// </summary>
        public NXOpen.Drawings.DrawingSheet CreateSetValueView()
        {
            Matrix4 inv = model.GetWorkMatr().GetInversMatrix();

            inv.ApplyPos(ref centerPt);
            double scale = model.GetScale(130.0, 170.0, disPt);

            NXOpen.Drawings.DrawingSheet sheet = Basic.DrawingUtils.DrawingSheet(eleTemplate, 297, 420, model.AssembleName);
            Point3d origin      = GetSetValueViewOriginPt(scale);
            Point3d projectedPt = new Point3d(0, 0, 0);

            projectedPt.X = origin.X;
            projectedPt.Y = origin.Y - (disPt.Y + disPt.Z) * scale - 30;
            DraftingView topView = null;
            DraftingView proView = null;

            try
            {
                topView = Basic.DrawingUtils.CreateView("TOP", origin, scale, model.GetWorkMatr(), setValueHidden.ToArray());
                proView = Basic.DrawingUtils.CreateProjectedView(topView, projectedPt, scale);
            }
            catch (NXException ex)
            {
                ClassItem.WriteLogFile(model.AssembleName + "视图创建错误!" + ex.Message);
            }
            Point        workPt = model.CreateCenterPoint();
            List <Point> setPt  = model.GetEleSetPoint();

            if (topView != null || workPt == null || setPt.Count > 0)
            {
                TopDimension(topView, scale, origin, workPt, setPt);
            }
            if (proView != null || workPt == null || setPt.Count > 0)
            {
                ProViewDimension(proView, scale, projectedPt, workPt, setPt);
            }
            SetViewVisible(new DraftingView[] { topView, proView });
            return(sheet);
        }
Example #11
0
    BaseView CreateEACT_FRONTView(NXOpen.Drawings.DrawingSheet ds, List <NXOpen.TaggedObject> selections, Snap.Position pos, Snap.Position size, ElecManage.Electrode electrode, EdmDraw.EdmConfig edmConfig)
    {
        var frontView            = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_FRONT).Tag, selections, pos, size, edmConfig);
        var frontViewRightMargin = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Right, frontView);
        var frontViewLeftMargin  = EdmDraw.DrawBusiness.GetViewBorder(EdmDraw.ViewBorderType.Left, frontView);


        var ufSession     = NXOpen.UF.UFSession.GetUFSession();
        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 drawBorderPoints = EdmDraw.DrawBusiness.GetDrawBorderPoint(frontView, Snap.NX.Body.Wrap(selections.First().Tag));
        var listY            = Enumerable.Select(drawBorderPoints, u => u.Y).ToList();
        var listX            = Enumerable.Select(drawBorderPoints, u => u.X).ToList();

        listY.Add(EdmDraw.DrawBusiness.MapModelToDrawing(frontView.Tag, originPoint.Position).Y);
        listY.Distinct().ToList().ForEach(u => {
            var tempModel = new double[] { 0, 0, 0 };
            ufSession.View.MapDrawingToModel(frontView.Tag, new double[] { listX.Min(), u }, tempModel);
            var tempU = EdmDraw.DrawBusiness.CreateNxObject <Snap.NX.Point>(() => { return(Snap.Create.Point(tempModel)); }, frontView.Tag);
            EdmDraw.DrawBusiness.CreatePerpendicularOrddimension(
                frontView.Tag,
                originPoint.NXOpenTag,
                frontViewLeftMargin.NXOpenTag,
                tempU.NXOpenTag
                );
        });

        var frontViewOrddimension = EdmDraw.DrawBusiness.CreatePerpendicularOrddimension(
            frontView.Tag,
            originPoint.NXOpenTag,
            frontViewRightMargin.NXOpenTag,
            elecBasePoint.NXOpenTag
            );

        EdmDraw.DrawBusiness.SetToleranceType(frontViewOrddimension);

        return(frontView);
    }
        private bool JudgmentBalloon(GridRow row)
        {
            string oldBalloon = "";

            try
            {
                oldBalloon = ((NXObject)row.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.BallonNum);
                if (oldBalloon == row.Cells["自定泡泡號"].Value.ToString())
                {
                    return(false);
                }
                NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(row.Cells["尺寸位置"].Value.ToString());
                NXObject[] SheetObj = CaxME.FindObjectsInView(drawingSheet1.View.Tag).ToArray();
                CaxME.DeleteFixBallon(oldBalloon, SheetObj);
                workPart.Views.Refresh();
            }
            catch (System.Exception ex)
            {
                oldBalloon = "";
            }
            return(true);
        }
Example #13
0
        /// <summary>
        /// 创建一张其他工件图
        /// </summary>
        /// <param name="other"></param>
        /// <param name="scale"></param>
        private void OtherWorkpieceView(List <WorkpieceDrawingModel> other, double scale)
        {
            Point3d firstPt = GetFirstPoint(other[0], scale);
            double  length  = 0;

            foreach (WorkpieceDrawingModel wk in other)
            {
                length += 2 * wk.DisPt.X * scale;
            }

            int k = 0;

            if (other.Count == 1)
            {
                k = 0;
            }
            else
            {
                k = (int)Math.Floor(300 - length) / (other.Count - 1);
            }
            NXOpen.Drawings.DrawingSheet sheet = Basic.DrawingUtils.DrawingSheet(workpieceDrawTemplate, 297, 420, other[0].WorkpiecePart.Name);
            for (int i = 0; i < other.Count; i++)
            {
                Point3d temp;
                if (i == 0)
                {
                    temp = firstPt;
                }
                else
                {
                    double x = other[i - 1].DisPt.X * scale + other[i].DisPt.X * scale + i * k;
                    temp = new Point3d(firstPt.X + x, firstPt.Y, firstPt.Z);
                }
                WorkpieceDrawing wd = new WorkpieceDrawing(other[i], this.work, workDra, this.originPoint);
                wd.CreateView(scale, temp, this.workpieceTablePath);
            }
            Basic.DrawingUtils.UpdateViews(sheet);
        }
Example #14
0
        /// <summary>
        /// 创建图纸模板
        /// </summary>
        /// <param name="sheetPath">模板地址</param>
        /// <param name="height">模板高</param>
        /// <param name="length">模板长</param>
        /// <param name="drawName">图纸名</param>
        /// <returns></returns>
        public static NXOpen.Drawings.DrawingSheet DrawingSheet(string sheetPath, double height, double length, string drawName)
        {
            Part workPart = theSession.Parts.Work;

            NXOpen.Drawings.DrawingSheet        nullNXOpen_Drawings_DrawingSheet = null;
            NXOpen.Drawings.DrawingSheetBuilder drawingSheetBuilder1;
            drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(nullNXOpen_Drawings_DrawingSheet);
            drawingSheetBuilder1.AutoStartViewCreation = true;                                                             //自动创建视图设置
            drawingSheetBuilder1.StandardMetricScale   = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11; //设置图纸比例为1:1
            drawingSheetBuilder1.Height                      = height;
            drawingSheetBuilder1.Length                      = length;
            drawingSheetBuilder1.ScaleNumerator              = 1.0;                                                            //自定义比例分子
            drawingSheetBuilder1.ScaleDenominator            = 1.0;                                                            //自定义比例分母
            drawingSheetBuilder1.Units                       = NXOpen.Drawings.DrawingSheetBuilder.SheetUnits.Metric;          //图纸单位为公制
            drawingSheetBuilder1.ProjectionAngle             = NXOpen.Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third; //投影视角为第三视角
            drawingSheetBuilder1.Number                      = "1";                                                            //创建或编辑图纸的编号
            drawingSheetBuilder1.SecondaryNumber             = "";                                                             //创建或编辑图纸的次要编号
            drawingSheetBuilder1.Revision                    = "A";                                                            //创建或编辑图纸的修订版
            drawingSheetBuilder1.MetricSheetTemplateLocation = sheetPath;                                                      //模板地址
            drawingSheetBuilder1.Name = drawName;
            try
            {
                NXOpen.NXObject nXObject1;
                nXObject1 = drawingSheetBuilder1.Commit();
                nXObject1.SetName(drawName);
                return(nXObject1 as NXOpen.Drawings.DrawingSheet);
            }
            catch (Exception ex)
            {
                LogMgr.WriteLog("DrawingUtils.DrawingSheet" + ex.Message);
                return(null);
            }
            finally
            {
                drawingSheetBuilder1.Destroy();
            }
        }
        private void InsertBalloon(GridRow row, CoordinateData cCoordinateData)
        {
            try
            {
                //取得圖紙長、高
                NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(row.Cells["尺寸位置"].Value.ToString());
                drawingSheet1.Open();
                double SheetLength = drawingSheet1.Length;
                double SheetHeight = drawingSheet1.Height;

                //事先塞入該尺寸所在Sheet
                ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.SheetName, row.Cells["尺寸位置"].Value.ToString());
                //計算泡泡座標
                CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();
                CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)row.Cells["Dimension"].Value).Tag, out cBoxCoordinate);
                DimenData sDimenData = new DimenData();
                Variables.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                Point3d BallonLocation = new Point3d();
                BallonLocation.X = sDimenData.LocationX;
                BallonLocation.Y = sDimenData.LocationY;
                //決定數字的大小
                double BallonNumSize = 0;
                if (Convert.ToInt32(row.Cells["自定泡泡號"].Value) <= 9)
                {
                    BallonNumSize = 2.5;
                }
                else if (Convert.ToInt32(row.Cells["自定泡泡號"].Value) > 9 && Convert.ToInt32(row.Cells["自定泡泡號"].Value) <= 99)
                {
                    BallonNumSize = 1.5;
                }
                else
                {
                    BallonNumSize = 1;
                }
                NXObject balloonObj = null;
                CaxME.CreateBallonOnSheet(row.Cells["自定泡泡號"].Value.ToString(), BallonLocation, BallonNumSize, "BalloonAtt", out balloonObj);

                //取得該尺寸數量
                string diCount = "";
                try
                {
                    diCount = ((NXObject)row.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.DiCount);
                }
                catch (System.Exception ex)
                {
                    //當遇到舊料號沒有Dicount的屬性時,在這邊補上
                    ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.DiCount, "1");
                    diCount = "1";
                }
                //如果大於1表示要插入a.b.c.....
                if (diCount != "1")
                {
                    //文字座標
                    CaxME.BoxCoordinate sBoxCoordinate = new CaxME.BoxCoordinate();
                    CaxME.GetTextBoxCoordinate(balloonObj.Tag, out sBoxCoordinate);
                    Point3d textCoord = new Point3d(sBoxCoordinate.lower_left[0] + 1.5, sBoxCoordinate.lower_left[1] - 1.5, 0);
                    string  countText = Convert.ToChar(65 + 0).ToString().ToLower() + "-" + Convert.ToChar(65 + Convert.ToInt32(diCount) - 1).ToString().ToLower();
                    CaxME.InsertDicountNote(row.Cells["自定泡泡號"].Value.ToString(), CaxME.DimenAttr.DiCount, countText, "1.8", textCoord);
                }

                #region 計算泡泡相對位置
                string RegionX = "", RegionY = "";
                for (int ii = 0; ii < cCoordinateData.DraftingCoordinate.Count; ii++)
                {
                    string SheetSize = cCoordinateData.DraftingCoordinate[ii].SheetSize;
                    if (Math.Ceiling(SheetHeight) != Convert.ToDouble(SheetSize.Split(',')[0]) || Math.Ceiling(SheetLength) != Convert.ToDouble(SheetSize.Split(',')[1]))
                    {
                        continue;
                    }
                    //比對X
                    for (int j = 0; j < cCoordinateData.DraftingCoordinate[ii].RegionX.Count; j++)
                    {
                        string X0 = cCoordinateData.DraftingCoordinate[ii].RegionX[j].X0;
                        string X1 = cCoordinateData.DraftingCoordinate[ii].RegionX[j].X1;
                        if (BallonLocation.X >= Convert.ToDouble(X0) && BallonLocation.X <= Convert.ToDouble(X1))
                        {
                            RegionX = cCoordinateData.DraftingCoordinate[ii].RegionX[j].Zone;
                        }
                    }
                    //比對Y
                    for (int j = 0; j < cCoordinateData.DraftingCoordinate[ii].RegionY.Count; j++)
                    {
                        string Y0 = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Y0;
                        string Y1 = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Y1;
                        if (BallonLocation.Y >= Convert.ToDouble(Y0) && BallonLocation.Y <= Convert.ToDouble(Y1))
                        {
                            RegionY = cCoordinateData.DraftingCoordinate[ii].RegionY[j].Zone;
                        }
                    }
                }
                #endregion

                ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.BallonNum, row.Cells["自定泡泡號"].Value.ToString());
                ((NXObject)row.Cells["Dimension"].Value).SetAttribute(CaxME.DimenAttr.BallonLocation, row.Cells["尺寸位置"].Value.ToString() + "-" + RegionY + RegionX);
                workPart.Views.Refresh();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #16
0
    //------------------------------------------------------------------------------
    //  Explicit Activation
    //      This entry point is used to activate the application explicitly
    //------------------------------------------------------------------------------
    public static int Main(string[] args)
    {
        int retValue = 0;

        try
        {
            theProgram = new Program();

            Session theSession  = Session.GetSession();
            Part    workPart    = theSession.Parts.Work;
            Part    displayPart = theSession.Parts.Display;

            int module_id;
            theUfSession.UF.AskApplicationModule(out module_id);
            if (module_id != UFConstants.UF_APP_DRAFTING)
            {
                MessageBox.Show("請先轉換為製圖模組後再執行!");
                return(retValue);
            }

            bool status, Is_Keep;

            //抓取目前圖紙數量和Tag
            //取得全部尺寸資料,並整理出尺寸落在的圖紙&尺寸設定的自定義泡泡再填入Panel中(當使用者點自定義時使用)
            int          SheetCount  = 0;
            NXOpen.Tag[] SheetTagAry = null;
            theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
            Dictionary <NXObject, Sheet_DefineNum> DicUserDefine = new Dictionary <NXObject, Sheet_DefineNum>();
            for (int i = 0; i < SheetCount; i++)
            {
                NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                CurrentSheet.Open();
                CurrentSheet.View.UpdateDisplay();
                NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                GetUserDefineData(SheetObj, CurrentSheet.Name, ref DicUserDefine);
            }

            NXOpen.Drawings.DrawingSheet DefaultSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0]);
            DefaultSheet.Open();

            Application.EnableVisualStyles();
            CreateBallonDlg cCreateBallonDlg = new CreateBallonDlg(DicUserDefine);
            FormUtilities.ReparentForm(cCreateBallonDlg);
            System.Windows.Forms.Application.Run(cCreateBallonDlg);
            if (cCreateBallonDlg.DialogResult == DialogResult.Yes)
            {
                Is_Keep = cCreateBallonDlg.Is_Keep;
                cCreateBallonDlg.Dispose();
            }
            else
            {
                ((NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[0])).Open();
                cCreateBallonDlg.Dispose();
                theProgram.Dispose();
                return(retValue);
            }


            #region 前置處理
            string         Is_Local        = Environment.GetEnvironmentVariable("UGII_ENV_FILE");
            CoordinateData cCoordinateData = new CoordinateData();
            if (Is_Local != null)
            {
                //取得圖紙範圍資料Data
                status = CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData);
                if (!status)
                {
                    return(retValue);
                }
            }
            else
            {
                string DraftingCoordinate_dat  = "DraftingCoordinate.dat";
                string DraftingCoordinate_Path = string.Format(@"{0}\{1}", "D:", DraftingCoordinate_dat);
                CaxPublic.ReadCoordinateData(DraftingCoordinate_Path, out cCoordinateData);
            }

            //圖紙長、高
            double SheetLength = 0;
            double SheetHeight = 0;


            //取得最後一顆泡泡的數字
            int MaxBallonNum;
            try
            {
                MaxBallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum));
            }
            catch (System.Exception ex)
            {
                MaxBallonNum = 0;
            }
            #endregion

            //重新產生泡泡
            if (Is_Keep == false)
            {
                #region 刪除全部泡泡
                IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols;
                IdSymbol[]         BallonAry        = BallonCollection.ToArray();
                foreach (IdSymbol i in BallonAry)
                {
                    try
                    {
                        i.GetStringAttribute("BalloonAtt");
                    }
                    catch (System.Exception ex)
                    {
                        continue;
                    }
                    CaxPublic.DelectObject(i);
                }
                workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "BALLONNUM");
                #endregion


                #region 存DicDimenData(string=檢具名稱,DimenData=尺寸物件、泡泡座標)
                DefineParam.DicDimenData = new Dictionary <string, List <DimenData> >();
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    //string SheetName = "S" + (i + 1).ToString();
                    //CaxME.SheetRename(CurrentSheet, SheetName);
                    CurrentSheet.Open();

                    if (i == 0)
                    {
                        DefineParam.FirstDrawingSheet = CurrentSheet;
                    }

                    //取得圖紙長、高
                    SheetLength = CurrentSheet.Length;
                    SheetHeight = CurrentSheet.Height;

                    //DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects();
                    NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        #region 刪除尺寸數量產生的文字(ex:a-c)
                        string dicount = "", chekcLevel = "";
                        try
                        {
                            dicount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount);
                        }
                        catch (System.Exception ex)
                        {
                            dicount = "";
                        }
                        try
                        {
                            chekcLevel = singleObj.GetStringAttribute(CaxME.DimenAttr.CheckLevel);
                        }
                        catch (System.Exception ex)
                        {
                            chekcLevel = "";
                        }
                        if (dicount != "" && chekcLevel == "")
                        {
                            CaxPublic.DelectObject(singleObj);
                        }
                        #endregion

                        string Gauge = "", AssignExcelType = "";
                        #region 判斷是否有屬性,沒有屬性就跳下一個
                        try{ AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.AssignExcelType); }
                        catch (System.Exception ex) { continue; }
                        try{ Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.Gauge); }
                        catch (System.Exception ex) { }
                        #endregion

                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        //string DimeType = singleObj.GetType().ToString();
                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();
                        //GetTextBoxCoordinate(DimeType, singleObj, out cBoxCoordinate);

                        //可以將NXOpen直接轉型成Annotation
                        CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)singleObj).Tag, out cBoxCoordinate);

                        #region 計算泡泡座標
                        DimenData sDimenData = new DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        Functions.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        if (Gauge != "")
                        {
                            List <DimenData> ListDimenData = new List <DimenData>();
                            status = DefineParam.DicDimenData.TryGetValue(Gauge, out ListDimenData);
                            if (!status)
                            {
                                ListDimenData = new List <DimenData>();
                            }
                            ListDimenData.Add(sDimenData);
                            DefineParam.DicDimenData[Gauge] = ListDimenData;
                        }
                    }
                }
                #endregion

                //插入泡泡
                int BallonNum = 0;
                InsertBallon(ref BallonNum, cCoordinateData, SheetHeight, SheetLength, "BalloonAtt");

                //將最後一顆泡泡的數字插入零件中
                workPart.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString());
            }
            //保留泡泡
            else
            {
                #region 存DicDimenData(string=檢具名稱,DimenData=尺寸物件、泡泡座標)
                DefineParam.DicDimenData = new Dictionary <string, List <DimenData> >();
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();

                    if (i == 0)
                    {
                        DefineParam.FirstDrawingSheet = CurrentSheet;
                    }

                    //取得圖紙長、高
                    SheetLength = CurrentSheet.Length;
                    SheetHeight = CurrentSheet.Height;

                    //DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects();
                    NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        //判斷是否取到舊的尺寸,如果是就跳下一個
                        string OldBallonNum = "";
                        try
                        {
                            OldBallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum);
                            continue;
                        }
                        catch (System.Exception ex) {  }

                        //判斷是否有屬性,沒有屬性就跳下一個
                        string Gauge = "", AssignExcelType = "";
                        try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.AssignExcelType); }
                        catch (System.Exception ex) { continue; }

                        try { Gauge = singleObj.GetStringAttribute(CaxME.DimenAttr.Gauge); }
                        catch (System.Exception ex) { }

                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        //string DimeType = "";
                        //DimeType = singleObj.GetType().ToString();
                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();

                        //GetTextBoxCoordinate(DimeType, singleObj, out cBoxCoordinate);
                        //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[0].ToString());
                        CaxME.GetTextBoxCoordinate(((NXOpen.Annotations.Annotation)singleObj).Tag, out cBoxCoordinate);
                        //CaxLog.ShowListingWindow(cBoxCoordinate.lower_left[0].ToString());
                        #region 計算泡泡座標
                        DimenData sDimenData = new DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        Functions.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        if (Gauge != "")
                        {
                            List <DimenData> ListDimenData = new List <DimenData>();
                            status = DefineParam.DicDimenData.TryGetValue(Gauge, out ListDimenData);
                            if (!status)
                            {
                                ListDimenData = new List <DimenData>();
                            }
                            ListDimenData.Add(sDimenData);
                            DefineParam.DicDimenData[Gauge] = ListDimenData;
                        }
                    }
                }
                #endregion

                if (DefineParam.DicDimenData.Count != 0)
                {
                    //插入泡泡
                    InsertBallon(ref MaxBallonNum, cCoordinateData, SheetHeight, SheetLength, "BalloonAtt");

                    //將最後一顆泡泡的數字插入零件中
                    workPart.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString());
                }
            }

            //切回第一張Sheet
            DefineParam.FirstDrawingSheet.Open();

            MessageBox.Show("完成");
            theProgram.Dispose();
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----
            CaxLog.ShowListingWindow(ex.ToString());
        }
        return(retValue);
    }
Example #17
0
 void CreateEACT_ISOMETRICView(NXOpen.Drawings.DrawingSheet ds, List <NXOpen.TaggedObject> selections, Snap.Position pos, Snap.Position size, EdmDraw.EdmConfig edmConfig)
 {
     var view = EdmDraw.DrawBusiness.CreateBaseView(ds, GetModelingView(EdmDraw.ViewType.EACT_ISOMETRIC).Tag, selections, pos, size, edmConfig);
 }
        private void OK_Click(object sender, EventArgs e)
        {
            //抓取目前圖紙數量和Tag
            int SheetCount = 0;

            NXOpen.Tag[] SheetTagAry = null;
            theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
            //取得最後一顆泡泡的數字
            int MaxBallonNum;

            try
            {
                MaxBallonNum = Convert.ToInt32(workPart.GetStringAttribute(CaxME.DimenAttr.BallonNum));
            }
            catch (System.Exception ex)
            {
                MaxBallonNum = 0;
            }

            if (chb_Regeneration.Checked == true)
            {
                #region 刪除全部泡泡
                IdSymbolCollection BallonCollection = workPart.Annotations.IdSymbols;
                IdSymbol[]         BallonAry        = BallonCollection.ToArray();
                foreach (IdSymbol i in BallonAry)
                {
                    try
                    {
                        i.GetStringAttribute("BalloonAtt");
                    }
                    catch (System.Exception ex)
                    {
                        continue;
                    }
                    CaxPublic.DelectObject(i);
                }
                workPart.DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, "BALLONNUM");
                #endregion

                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();
                    if (i == 0)
                    {
                        Variables.FirstDrawingSheet = CurrentSheet;
                    }

                    int        BallonNum = 0;
                    NXObject[] SheetObj  = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        string diCount = "", fixDiemnsion = "";
                        #region 刪除尺寸數量產生的文字(ex:a-c)
                        try
                        {
                            diCount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount);
                        }
                        catch (System.Exception ex)
                        {
                            diCount = "";
                        }
                        try
                        {
                            fixDiemnsion = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension);
                        }
                        catch (System.Exception ex)
                        {
                            fixDiemnsion = "";
                        }
                        if (diCount != "" && fixDiemnsion == "")
                        {
                            CaxPublic.DelectObject(singleObj);
                        }
                        #endregion

                        string AssignExcelType = "";
                        #region 判斷是否有屬性,沒有屬性就跳下一個
                        try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension); }
                        catch (System.Exception ex) { continue; }
                        #endregion


                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();
                        CaxME.GetTextBoxCoordinate(singleObj.Tag, out cBoxCoordinate);

                        #region 計算泡泡座標
                        CaxME.DimenData sDimenData = new CaxME.DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        CaxME.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        sDimenData.CurrentSheet.Open();

                        Point3d BallonLocation = new Point3d();
                        BallonLocation.X = sDimenData.LocationX;
                        BallonLocation.Y = sDimenData.LocationY;

                        BallonNum++;
                        InsertBalloon(BallonNum, diCount, BallonLocation);
                        singleObj.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString());
                    }


                    //將最後一顆泡泡的數字插入零件中
                    workPart.SetAttribute(CaxME.DimenAttr.BallonNum, BallonNum.ToString());
                }
            }
            else if (chb_keepOrigination.Checked == true)
            {
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();
                    if (i == 0)
                    {
                        Variables.FirstDrawingSheet = CurrentSheet;
                    }

                    NXObject[] SheetObj = CaxME.FindObjectsInView(CurrentSheet.View.Tag).ToArray();
                    foreach (NXObject singleObj in SheetObj)
                    {
                        //判斷是否取到舊的尺寸,如果是就跳下一個
                        string OldBallonNum = "";
                        try
                        {
                            OldBallonNum = singleObj.GetStringAttribute(CaxME.DimenAttr.BallonNum);
                            continue;
                        }
                        catch (System.Exception ex) { }

                        string AssignExcelType = "";
                        #region 判斷是否有屬性,沒有屬性就跳下一個
                        try { AssignExcelType = singleObj.GetStringAttribute(CaxME.DimenAttr.FixDimension); }
                        catch (System.Exception ex) { continue; }
                        #endregion

                        //事先塞入該尺寸所在Sheet
                        singleObj.SetAttribute("SheetName", CurrentSheet.Name);

                        CaxME.BoxCoordinate cBoxCoordinate = new CaxME.BoxCoordinate();
                        CaxME.GetTextBoxCoordinate(singleObj.Tag, out cBoxCoordinate);

                        #region 計算泡泡座標
                        CaxME.DimenData sDimenData = new CaxME.DimenData();
                        sDimenData.Obj          = singleObj;
                        sDimenData.CurrentSheet = CurrentSheet;
                        CaxME.CalculateBallonCoordinate(cBoxCoordinate, ref sDimenData);
                        #endregion

                        sDimenData.CurrentSheet.Open();

                        Point3d BallonLocation = new Point3d();
                        BallonLocation.X = sDimenData.LocationX;
                        BallonLocation.Y = sDimenData.LocationY;

                        MaxBallonNum++;
                        string diCount = "";
                        try
                        {
                            diCount = singleObj.GetStringAttribute(CaxME.DimenAttr.DiCount);
                        }
                        catch (System.Exception ex)
                        {
                            diCount = "1";
                        }

                        InsertBalloon(MaxBallonNum, diCount, BallonLocation);
                        singleObj.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString());
                    }
                    //將最後一顆泡泡的數字插入零件中
                    workPart.SetAttribute(CaxME.DimenAttr.BallonNum, MaxBallonNum.ToString());
                }
            }
            else if (chb_UserDefine.Checked == true)
            {
                //判斷所有的泡泡是否有重複
                List <string> ListIsRepeat = new List <string>();
                foreach (GridRow i in SGC.PrimaryGrid.Rows)
                {
                    if (i.Cells["自定泡泡號"].Value.ToString() == "")
                    {
                        continue;
                    }
                    if (ListIsRepeat.Contains(i.Cells["自定泡泡號"].Value.ToString()))
                    {
                        MessageBox.Show("泡泡號【" + i.Cells["自定泡泡號"].Value.ToString() + "】重複,請重新檢查");
                        return;
                    }
                    else
                    {
                        ListIsRepeat.Add(i.Cells["自定泡泡號"].Value.ToString());
                    }
                }
                CoordinateData cCoordinateData = new CoordinateData();
                CaxGetDatData.GetDraftingCoordinateData(out cCoordinateData);

                //開始插入自定義泡泡
                foreach (GridRow i in SGC.PrimaryGrid.Rows)
                {
                    //判斷是否有舊的泡泡,如果舊泡泡與自定的相同,則跳下一個
                    //判斷是否有舊的泡泡,如果舊泡泡與自定的不相同,則先刪除泡泡再重新產生
                    //如有Dicount也要加入一起生成


                    //如果沒有自定泡泡就跳下一個row
                    if (i.Cells["自定泡泡號"].Value.ToString() == "")
                    {
                        //判斷是否需刪除已存在的泡泡
                        NXOpen.Drawings.DrawingSheet drawingSheet1 = (NXOpen.Drawings.DrawingSheet)workPart.DrawingSheets.FindObject(i.Cells["尺寸位置"].Value.ToString());
                        string oldBalloon = "";
                        try
                        {
                            oldBalloon = ((NXObject)i.Cells["Dimension"].Value).GetStringAttribute(CaxME.DimenAttr.BallonNum);
                        }
                        catch (System.Exception ex)
                        {
                            continue;
                        }
                        NXObject[] SheetObj = CaxME.FindObjectsInView(drawingSheet1.View.Tag).ToArray();
                        CaxME.DeleteBallon(oldBalloon, SheetObj);
                        workPart.Views.Refresh();
                        //刪除屬性
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonNum);
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.BallonLocation);
                        ((NXObject)i.Cells["Dimension"].Value).DeleteAttributeByTypeAndTitle(NXObject.AttributeType.String, CaxME.DimenAttr.SheetName);
                        continue;
                    }
                    //如果回傳False,表示舊泡泡=自定泡泡;如果回傳True,表示舊泡泡=\=自定泡泡
                    if (!JudgmentBalloon(i))
                    {
                        continue;
                    }
                    InsertBalloon(i, cCoordinateData);
                }
                if (exOnj != null)
                {
                    exOnj.Unhighlight();
                    workPart.Views.Refresh();
                }
            }

            MessageBox.Show("完成!");
        }
Example #19
0
    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);
    }
        private void Upload_Click(object sender, EventArgs e)
        {
            try
            {
                int          SheetCount  = 0;
                NXOpen.Tag[] SheetTagAry = null;
                theUfSession.Draw.AskDrawings(out SheetCount, out SheetTagAry);
                //判斷是否需要出PDF
                List <DrawingSheet> drawingSheets = new List <DrawingSheet>();
                for (int j = 0; j < SheetCount; j++)
                {
                    drawingSheets.Add((DrawingSheet)NXObjectManager.Get(SheetTagAry[j]));
                }
                if (this.ExportPDF.Checked)
                {
                    if (!Directory.Exists(this.L_Folder))
                    {
                        Directory.CreateDirectory(this.L_Folder);
                    }
                    string str1 = string.Format(@"{0}\{1}.pdf", this.L_Folder, Path.GetFileNameWithoutExtension(FixInsUploadDlg.displayPart.FullPath));
                    CaxME.CreateOISPDF(drawingSheets, str1);

                    //傳OIS圖到SERVER
                    if (!Directory.Exists(S_Folder))
                    {
                        System.IO.Directory.CreateDirectory(S_Folder);
                    }
                    CaxPublic.DirectoryCopy(this.L_Folder, S_Folder, true);
                }
                //取得WorkPart資訊並檢查資料是否完整
                DadDimension.WorkPartAttribute sWorkPartAttribute = new DadDimension.WorkPartAttribute();
                status = DadDimension.GetWorkPartAttribute(workPart, out sWorkPartAttribute);
                if (!status)
                {
                    if (this.ExportPDF.Checked)
                    {
                        MessageBox.Show("量測資訊不足,僅上傳PDF檔案,上傳完成!");
                    }
                    else
                    {
                        MessageBox.Show("量測資訊不足,無法上傳資料!");
                    }
                    this.Close();
                    return;
                }
                //if (sWorkPartAttribute.draftingVer == "" || sWorkPartAttribute.draftingDate == "" ||
                //    sWorkPartAttribute.partDescription == "" || sWorkPartAttribute.material == "")
                //{
                //    MessageBox.Show("量測資訊不足");
                //    this.Close();
                //    return;
                //}

                //取得所有量測尺寸資料

                List <DadDimension> listDimensionData = new List <DadDimension>();
                for (int i = 0; i < SheetCount; i++)
                {
                    //打開Sheet並記錄所有OBJ
                    NXOpen.Drawings.DrawingSheet CurrentSheet = (NXOpen.Drawings.DrawingSheet)NXObjectManager.Get(SheetTagAry[i]);
                    CurrentSheet.Open();
                    CurrentSheet.View.UpdateDisplay();
                    DisplayableObject[] SheetObj = CurrentSheet.View.AskVisibleObjects();
                    status = Com_FixDimension.RecordFixDimension(SheetObj, sWorkPartAttribute, ref listDimensionData);
                    if (!status)
                    {
                        this.Close();
                        return;
                    }
                }

                //將圖片存到本機Globaltek內
                for (int i = 0; i < PicNameStr.Length; i++)
                {
                    string destFileName = string.Format(@"{0}\{1}", this.L_Folder, PicNameStr[i]);
                    File.Copy(PicPathStr[i], destFileName, true);
                }



                //由料號查Com_PEMain
                Com_PEMain cCom_PEMain = new Com_PEMain();
                status = CaxSQL.GetCom_PEMain(cCaxUpLoad.CusName, cCaxUpLoad.PartName, cCaxUpLoad.CusRev, cCaxUpLoad.OpRev, out cCom_PEMain);
                if (!status)
                {
                    return;
                }
                //由Com_PEMain和Op查Com_PartOperation
                Com_PartOperation cCom_PartOperation = new Com_PartOperation();
                status = CaxSQL.GetCom_PartOperation(cCom_PEMain, cCaxUpLoad.OpNum, out cCom_PartOperation);
                if (!status)
                {
                    return;
                }

                #region 比對資料庫FixInspection是否有同筆數據
                bool Is_Exit = true;
                Com_FixInspection cCom_FixInspection = new Com_FixInspection();
                CaxSQL.GetCom_FixInspection(cCom_PartOperation, Path.GetFileNameWithoutExtension(workPart.FullPath), out cCom_FixInspection);
                if (cCom_FixInspection == null)
                {
                    Is_Exit = false;
                }

                if (Is_Exit && eTaskDialogResult.Yes == CaxPublic.ShowMsgYesNo("此檢、治具已存在上一筆資料,是否更新?"))
                {
                    #region 刪除Com_FixDimension
                    IList <Com_FixDimension> listComFixDimension = new List <Com_FixDimension>();
                    CaxSQL.GetListCom_FixDimension(cCom_FixInspection, out listComFixDimension);
                    foreach (Com_FixDimension i in listComFixDimension)
                    {
                        CaxSQL.Delete <Com_FixDimension>(i);
                    }
                    #endregion
                    #region 刪除Com_FixInspection
                    CaxSQL.Delete <Com_FixInspection>(cCom_FixInspection);
                    #endregion
                    Is_Exit = false;
                }

                if (!Is_Exit)
                {
                    cCom_FixInspection = new Com_FixInspection()
                    {
                        comPartOperation  = cCom_PartOperation,
                        fixinsDescription = this.Desc.Text,
                        fixinsERP         = this.ERPNo.Text,
                        fixinsNo          = this.FixInsNo.Text,
                        fixPicPath        = this.S_PicPath,
                        fixPartName       = Path.GetFileNameWithoutExtension(FixInsUploadDlg.workPart.FullPath)
                    };

                    IList <Com_FixDimension> listCom_FixDimension = new List <Com_FixDimension>();
                    foreach (DadDimension i in listDimensionData)
                    {
                        //Com_FixDimension cCom_FixDimension = new Com_FixDimension()
                        //{
                        //    comFixInspection = comFixInspection
                        //};
                        ////cCom_FixDimension.comFixInspection = comFixInspection;

                        //CaxME.MappingData(i, ref cCom_FixDimension);
                        //listCom_FixDimension.Add(cCom_FixDimension);
                        Com_FixDimension cCom_FixDimension = new Com_FixDimension();
                        cCom_FixDimension.MappingData(i);
                        cCom_FixDimension.comFixInspection = cCom_FixInspection;
                        listCom_FixDimension.Add(cCom_FixDimension);
                    }
                    cCom_FixInspection.comFixDimension = listCom_FixDimension;

                    CaxSQL.Save <Com_FixInspection>(cCom_FixInspection);

                    //傳OIS圖到SERVER
                    if (!Directory.Exists(S_Folder))
                    {
                        System.IO.Directory.CreateDirectory(S_Folder);
                    }
                    CaxPublic.DirectoryCopy(this.L_Folder, S_Folder, true);
                }

                #endregion

                MessageBox.Show("上傳完成");
                base.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }