Esempio n. 1
0
        public static void UpdateTabularNote(NXOpen.Tag tag)
        {
            int numberColumns, numberRows;

            _ufSession.Tabnot.AskNmColumns(tag, out numberColumns);
            _ufSession.Tabnot.AskNmRows(tag, out numberRows);
            for (int i = 0; i < numberColumns; i++)
            {
                NXOpen.Tag columnTag;
                _ufSession.Tabnot.AskNthColumn(tag, i, out columnTag);
                for (int j = 0; j < numberRows; j++)
                {
                    NXOpen.Tag rowTag;
                    _ufSession.Tabnot.AskNthRow(tag, j, out rowTag);
                    NXOpen.Tag cellTag;
                    _ufSession.Tabnot.AskCellAtRowCol(rowTag, columnTag, out cellTag);
                    var cellPrefs = new NXOpen.UF.UFTabnot.CellPrefs();
                    _ufSession.Tabnot.AskCellPrefs(cellTag, out cellPrefs);
                    cellPrefs.zero_display = NXOpen.UF.UFTabnot.ZeroDisplay.ZeroDisplayZero;// UF_TABNOT_zero_display_zero;
                    cellPrefs.text_density = 3;
                    _ufSession.Tabnot.SetCellPrefs(cellTag, ref cellPrefs);
                }
            }
            _ufSession.Draw.UpdateTabnot(tag);
            _ufSession.Tabnot.Update(tag);
        }
Esempio n. 2
0
        /// <summary>
        /// 创建表格
        /// </summary>
        public static NXOpen.Tag CreateTabnot(Snap.Position origin, int rowCount, int columnCount, double rowHeight, double columnWidth, EdmConfig edmConfig)
        {
            var workPart     = Snap.Globals.WorkPart.NXOpenPart;
            var theUFSession = NXOpen.UF.UFSession.GetUFSession();
            var tableParam   = new NXOpen.UF.UFDraw.TabnotParams();

            //设置单元格默认样式
            NXOpen.UF.UFTabnot.CellPrefs cellPrefs = new NXOpen.UF.UFTabnot.CellPrefs();
            theUFSession.Tabnot.AskDefaultCellPrefs(out cellPrefs);
            cellPrefs.nm_fit_methods = 2;
            cellPrefs.fit_methods[0] = NXOpen.UF.UFTabnot.FitMethod.FitMethodAutoSizeText; //UF_TABNOT_fit_method_auto_size_text;
            cellPrefs.fit_methods[1] = NXOpen.UF.UFTabnot.FitMethod.FitMethodAutoSizeRow;  //UF_TABNOT_fit_method_auto_size_row;
            cellPrefs.text_density   = 3;
            cellPrefs.zero_display   = NXOpen.UF.UFTabnot.ZeroDisplay.ZeroDisplayZero;
            theUFSession.Tabnot.SetDefaultCellPrefs(ref cellPrefs);

            //创建的表格信息
            tableParam.position        = new double[3];
            tableParam.position[0]     = origin.X;
            tableParam.position[1]     = origin.Y;
            tableParam.position[2]     = origin.Z;
            tableParam.range_start.row = 1;
            tableParam.range_start.col = 1;
            tableParam.range_end.row   = rowCount;
            tableParam.range_end.col   = columnCount;

            //标题;
            tableParam.title_cell.row = 0;

            //标题;
            tableParam.title_cell.col  = 0;
            tableParam.ug_aspect_ratio = 1.0;
            tableParam.border_type     = NXOpen.UF.UFDraw.TabnotBorderType.TabnotBorderTypeSingle;
            tableParam.border_width    = 0;

            //标题;
            tableParam.use_title_cell = false;

            //网络线使用;
            tableParam.use_grid_lines         = true;
            tableParam.use_vert_grid_lines    = true;
            tableParam.use_horiz_grid_lines   = true;
            tableParam.use_row_hdr_grid_lines = true;
            tableParam.use_col_hdr_grid_lines = true;
            tableParam.auto_size_cells        = false;

            NXOpen.Tag tabularNote = NXOpen.Tag.Null;
            theUFSession.Draw.CreateTabularNote(ref tableParam, out tabularNote);

            //设置列宽
            for (int i = 0; i < columnCount; i++)
            {
                DraftingHelper.SetTabularColumnWidth(i, columnWidth, tabularNote);
            }

            //设置行高
            for (int i = 0; i < rowCount; i++)
            {
                DraftingHelper.SetTabularRowHeight(i, rowHeight, tabularNote);
            }

            return(tabularNote);

            //var tabnot=theUFSession.Tabnot;
            //var section_prefs = new NXOpen.UF.UFTabnot.SectionPrefs();
            //theUFSession.Tabnot.AskDefaultSectionPrefs(out section_prefs);
            //section_prefs.border_width = 60;
            //var tabular_note = NXOpen.Tag.Null;
            //theUFSession.Tabnot.Create(ref section_prefs, origin.Array, out tabular_note);

            //var tabel=NXOpen.Utilities.NXObjectManager.Get(tabular_note) as NXOpen.Annotations.Table;
            //var tableSectionBuilder1 = workPart.Annotations.TableSections.CreateTableSectionBuilder(null);
            //tableSectionBuilder1.NumberOfRows = rowCount;
            //tableSectionBuilder1.NumberOfColumns = columnCount;
            //tableSectionBuilder1.ColumnWidth = columnWidth;
            //tableSectionBuilder1.RowHeight = rowHeight;
            //tableSectionBuilder1.Origin.OriginPoint = origin;
            //tableSectionBuilder1.Commit();
            //tableSectionBuilder1.Destroy();
        }