Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

A new NX9 JOURNAL question

Status
Not open for further replies.

Kenja824

Automotive
Joined
Nov 5, 2014
Messages
958
Location
US
I have a Journal that fixes a bunch of Drafting Settings for us. I tested it on four different computers and it worked perfect, so I sent out an email for everyone to go ahead and use it. Shortly after, someone told me it changed the font to "NX ANSI Symbols" when it is set up to change it to "Leroy". My guess was that that computer might need an update to a patch or something, but then the next day, it happened to me. Right now I have a file in Team Center that if I run it, the Font will change to Leroy, as it should. But if I go to one of the new details I created for this file and run the Journal, it changes the font to the NX Ansi Symbols.

Why would it change it to Leroy on some files (Possibly only older files) but to NX Ansi Symbols on other files (Possibly newly created files)?
 
Are you referring back to thread561-374824?

If so, it appears that the font was added to the NX file, but the journal doesn't tell NX where to use the font. The following code snippet adds the "leroy" font and sets it as the default for dimension text, appended text, tolerance text, and general text. Note that it will set the default for new notes and dimensions, it will not change the font of existing notes or dimensions.

Code:
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = workPart.Annotations.Preferences.GetLetteringPreferences()

Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)

Dim dimensionText1 As Annotations.Lettering
dimensionText1.Cfw.Font = fontIndex1
letteringPreferences1.SetDimensionText(dimensionText1)

Dim appendedText1 As Annotations.Lettering
appendedText1.Cfw.Font = fontIndex1
letteringPreferences1.SetAppendedText(appendedText1)

Dim toleranceText1 As Annotations.Lettering
toleranceText1.Cfw.Font = fontIndex1
letteringPreferences1.SetToleranceText(toleranceText1)

Dim generalText1 As Annotations.Lettering
generalText1.Cfw.Font = fontIndex1
letteringPreferences1.SetGeneralText(generalText1)

workPart.Annotations.Preferences.SetLetteringPreferences(letteringPreferences1)

letteringPreferences1.Dispose()

www.nxjournaling.com
 
While trying to figure it out for myself, I found something strange. The code I had was this....


preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextFont = 3

preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextFont = 3

preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextFont = 3

In the assembly, which was created in the past, it made the text for all three places "Leroy". But in the two details I created to add to this assembly, it would change the text to the NX Ansi Symbols. So just out of curiosity to see what it would give me, I changed one of them to a 4 then ran it. It gave me Leroy on both files. So I changed them all to 4 and it seems to give Leroy to both the old and new files. I dont understand why. Was I extremely lucky to just use the number that fixed it?

Either way, I am thinking I would be better served to use the code you gave me in the long run. lol But I would be curious to what your thoughts are on why the number 4 seemed to fix it.
 
The .AddFont method adds the specified font to the NX part and returns the integer associated to the font. The integer value represents the position in the part's font table it can be different between parts; the leroy font may have an index of 4 in one part and 12 in another. I recorded a journal that changed the font for dimension text, the result is below (some code removed for clarity).

Code:
Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)

' Font is associated with integer 4
Dim dimensionText1 As Annotations.Lettering
dimensionText1.Cfw[highlight #FCE94F].Font = 4[/highlight]
letteringPreferences1.SetDimensionText(dimensionText1)

This is a case where the journal recorder isn't doing you a favor. In this case, the .AddFont method returned the value "4". Instead of using the fontIndex1 variable in the font definition, it uses the literal value of "4". When we run this code on another part, it will assign whatever font has the index of "4" to the dimension text; this may be the leroy font (if we are lucky), but probably will not be.

www.nxjournaling.com
 
I added your code and got the attached error.

Here is your code with a little of what I already have on it to show where I placed it.

-----------------------------------------------------------------------
preferencesBuilder1.AnnotationStyle.HoleCalloutSettings.SetLeaderAttachment(Annotations.HoleCalloutSettingsBuilder.LeaderAttachment.Top)

'dim fontIndex2 As Integer
'fontIndex2 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)
preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextSize = 2.5
preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextSize = 2.5
preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextSize = 2.5

Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = workPart.Annotations.Preferences.GetLetteringPreferences()

Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)

