Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

scaling dimensions

Status
Not open for further replies.

moog3

Marine/Ocean
Nov 29, 2022
63
Can someone please show me how to add an input box into this journal.
I've used a journal I found in this thread thread561-489980 and modified it with my drafting preferences.
I'd like to have an input box show up when you run the journal, it asks "enter scale value"
then it'll multiply the "TEXTSIZE" value by this amount and run the rest of the code.

It's so I can make BIG dimensions, then switch back to standard size. IE, x10, & x1 to get back to standard.
I can easily create buttons of specific scale values, but would prefer a single button , such as this.

here's the code...

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

' ----------------------------------------------
' modified by me to scale dimensions
' to get another text style use these numbers
'
'arial=1 blockfont=2 full_leroy=3 leroy=4 arial unicode MS=5 helios=6 arial=7 tahoma=8 Nx ANSII Symbols=9
'ideas_century=10 High_tower_text=11 ideas_din=12 ideas_helvetica=13 ideas_iges_1002=14 ideas_korean=15 ideas_prc=16
'aurira_lt=61 ballfont=62 agency FB=63 AMGDT=66 franklin gothic book=93 helios_con_lt=98
'
' Menu: Preferences->Drafting...
' ----------------------------------------------
'alter TEXTSIZE to scale dimension
Dim TEXTSIZE = 2.75
Dim TEXTSIZEHALF = TEXTSIZE/2.2
Dim FONTNUMBER = 98



Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim preferencesBuilder1 As NXOpen.Drafting.PreferencesBuilder = Nothing
preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder()

preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextSize = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextSize = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LineArrowStyle.ArrowheadLength = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LineArrowStyle.TextOverStubFactor = TEXTSIZE/55
preferencesBuilder1.AnnotationStyle.LineArrowStyle.StubLength = TEXTSIZE*1.0909090909090909090909090909091
preferencesBuilder1.AnnotationStyle.LineArrowStyle.TextToLineDistance = TEXTSIZEHALF

preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstPosToExtensionLineDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondPosToExtensionLineDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.LinePastArrowDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.DatumLengthPastArrow = TEXTSIZEHALF*2.4
preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextSize = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LetteringStyle.TwoLineToleranceTextSize = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextSize = TEXTSIZE


Dim nXObject1 As NXObject
nXObject1 = preferencesBuilder1.Commit()
theSession.SetUndoMarkName(markId1, "Drafting Preferences")
preferencesBuilder1.Destroy()

' ----------------------------------------------

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim preferencesBuilder2 As NXOpen.Drafting.PreferencesBuilder = Nothing
preferencesBuilder2 = workPart.SettingsManager.CreatePreferencesBuilder()

Dim fontIndex1 As Integer = Nothing

'preferencesBuilder2.AnnotationStyle.LetteringStyle.GeneralTextFont = FONTNUMBER

Dim fontIndex2 As Integer = Nothing

preferencesBuilder2.AnnotationStyle.LetteringStyle.DimensionTextFont = FONTNUMBER

Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = preferencesBuilder2.Commit()
theSession.SetUndoMarkName(markId2, "Drafting Preferences")
preferencesBuilder2.Destroy()

End Sub
End Module

Any help, much appreciated...
 
Replies continue below

Recommended for you

I've added the user input box from NXjournalising, and I've managed to get both parts of the journal to work along side each other, but don't know how to pass the value obtained from the input box, down into a scale value to use in the code.
I must be fairly close, can someone show me how, or share a sample journal, that I can use, to see how its done..
My code, is below..

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim theUISession As UI = UI.GetUI
Dim answer As String = ""
Dim myInt As Integer
Dim myNumber As Double

'answer = NXInputBox.GetInputString("prompt", "title bar caption", "initial text")
'MsgBox("answer: """ & answer & """")

'loop until there is valid input
'Do
'answer = NXInputBox.GetInputString("Enter your name", "Name?", " ")
'if cancel is pressed, exit sub
'If answer = "" Then Exit Sub
'Loop Until answer.Trim.Length > 0

'theUISession.NXMessageBox.Show("Greetings", NXMessageBox.DialogType.Information, "Hello, " & answer)

'loop until there is valid input
'Do
'answer = NXInputBox.GetInputString("Enter an integer", "Number of copies?", " ")
'if cancel is pressed, exit sub
'If answer = "" Then Exit Sub
'Loop Until Integer.TryParse(answer, myInt)

