Below journal which show the scale of view in drawings as scale factory (e.g.1, 0.5, 0.1). I would like to show scale of view as RATIO (e.g. 1:1, 2:1; 1:10 ...)
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "Module1"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim exportScale As String
Dim ScaleNumerator As double
Dim ScaleDenominator as double
Dim sheet As NXOpen.Drawings.DrawingSheet
For Each sheet In workPart.DrawingSheets
exportScale = sheet.GetDraftingViews(0).Style.General.Scale
lw.writeline(" Scale: " & exportScale)
lw.writeline("Number of views on sheet: " & sheet.SheetDraftingViews.ToArray.Length)
sheet.GetScale(ScaleNumerator, ScaleDenominator)
lw.writeline("Scale of the drawing sheet: " & ScaleNumerator & ":" & ScaleDenominator)
Next
For Each shtView As Drawings.DraftingView In sheet.SheetDraftingViews
lw.WriteLine(" View name: " & shtView.Name)
lw.WriteLine(" Method no. 2 - Scale: " & shtView.Style.General.Scale)
Next
lw.Close()
End Sub
'***********************************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
I recorded my journal and tried something like this (according to NXOpen.Net reference guide):
For Each Scala1 As Drawings.EditViewSettingsBuilder In Drafting.SettingsManager.CreateDrawingEditViewSettingsBuilder
lw.writeline("Scala: " & Scala1.ViewStyle.ViewStyleGeneral.Scale.ScaleType.Ratio)
Next
I'm not sure how to correctly define a group "Drafting.SettingsManager.CreateDrawingEditViewSettingsBuilder()". I tried "workpart.Drafting.SettingsManager.CreateDrawingEditViewSettingsBuilder()" but I do not want to guess I would like to be aware of these.
Could You help me how to show Scale of Drafting View as Ratio?
I use NX 10
Thanks
Marcin
Scale view in Drafting
I solved my issue by function "if" as shown on below. Does anyone know a "shorter way" to do the same?
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const undoMarkName As String = "Module1"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim exportScale As String
Dim ScaleNumerator As double
Dim ScaleDenominator as double
Dim sheet As NXOpen.Drawings.DrawingSheet
Dim Numerator As double
Dim Denominator as double
For Each sheet In workPart.DrawingSheets
exportScale = sheet.GetDraftingViews(0).Style.General.Scale
if exportScale >= 1 then
Numerator = exportScale
Denominator = 1
'lw.writeline("SCALE: " & Numerator & " : " & Denominator )
else
Numerator = 1
Denominator = 1/exportScale
'lw.writeline("SCALE: " & Numerator & " : " & Denominator )
end if
'lw.writeline(" Scale: " & exportScale)
lw.writeline("SCALE: " & Numerator & " : " & Denominator)
lw.writeline("Number of views on sheet: " & sheet.SheetDraftingViews.ToArray.Length)
sheet.GetScale(ScaleNumerator, ScaleDenominator)
lw.writeline("Scale of the drawing sheet: " & ScaleNumerator & ":" & ScaleDenominator)
Next
For Each shtView As Drawings.DraftingView In sheet.SheetDraftingViews
lw.WriteLine(" View name: " & shtView.Name)
lw.WriteLine(" Scale of view: " & shtView.Style.General.Scale)
Next
lw.Close()
End Sub
'***********************************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
re: drafting view scale
The "numerator" and "denominator" are not stored for drafting views, only the scale factor. What you have is probably about a simple as it gets. If you do a websearch for "convert double to fraction" (or "convert double to rational number", or something similar), you will get various methods to convert decimal values to proper fractions.