Dim dimensionText1 As Annotations.Lettering
dimensionText1.Cfw.Font = fontIndex1
letteringPreferences1.SetDimensionText(dimensionText1)

Dim appendedText1 As Annotations.Lettering
appendedText1.Cfw.Font = fontIndex1
letteringPreferences1.SetAppendedText(appendedText1)

Dim toleranceText1 As Annotations.Lettering
toleranceText1.Cfw.Font = fontIndex1
letteringPreferences1.SetToleranceText(toleranceText1)

Dim generalText1 As Annotations.Lettering
generalText1.Cfw.Font = fontIndex1
letteringPreferences1.SetGeneralText(generalText1)

workPart.Annotations.Preferences.SetLetteringPreferences(letteringPreferences1)

letteringPreferences1.Dispose()

Dim nXObject1 As NXObject
nXObject1 = preferencesBuilder1.Commit()

theSession.SetUndoMarkName(markId1, "Drafting Preferences")

preferencesBuilder1.Destroy()
 
 http://files.engineering.com/getfile.aspx?folder=180a03c0-706a-4858-93bb-dc63479029c2&file=Journal-font_error.JPG
In my example, I deleted some lines to emphasize what was happening with the font index number. You will need to supply valid values for the other font properties (size, aspect ratio, color, etc) before "setting" the style.

Code:
Dim dimensionText1 As Annotations.Lettering
dimensionText1.Size = 0.125
dimensionText1.CharacterSpaceFactor = 1.0
dimensionText1.AspectRatio = 1.0
dimensionText1.LineSpaceFactor = 1.0
dimensionText1.Cfw.Color = 216
dimensionText1.Cfw.Font = fontIndex1
dimensionText1.Cfw.Width = Annotations.LineWidth.Thin
dimensionText1.Italic = False
letteringPreferences1.SetDimensionText(dimensionText1)

www.nxjournaling.com
 
Well I am thinking I am messing up something and putting myself further away. So I attached the Journal I am testing it with for you to look over, if you will. You will notive I did not add the spaces to the beginning of the newer stuff.

With the fixes I did, the Journal now runs through without an error, but its not changing anything. I went in and set the font to something strange, made the height 3.5 and changed the aspect ratio to 4 just to see if it put everthing to how it should be. Not one item changed back to the correct information.

Again, I do appreciate the help. I know it might become aggrivating to try to teach someone so much over the internet like this. lol
 
 http://files.engineering.com/getfile.aspx?folder=2e20c6c3-7f82-4c9e-98a0-d665a1f3ce35&file=Setup_-_Copy.vb
My fault, I forgot you were using NX 9; I'm currently using 8.5, all my examples were from that version. NX 9 does this a little differently, your code should look something like:

Code:
Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)

preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextFont = fontIndex1

You'll need to add that in after the preferencesBuilder1 object is created and before the changes are committed.

www.nxjournaling.com
 
Well, I am just not winning today. lol think I did what you said, and it changes the font to Leroy, but none of the other preferences take. The text height, etc... Here is my latest version of the journal. Did I place it in the wrong spot?
 
 http://files.engineering.com/getfile.aspx?folder=38cbc81c-36af-4ce7-a185-61486f54b7be&file=Setup_-_Copy.vb