'theUISession.NXMessageBox.Show("Valid input", NXMessageBox.DialogType.Information, "The input was successfully parsed as: " & myInt.ToString)

'loop until there is valid input
Do
answer = NXInputBox.GetInputString("SCALE VALUE", "DIMENSION SIZE", "1")
'if cancel is pressed, exit sub
If answer = "" Then Exit Sub
Loop Until Double.TryParse(answer, myNumber)

theUISession.NXMessageBox.Show("Valid input", NXMessageBox.DialogType.Information, "The input was successfully parsed as: " & myNumber.ToString)

Scale()

End Sub

'Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

'End Function

'End Module

'========================================================================
'Option Strict Off
'Imports System
'Imports NXOpen

'Module NXJournal
'Public Sub Scale(ByVal args() As String)
'Sub (ByVal args() As String)
Public Sub Scale()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

' ----------------------------------------------
' modified by me to scale dimensions
' to get another text style use these numbers
'
'arial=1 blockfont=2 full_leroy=3 leroy=4 arial unicode MS=5 helios=6 arial=7 tahoma=8 Nx ANSII Symbols=9
'ideas_century=10 High_tower_text=11 ideas_din=12 ideas_helvetica=13 ideas_iges_1002=14 ideas_korean=15 ideas_prc=16
'aurira_lt=61 ballfont=62 agency FB=63 AMGDT=66 franklin gothic book=93 helios_con_lt=98
'
' Menu: Preferences->Drafting...
' ----------------------------------------------
'alter TEXTSIZE to scale dimension
Dim myInt
Dim myNumber
Dim SIZE = 10
'Dim SIZE = myNumber
'Dim SIZE = myInt
'Dim TEXTSIZE =SIZE*myNumber
Dim TEXTSIZE = 2.75*SIZE

Dim TEXTSIZEHALF = TEXTSIZE/2.2
Dim FONTNUMBER = 98



Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim preferencesBuilder1 As NXOpen.Drafting.PreferencesBuilder = Nothing
preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder()

preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextSize = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextSize = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LineArrowStyle.ArrowheadLength = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LineArrowStyle.TextOverStubFactor = TEXTSIZE/55
preferencesBuilder1.AnnotationStyle.LineArrowStyle.StubLength = TEXTSIZE*1.0909090909090909090909090909091
preferencesBuilder1.AnnotationStyle.LineArrowStyle.TextToLineDistance = TEXTSIZEHALF

preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstPosToExtensionLineDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondPosToExtensionLineDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.LinePastArrowDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.DatumLengthPastArrow = TEXTSIZEHALF*2.4
preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextSize = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LetteringStyle.TwoLineToleranceTextSize = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextSize = TEXTSIZE


Dim nXObject1 As NXObject
nXObject1 = preferencesBuilder1.Commit()
theSession.SetUndoMarkName(markId1, "Drafting Preferences")
preferencesBuilder1.Destroy()

' ----------------------------------------------

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim preferencesBuilder2 As NXOpen.Drafting.PreferencesBuilder = Nothing
preferencesBuilder2 = workPart.SettingsManager.CreatePreferencesBuilder()

Dim fontIndex1 As Integer = Nothing

'preferencesBuilder2.AnnotationStyle.LetteringStyle.GeneralTextFont = FONTNUMBER

Dim fontIndex2 As Integer = Nothing

preferencesBuilder2.AnnotationStyle.LetteringStyle.DimensionTextFont = FONTNUMBER

Dim nXObject2 As NXOpen.NXObject = Nothing
theSession.SetUndoMarkName(markId2, "Drafting Preferences")
preferencesBuilder2.Destroy()

End Sub
End Module
 
Code:
Sub Main()
    'other code
    'Define value, or get it from user
    Dim myScaleValue as Double = 3.14
    'here we pass in the value of an existing variable
    Scale(myScaleValue)
    'or pass in a value directly:
    Scale(2.718)
End Sub

Public Sub Scale(byval scaleValue as Double)
    Dim TEXTSIZE = 2.75 * scaleValue
    'other code
End Sub

When you create a function or subroutine, you can accept a parameter to be passed into the function/sub. In the code above, when we call the "Scale" sub, we MUST pass in a double value to the sub. You can pass in an existing variable or a literal value. In the definition of the "Scale" sub above, the value passed in will be a local variable in the sub named "scaleValue". We can now use this value in the sub as needed. Note that all the variables above are "local" variables, which means that they only have a value in the function or sub where they are defined; the "Scale" sub cannot access the "myScaleValue" variable directly as it belongs to the Sub Main.

