Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Tabular Note -- Error while applying Cell Preferences

Hi,

I was trying to set the cell preferences to a Tab Note and it is giving me error as below

 


{"Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout."}


Code:

UFTabnot.CellPrefs cellPrefs = default(UFTabnot.CellPrefs);
cellPrefs.text_height = 2.5;
cellPrefs.horiz_just = UFTabnot.Just.JustCenter;
cellPrefs.vert_just = UFTabnot.Just.JustCenter;
cellPrefs.text_aspect_ratio = 1.0;
cellPrefs.line_space_factor = 5.0;
cellPrefs.char_space_factor = 1.0;
cellPrefs.format = UFTabnot.Format.FormatText;
cellPrefs.text_density = 3;
int[] arrLineColorFont = new int[] { 1, 1, 1 };
cellPrefs.bottom_line_cfw = arrLineColorFont;
cellPrefs.right_line_cfw = arrLineColorFont
cellPrefs.nm_fit_methods = 1;
//cellPrefs.fit_methods = new UFTabnot.FitMethod[] { UFTabnot.FitMethod.FitMethodAutoSizeCol };
cellPrefs.fit_methods = new UFTabnot.FitMethod[] { UFTabnot.FitMethod.FitMethodAutoSizeCol };

tagOfCell = GetCellTag(tagTable, iRowNo - 1,iColNo - 1);
Set_CellText(tagOfCell, "Sl No");
Set_CellPref(tagOfCell, cellPrefs);

private void Set_CellText(Tag tagCell, string sCellTextToSet)
{
UFSession.GetUFSession().Tabnot.SetCellText(tagCell, sCellTextToSet);
}
private void Set_CellPref(Tag tagCell, UFTabnot.CellPrefs structCellPreferences)
{
UFSession.GetUFSession().Tabnot.SetCellPrefs(tagCell, structCellPreferences);
}
private Tag GetCellTag(Tag tabOfTable, int iRowNumber, int iColumnNumber)
{
Tag tagRow, tagCol, tagCell;
UFSession theUfSession = UFSession.GetUFSession();
theUfSession.Tabnot.AskNthRow(tabOfTable, iRowNumber, out tagRow);
theUfSession.Tabnot.AskNthColumn(tabOfTable, iColumnNumber, out tagCol);
theUfSession.Tabnot.AskCellAtRowCol(tagRow, tagCol, out tagCell);
return tagCell;
}
 

 

 

I just could not able to identify the error root cause.

Can some body sujjest me where i'm getting it wrong.

 

Regards,

Maddy

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4
3 REPLIES

Re: Tabular Note -- Error while applying Cell Preferences

The complete Code is Follows::

 

using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Assemblies;
using NXOpen.Drafting;
using NXOpen.Drawings;
using NXOpen.UIStyler;

public class Program
{
    // class members
    public static Program theProgram;
    public static bool isDisposeCalled;

    public static Session theSession = null;
    public static UFSession theUFSession = null;
    // Constructor 
    public Program()
    {
        try
        {
            theSession = Session.GetSession();
            theUFSession = UFSession.GetUFSession();
            isDisposeCalled = false;
        }
        catch (NXOpen.NXException ex)
        {
            // UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
        }
    }

    public static int Main(string[] args)
    {
        int retValue = 0;
        try
        {
            theProgram = new Program();
            theProgram.Test_Method();
            theProgram.Dispose();
        }
        catch (NXOpen.NXException ex)
        {

        }
        return retValue;
    }
     
    public void Dispose()
    {
        try
        {
            if (isDisposeCalled == false)
            {
            }
            isDisposeCalled = true;
        }
        catch (NXOpen.NXException ex)
        {
            // ---- Enter your exception handling code here -----

        }
    }

    public static int GetUnloadOption(string arg)
    {
        return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
    }



