cancel
Showing results for 
Search instead for 
Did you mean: 

Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Innovator
Innovator

Hello all,

 

I am attempting to retireve certain metadata from Note objects in a part via a console C# application in NX 9.0.3.4 MP3, but all my attempts have failed, as these have thrown Memory Access Violation exceptions (or similar). The metadata which I'm trying to retrieve is: Text size (size), alignment (AlignmentPosition), and the font index (Cfw.Font).

 

This is what I've tried so far:

  • EditSettingsBuilder (Part.SettingsManager.CreateAnnotationSettingsBuilder)
    The program crashes when attempting to create the settings builder.
  • DraftingNoteBuilder (Part.Annotations.CreateDraftingNoteBuilder)
    The program crashes when attempting to create the drafting note builder.

  • AskObjectPreferences (UFDrf.AskObjectPreferences)
    The program crashes when this method is called.
  • LetteringPreferences (Note.GetLetteringPrefences())
    The program crashes when attempting to retrieve the lettering preferences.

Has anyone else had this issue? Is this a known issue (I haven't located anything in GTAC)? Is there a workaround?

 

Any help is much appreciated, thank you!

Marc Prosl
NX Software Developer
8 REPLIES

Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Esteemed Contributor
Esteemed Contributor

I do have a function to create a note, which sets some of the note properties, may be it can help to decipher the way of getting the properties.

 

    Private Function MakeNote(PosX As Double, PosY As Double, Text() As String, TextHeight As Double, TextAngle As Double, _
        AlignPos As Annotations.AlignmentPosition, Color As String) As Tag
        
        Dim wPart As Part = theSession.Parts.Work
        Dim cNote As Annotations.Note
        Dim mAnnot As Annotations.AnnotationManager = wPart.Annotations
        Dim lPrefs As Annotations.LetteringPreferences = mAnnot.Preferences.GetLetteringPreferences
        Dim usPrefs As Annotations.UserSymbolPreferences = _
            mAnnot.NewUserSymbolPreferences(Annotations.UserSymbolPreferences.SizeType.ScaleAspectRatio, 1, 1)
        Dim pOrigin As New Point3d
        Dim gText As Annotations.Lettering
        Dim cFont As FontCollection = wPart.Fonts
        Dim iColor As Integer
        
        lPrefs.AlignmentPosition = AlignPos
        lPrefs.Angle = TextAngle
        lPrefs.HorizTextJust = Annotations.TextJustification.Left
        
        gText = lPrefs.GetGeneralText
        
        Select Case Color.ToLower
            Case "green"
                gText.Cfw.Width = Annotations.LineWidth.Thin
                theUFSession.Disp.AskClosestColorInDisplayedPart(UF.UFDisp.ColorName.GreenName,iColor)
            Case "orange"
                gText.Cfw.Width = Annotations.LineWidth.Normal
                theUFSession.Disp.AskClosestColorInDisplayedPart(UF.UFDisp.ColorName.OrangeOrangeRedName,iColor)
            Case "yellow"
                gText.Cfw.Width = Annotations.LineWidth.Thick
                theUFSession.Disp.AskClosestColorInDisplayedPart(UF.UFDisp.ColorName.YellowName,iColor)
        End Select
        
        gText.Cfw.Color = iColor
        gText.Size = TextHeight
        gText.Cfw.Font = cFont.AddFont("latin_extended")
        
        lPrefs.SetGeneralText(gText)
        
        pOrigin.X = PosX
        pOrigin.Y = PosY
        pOrigin.Z = 0
        
        cNote = mAnnot.CreateNote(Text, pOrigin, AxisOrientation.Horizontal, lPrefs, usPrefs)
        
        Return cNote.Tag
    End Function

 

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Esteemed Contributor
Esteemed Contributor

Does the object need to be "displayed" to get this data?

 

I was dealing with some drafting stuff recently, and getting errors, only to realize I was trying to do something with a "displayable object"  after I had a "UF_CALL(UF_DISP_set_display(UF_DISP_SUPPRESS_DISPLAY));" 

 

When I moved the code after a "UF_CALL(UF_DISP_set_display(UF_DISP_UNSUPPRESS_DISPLAY));", it worked much better :-)

 

Maybe try to move the code to a function, and try to call that function in a DLL used in an interactcive session.  Once it works there, then see if it works in "batch"?

 

Ken

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Honored Contributor
Honored Contributor

If you run a program in batch mode with no NX GUI, NX *should* still write to a log file. Run your program, then check the temp directory for the latest syslog file; perhaps it will provide some clues.

 

Beyond that, I agree with Ken. Get it working in interactive mode, then try it with batch mode.

Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Innovator
Innovator

Hi everyone,

 

Thank you for all your inputs.

The code which I had originally tried in batch works fine in interactive mode (retrieving the lettering preferences), but still crashes in batch mode.

 

Possible scenarios:

1) The part is somewhat corrupt, and a part-cleanup might have to be executed before trying again in batch.

2) This is actually a bug in the API.

Marc Prosl
NX Software Developer

Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Esteemed Contributor
Esteemed Contributor

Try this

- Take your interactive code (that works)

- add a call to UF_DISP_set_display(UF_DISP_SUPPRESS_DISP​LAY) before you try getting the note settings

- does it now have similar issues?

 

I'm thinking it requires the display to be active.

 

Now whether that is a bug or a "feechur", that is up to you to decide ;-)

 

Ken "bugs are just features that have not yet been discovered by the marketing department" Akerboom

 

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Valued Contributor
Valued Contributor

HI,

 

UF_DISP_set_display(UF_DISP_SUPPRESS_DISPLAY) function is only for internal envirnoment (DLL).

 

Please try the below steps

- Take the code which is working fine in interactive mode.

- Remove the function UF_DISP_set_display(UF_DISP_SUPPRESS_DISPLAY) from all the places

- Compile and run in batch mode.

 

Please try this.

 

Thanks,

Shivaji

Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Esteemed Contributor
Esteemed Contributor

Shivaji -

Note I said to take the INTERACTIVE version that works (NOT the batch one) and modify to see if the suppressed display is the issue.

 

Not that I'm 100% sure this is the issue, but it is something *I* would test

Ken

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Attempting to retrieve LetterPreferences from a Note in a console C# program causes exception

Siemens Phenom Siemens Phenom
Siemens Phenom

 

The attached code worked for me, both using run_journal and as an x64 .EXE.  It is VB but the classes should work the same way in C#.