I apologize for misleading you with NX 8.5 code snippets, please ignore the code in the post dated: 17 Nov 14 10:32. NX 9 does it differently. If all you want to do is change the default font, not the size or style, the following should work in NX 9:

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal

    Sub Main(ByVal args() As String)

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

        Dim preferencesBuilder1 As Drafting.PreferencesBuilder
        preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder()

        preferencesBuilder1.ViewStyle.ViewStyleGeneral.Silhouettes = True

        preferencesBuilder1.ViewStyle.ViewStyleGeneral.Centerlines = False

        'find closest NX color in display part color table
        'Iron Gray (R,G,B) = 76, 76, 76
        Dim colorValues(2) As Double
        colorValues(0) = 76 / 255
        colorValues(1) = 76 / 255
        colorValues(2) = 76 / 255

        Dim closeColor As Integer
        theUfSession.Disp.AskClosestColor(UFConstants.UF_DISP_rgb_model, colorValues, UFConstants.UF_DISP_CCM_EUCLIDEAN_DISTANCE, closeColor)

        Dim myBorderColor As NXColor
        myBorderColor = workPart.Colors.Find(closeColor)

        'preferencesBuilder1.ViewWorkflow.BorderColor = workPart.Colors.Find("Iron Gray")
        preferencesBuilder1.ViewWorkflow.BorderColor = myBorderColor

        preferencesBuilder1.ViewStyle.ViewStyleVisibleLines.VisibleColor = workPart.Colors.Find(-1)

        preferencesBuilder1.ViewStyle.ViewStyleVisibleLines.VisibleColor = workPart.Colors.Find("Background")

        preferencesBuilder1.ViewStyle.ViewStyleHiddenLines.Color = workPart.Colors.Find(-1)

        preferencesBuilder1.ViewStyle.ViewStyleHiddenLines.Color = workPart.Colors.Find("Background")

        preferencesBuilder1.ViewStyle.ViewStyleHiddenLines.EdgesHiddenByEdges = True

        preferencesBuilder1.ViewStyle.ViewStyleSmoothEdges.Color = workPart.Colors.Find(-1)

        preferencesBuilder1.ViewStyle.ViewStyleSmoothEdges.Color = workPart.Colors.Find("Background")

        preferencesBuilder1.ViewStyle.ViewStyleSmoothEdges.SmoothEdge = False

        preferencesBuilder1.ViewStyle.ViewProjectedViewSettings.DisplayArrowOnParentView = Drawings.ViewProjectedViewSettingsBuilder.DisplayArrowOnParentViewType.No

        preferencesBuilder1.ViewStyle.ViewStyleSection.SheetBodies = True

        preferencesBuilder1.ViewStyle.ViewStyleSection.Background = True
        
        preferencesBuilder1.AnnotationStyle.UnitsStyle.DisplayTrailingZeros = False

        preferencesBuilder1.AnnotationStyle.DimensionStyle.ChamferSeparator = Annotations.ChamferSeparatorType.UppercaseX

        preferencesBuilder1.AnnotationStyle.DimensionStyle.LineBetweenArrows = False

        preferencesBuilder1.AnnotationStyle.OrdinateStyle.PositiveDirection = Annotations.OrdinatePositiveDirection.UpperRight

        preferencesBuilder1.AnnotationStyle.OrdinateStyle.DisplayNameStyle = Annotations.OrdinateOriginDisplayOption.NoText

        preferencesBuilder1.AnnotationStyle.OrdinateStyle.OrdinateTextOrientation = Annotations.TextOrientation.Aligned

        preferencesBuilder1.AnnotationStyle.OrdinateStyle.DoglegAngle = 1.13446401379631

        preferencesBuilder1.AnnotationStyle.HoleCalloutSettings.SetLeaderAttachment(Annotations.HoleCalloutSettingsBuilder.LeaderAttachment.Top)



Dim fontIndex1 As Integer
fontIndex1 = workPart.Fonts.AddFont("leroy", FontCollection.Type.Nx)


preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextFont = fontIndex1
preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextFont = fontIndex1


        Dim nXObject1 As NXObject
        nXObject1 = preferencesBuilder1.Commit()

        theSession.SetUndoMarkName(markId1, "Drafting Preferences")

        preferencesBuilder1.Destroy()

' ----------------------------------------------
'   Menu: Edit->Sheet...
' ----------------------------------------------

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim drawingSheet1 As Drawings.DrawingSheet = CType(workPart.DrawingSheets.FindObject("SHT1"), Drawings.DrawingSheet)

Dim drawingSheetBuilder1 As Drawings.DrawingSheetBuilder
drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(drawingSheet1)

drawingSheetBuilder1.ProjectionAngle = Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third

Dim nXObject2 As NXObject
nXObject2 = drawingSheetBuilder1.Commit()

theSession.SetUndoMarkName(markId4, "Sheet")

drawingSheetBuilder1.Destroy()

End Sub
End Module

www.nxjournaling.com
 
No apologees needed. You have helped me far more than I was expecting when I first posted about Journal code.
I did want to set the sizes and such too, but that was easy to figure out once I figured out what was happening. Hopefully this journal is set with what I need.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top