    private void Test_Method()
    {

        int iAttributeIndex = 0;
        double dActualTablePos = 0; 
        int no_Of_Columns = 0;
        int no_Of_Rows = 0;
        Tag tagTableCreated = Tag.Null;

        DrawingSheet currentDrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet; 

        double dSheet_Height = currentDrawingSheet.Height;
        double dSheet_Width = currentDrawingSheet.Length; 

        double[] tableOrigin = new double[]
		{
			dSheet_Width - dActualTablePos,
			dSheet_Height - dActualTablePos,
			0.0
		}; 
		
        UFTabnot.SectionPrefs tableSectionPrefs = default(UFTabnot.SectionPrefs);
        tableSectionPrefs.header_location = UFTabnot.HeaderLocation.HeaderLocationBelow;
        tableSectionPrefs.attach_point = UFTabnot.AttachPoint.AttachPointTopRight;
        tableSectionPrefs.border_width = 6.0;
        tableSectionPrefs.max_height = 1000.0;
        tableSectionPrefs.use_double_width_border = false;
        tableSectionPrefs.overflow_direction = UFTabnot.OverflowDirection.OverflowLeft;
        tableSectionPrefs.overflow_spacing = 6.0;

        theUFSession.Tabnot.Create(ref tableSectionPrefs, tableOrigin, out tagTableCreated);

        UFTabnot.CellPrefs cellPrefs = default(UFTabnot.CellPrefs);
        cellPrefs.text_height = 2.5;
        cellPrefs.horiz_just = UFTabnot.Just.JustCenter;
        cellPrefs.vert_just = UFTabnot.Just.JustCenter;
        cellPrefs.text_aspect_ratio = 1.0;
        cellPrefs.line_space_factor = 5.0;
        cellPrefs.char_space_factor = 1.0;
        cellPrefs.format = UFTabnot.Format.FormatText;
        cellPrefs.text_density = 3;

        int[] arr_ColorFontWidth_Of_BorderLine = new int[]  
		{
			1,
			1,
			1
		};
        cellPrefs.bottom_line_cfw = arr_ColorFontWidth_Of_BorderLine;
        cellPrefs.right_line_cfw = arr_ColorFontWidth_Of_BorderLine;

        cellPrefs.nm_fit_methods = 1;
        cellPrefs.fit_methods = new UFTabnot.FitMethod[] 
        { 
            UFTabnot.FitMethod.FitMethodAutoSizeCol
        }; 


        theUFSession.Tabnot.AskNmColumns(tagTableCreated, out no_Of_Columns);
        theUFSession.Tabnot.AskNmRows(tagTableCreated, out no_Of_Rows);

        Tag tagRow = Tag.Null;
        Tag tagCol = Tag.Null;
        Tag tagOfCell = Tag.Null;

        //   this 
        // tagOfCell = GetCellTag(tag_Of_Point_Table, 0,0);

        //   OR this 
        theUFSession.Tabnot.AskNthRow(tagTableCreated, 0, out tagRow);
        theUFSession.Tabnot.AskNthColumn(tagTableCreated, 0, out tagCol);
        theUFSession.Tabnot.AskCellAtRowCol(tagRow, tagCol, out tagOfCell);
        theUFSession.Tabnot.SetCellText(tagOfCell, "Test");

        theUFSession.Tabnot.SetCellPrefs(tagOfCell, ref cellPrefs);

    }
 

	private void Set_CellText(Tag tagCell, string sCellTextToSet)
	{
		UFSession.GetUFSession().Tabnot.SetCellText(tagCell, sCellTextToSet);
	}
	private void Set_CellPref(Tag tagCell, UFTabnot.CellPrefs structCellPreferences)
	{
		UFSession.GetUFSession().Tabnot.SetCellPrefs(tagCell, structCellPreferences);
	}
	private Tag GetCellTag(Tag tabOfTable, int iRowNumber, int iColumnNumber)
	{
		Tag tagRow, tagCol, tagCell;
		UFSession theUfSession = UFSession.GetUFSession();
		theUfSession.Tabnot.AskNthRow(tabOfTable, iRowNumber, out tagRow);
		theUfSession.Tabnot.AskNthColumn(tabOfTable, iColumnNumber, out tagCol);
		theUfSession.Tabnot.AskCellAtRowCol(tagRow, tagCol, out tagCell); 
		return tagCell;
	}

}

can some body suggest me what is wrong in here?

 

Regards,

Maddy

 

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4
Solution
Solution
Accepted by topic author Maddy
‎08-26-2015 04:32 AM

Re: Tabular Note -- Error while applying Cell Preferences

Try starting with the default cell preferences fit values array and customize it to your liking.

 

In my testing, it seems that you'll want to list your desired fit methods in order of application in the array then tell it to use the first "n" fit methods that you have specified.

 

Some code might explain it better; the following is in VB format, but it should be easy enough to convert over to your language of choice.

 

Dim arrLineColorFont() As Integer = {1, 1, 1}
'start with the default values
Dim fitMethods() As UFTabnot.FitMethod = theCellPrefs.fit_methods
'list desired fit methods in desired order of application.
'first desired fit method:
fitMethods(0) = UFTabnot.FitMethod.FitMethodAutoSizeCol
'second desired fit method:
fitMethods(1) = UFTabnot.FitMethod.FitMethodAutoSizeRow
'third desired fit method:
fitMethods(2) = UFTabnot.FitMethod.FitMethodAutoSizeText
'etc...

With theCellPrefs
    .text_height = 0.125
    .horiz_just = UFTabnot.Just.JustCenter
    .vert_just = UFTabnot.Just.JustCenter
    .text_aspect_ratio = 1
    .line_space_factor = 5
    .char_space_factor = 1
    .format = UFTabnot.Format.FormatText
    .text_density = 3
    .bottom_line_cfw = arrLineColorFont
    .right_line_cfw = arrLineColorFont
    'how many of the fit methods to use
    .nm_fit_methods = 1
    .fit_methods = fitMethods

End With


'apply the new settings to the cell
theUfSession.Tabnot.SetCellPrefs(cellTag, theCellPrefs)

After running the code, check the cell "fit methods" preferences. "Auto size column" should be at the top of the list and the only one active.

Re: Tabular Note -- Error while applying Cell Preferences

Thanks Cowski,

 

I was actually referring to an old source code available and tried to test.

In that old code it is workign absoultely without any error.

So i tried in the same way.

 

As you suggested to use default cell preferences, so i tried by asking the cell preferences to check out the Fit Methods array size and it was 8, So now i changed the fitmethods array size to 8, defined values and it is working fine.

 

 

Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4