www.nxjournaling.com
 
Thanks very much for your help, it now works perfectly..
here's the code for anyone who wants it...
what I want it for, is if you want to place dimensions on an iso view, in drafting, you expand the view, orient your WCS to a face, then place dimensions, but depending on the view scale, the dimensions are usually too small...
This journal fixes that, and running it again, without an input, will set it back again..
CODE.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim theUISession As UI = UI.GetUI
Dim answer As String = ""
Dim myInt As Integer
Dim myNumber As Double


Do
answer = NXInputBox.GetInputString("SCALE VALUE", "DIMENSION SIZE", "1")
'if cancel is pressed, exit sub
If answer = "" Then Exit Sub
Loop Until Double.TryParse(answer, myNumber)

theUISession.NXMessageBox.Show("PREFERENCES, DRAFTING", NXMessageBox.DialogType.Information, "DIMENSIONS SCALED BY x" & myNumber.ToString)

Dim myScaleValue=myNumber

Scale(myScaleValue)

End Sub


Public Sub Scale(byval scaleValue as Double)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

' ----------------------------------------------
' modified by me to scale dimensions
' to get another text style use these numbers
'
'arial=1 blockfont=2 full_leroy=3 leroy=4 arial unicode MS=5 helios=6 arial=7 tahoma=8 Nx ANSII Symbols=9
'ideas_century=10 High_tower_text=11 ideas_din=12 ideas_helvetica=13 ideas_iges_1002=14 ideas_korean=15 ideas_prc=16
'aurira_lt=61 ballfont=62 agency FB=63 AMGDT=66 franklin gothic book=93 helios_con_lt=98
'
' Menu: Preferences->Drafting...
' ----------------------------------------------
'alter TEXTSIZE to scale dimension

Dim TEXTSIZE = 2.75*scaleValue

Dim TEXTSIZEHALF = TEXTSIZE/2.2
Dim FONTNUMBER = 98



Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim preferencesBuilder1 As NXOpen.Drafting.PreferencesBuilder = Nothing
preferencesBuilder1 = workPart.SettingsManager.CreatePreferencesBuilder()

preferencesBuilder1.AnnotationStyle.LetteringStyle.DimensionTextSize = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LetteringStyle.GeneralTextSize = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LineArrowStyle.ArrowheadLength = TEXTSIZE
preferencesBuilder1.AnnotationStyle.LineArrowStyle.TextOverStubFactor = TEXTSIZE/55
preferencesBuilder1.AnnotationStyle.LineArrowStyle.StubLength = TEXTSIZE*1.0909090909090909090909090909091
preferencesBuilder1.AnnotationStyle.LineArrowStyle.TextToLineDistance = TEXTSIZEHALF

preferencesBuilder1.AnnotationStyle.LineArrowStyle.FirstPosToExtensionLineDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.SecondPosToExtensionLineDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.LinePastArrowDistance = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LineArrowStyle.DatumLengthPastArrow = TEXTSIZEHALF*2.4
preferencesBuilder1.AnnotationStyle.LetteringStyle.ToleranceTextSize = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LetteringStyle.TwoLineToleranceTextSize = TEXTSIZEHALF
preferencesBuilder1.AnnotationStyle.LetteringStyle.AppendedTextSize = TEXTSIZE


Dim nXObject1 As NXObject
nXObject1 = preferencesBuilder1.Commit()
theSession.SetUndoMarkName(markId1, "Drafting Preferences")
preferencesBuilder1.Destroy()

' ----------------------------------------------

Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
Dim preferencesBuilder2 As NXOpen.Drafting.PreferencesBuilder = Nothing
preferencesBuilder2 = workPart.SettingsManager.CreatePreferencesBuilder()

Dim fontIndex1 As Integer = Nothing

'preferencesBuilder2.AnnotationStyle.LetteringStyle.GeneralTextFont = FONTNUMBER

Dim fontIndex2 As Integer = Nothing

preferencesBuilder2.AnnotationStyle.LetteringStyle.DimensionTextFont = FONTNUMBER

Dim nXObject2 As NXOpen.NXObject = Nothing
theSession.SetUndoMarkName(markId2, "Drafting Preferences")
preferencesBuilder2.Destroy()

End Sub
End Module
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor