Changing Sheet Sizes Automatically to Customer Size

We have two different sizes for each sheet (B,C,D,E). One for our company and one for our customer. The size of the sheet is different so we need to change the sheet size before plotting etc. For example our C size is 16 x 41.5 and our customer C size is 18.5 x 24.5, We need an easy way for it to recognize our company sheet sizes and change the sheet to our customer sizes. And vice versa. Can this be done by expressions? I haven't been successful have the Sheet Height and Length allowing expressions in a journal. Any suggestions appreciate. Thanks in advance!

Can you provide more information on what you are trying to do? I don't understand why you need to change the sheet size before you plot. The plot settings in NX should read your sheet dimensions and plot accordingly, no? It seems to me that you would only need to create some sheet templates, something like "C - our company" and "C - customer" and use the proper one when creating the drawing.

To the best of my knowledge, expressions cannot be associated to the dimensions of a drawing sheet, i.e. the expression values cannot drive or be driven by the sheet dimensions.

We do have templates for our customer and for us. We use different layers in our templates to produce a customer print and our company print that has everything else (views, dims, etc) the same on the print. We have a custom program to generate plots and pdfs and other exports. The designer will need to jump back and forth quickly between the "C" sizes of the sheets. So I found a journal to read the sheet size and create expressions. Then I created IF Then Else expressions to change to the other sheet sizes. But when I create a journal or macro to edit the sheet to the new values by entering the name of the new expression, it does not record the entry of the expression name, just records the new value of the expression. I need to be able to enter expression names for the height and length of the drawing sheet. I only know how to create journals from NX not but creating it using code. Any help appreciated.

AngieL

Can you post the code that you currently have?
If I'm reading this correctly, it sounds like you want a sort of toggle function where the journal will read the current size of the sheet, determine that it is (for example) your "company C size", then change the size of the sheet to "customer C size" and vice versa. Is this correct?

I used the following vb to create expressions for the SheetHeight and SheetLength.

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 lw As ListingWindow = theSession.ListingWindow
lw.Open()

Const undoMarkName As String = "sheet size expressions"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

'lw.WriteLine("base unit of length: " & workPart.UnitCollection.GetBase("length").Abbreviation)

Dim sheetLength As Double
Dim sheetHeight As Double

Dim unit1 As Unit = workPart.UnitCollection.GetBase("length")

For Each tempSheet As Drawings.DrawingSheet In workPart.DrawingSheets
If tempSheet.Units = Drawings.DrawingSheet.Unit.Inches Then
unit1 = CType(workPart.UnitCollection.FindObject("Inch"), Unit)
Else
unit1 = CType(workPart.UnitCollection.FindObject("MilliMeter"), Unit)
End If
sheetLength = tempSheet.Length
sheetHeight = tempSheet.Height
Exit For
Next

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Expression")

Try
'look for existing expression and update it
Dim expression1 As Expression = CType(workPart.Expressions.FindObject("SheetHeight"), Expression)

workPart.Expressions.EditWithUnits(expression1, unit1, sheetHeight.ToString)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Catch ex As NXException

If ex.ErrorCode = 3520016 Then
'expression does not exist, create it
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateWithUnits("SheetHeight=" & sheetHeight.ToString, unit1)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Else
theSession.UndoToMark(markId1, undoMarkName)
MsgBox(ex.ErrorCode & ": " & ex.Message)

End If

End Try

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Expression")

Try
'look for existing expression and update it
Dim expression1 As Expression = CType(workPart.Expressions.FindObject("SheetLength"), Expression)

workPart.Expressions.EditWithUnits(expression1, unit1, sheetLength.ToString)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId3)

Catch ex As NXException

If ex.ErrorCode = 3520016 Then
'expression does not exist, create it
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateWithUnits("SheetLength=" & sheetLength.ToString, unit1)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId3)

Else
'unexpected error, undo all changes made by journal
theSession.UndoToMark(markId1, undoMarkName)
MsgBox(ex.ErrorCode & ": " & ex.Message)

End If

End Try

lw.Close()

End Sub

End Module

Then I created new expressions. Thinking that I could use them to change the sheet size to what it needs to be.

DWG_HEIGHT=IF (SheetHeight=10.25) THEN (12.5) ELSE IF (SheetHeight=16) THEN (18.5) ELSE IF (SheetHeight=23.5) THEN (24.5) ELSE IF (SheetHeight=41.5) THEN (36.5) ELSE IF (SheetHeight=12.5) THEN (10.25) ELSE IF (SheetHeight=18.5) THEN (16) ELSE IF (SheetHeight=24.5) THEN (23.5) ELSE (41.5)

DWG_LENGTH=IF (SheetLength=16.25) THEN (18.5) ELSE IF (SheetLength=40.5) THEN (24.5) ELSE IF (SheetLength=41.5) THEN (36.5) ELSE IF (SheetLength=59.5) THEN (48.5) ELSE IF (SheetLength=18.5) THEN (16.25) ELSE IF (SheetLength=24.5) THEN (40.5) ELSE IF (SheetLength=36.5) THEN (41.5) ELSE (59.5)

But the record journal with NX doesn't remember the expression name when entered.

Not sure if this is the easiest way to toggle between the sizes or not.
Here are the sheet sizes that we need to toggle back and forth between.

CUSTOMER SHEET SIZES OUR COMPANY SHEET SIZES
B 12.5 X 18.5 10.25 X 16.25
C 18.5 X 24.5 16 X 41.25
D 24.5 X 36.5 23.5 X 41.5
E 36.5 X 48.5 41.5 X 59.5

Hope this helps explains what we are trying to do. Thanks for the help.

AngieL

Yes that is what I am looking for.

AngieL

Try the following journal:

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

If IsNothing(theSession.Parts.Display) Then
'no part open
Return
End If

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "toggle sheet size")

lw.Open()

Dim sheetSizeList As New List(Of SheetSizes)
'... New SheetSizes(Length1, Height1, Length2, Height2)
Dim Bsize As New SheetSizes(16.25, 10.25, 18.5, 12.5)
Dim Csize As New SheetSizes(41.25, 16, 24.5, 18.5)
Dim Dsize As New SheetSizes(41.5, 23.5, 36.5, 24.5)
Dim Esize As New SheetSizes(59.5, 41.5, 48.5, 36.5)
sheetSizeList.Add(Bsize)
sheetSizeList.Add(Csize)
sheetSizeList.Add(Dsize)
sheetSizeList.Add(Esize)

Const sizeTolerance As Double = 0.1
Dim sizeFound As Boolean = False

Dim currentSheetLength As Double = theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet.Length
Dim currentSheetHeight As Double = theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet.Height

'lw.WriteLine("currentSheetLength: " & currentSheetLength.ToString)
'lw.WriteLine("currentSheetHeight: " & currentSheetHeight.ToString)
'lw.WriteLine("")

For Each tempSheetSize As SheetSizes In sheetSizeList

'lw.WriteLine("company sheet length: " & tempSheetSize.CompanySheetLength.ToString)
'lw.WriteLine("company sheet height: " & tempSheetSize.CompanySheetHeight.ToString)
'lw.WriteLine("")
'lw.WriteLine("customer sheet length: " & tempSheetSize.CustomerSheetLength.ToString)
'lw.WriteLine("customer sheet height: " & tempSheetSize.CustomerSheetHeight.ToString)
'lw.WriteLine("")

If Math.Abs(currentSheetLength - tempSheetSize.CompanySheetLength) < sizeTolerance AndAlso Math.Abs(currentSheetHeight - tempSheetSize.CompanySheetHeight) < sizeTolerance Then
'current sheet matches company size
'change sheet to customer size
sizeFound = True
ChangeSheetSize(theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet, tempSheetSize.CustomerSheetLength, tempSheetSize.CustomerSheetHeight)
Exit For
End If

If Math.Abs(currentSheetLength - tempSheetSize.CustomerSheetLength) < sizeTolerance AndAlso Math.Abs(currentSheetHeight - tempSheetSize.CustomerSheetHeight) < sizeTolerance Then
'current sheet matches customer size
'change sheet to company size
sizeFound = True
ChangeSheetSize(theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet, tempSheetSize.CompanySheetLength, tempSheetSize.CompanySheetHeight)
Exit For
End If

Next

If Not sizeFound Then
lw.WriteLine("the current drawing sheet size does not match known sheet sizes")
End If

lw.Close()

End Sub

Sub ChangeSheetSize(ByVal theSheet As Drawings.DraftingDrawingSheet, ByVal newLength As Double, ByVal newHeight As Double)

Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "ChangeSheetSize")

Dim draftingDrawingSheetBuilder1 As NXOpen.Drawings.DraftingDrawingSheetBuilder = Nothing
draftingDrawingSheetBuilder1 = theSession.Parts.Work.DraftingDrawingSheets.CreateDraftingDrawingSheetBuilder(theSheet)

draftingDrawingSheetBuilder1.Option = NXOpen.Drawings.DrawingSheetBuilder.SheetOption.CustomSize

draftingDrawingSheetBuilder1.Height = newHeight

draftingDrawingSheetBuilder1.Length = newLength

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Sheet")

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = draftingDrawingSheetBuilder1.Commit()

theSession.DeleteUndoMark(markId3, Nothing)

draftingDrawingSheetBuilder1.Destroy()

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

Public Class SheetSizes

Private _customerSheetLength As Double
Public ReadOnly Property CustomerSheetLength() As Double
Get
Return _customerSheetLength
End Get
End Property

Private _customerSheetHeight As Double
Public ReadOnly Property CustomerSheetHeight() As Double
Get
Return _customerSheetHeight
End Get
End Property

Private _companySheetLength As Double
Public ReadOnly Property CompanySheetLength() As Double
Get
Return _companySheetLength
End Get
End Property

Private _companySheetHeight As Double
Public ReadOnly Property CompanySheetHeight() As Double
Get
Return _companySheetHeight
End Get
End Property

Public Sub New(ByVal companySheetLength As Double,
ByVal companySheetHeight As Double,
ByVal customerSheetLength As Double,
ByVal customerSheetHeight As Double)

_companySheetLength = companySheetLength
_companySheetHeight = companySheetHeight
_customerSheetLength = customerSheetLength
_customerSheetHeight = customerSheetHeight

End Sub

End Class

I believe is works perfect! Thank you so much! Definitely more simple route than what I was taking. I need to learn more about code.

So would it be easy to switch layers depending on whether it is a "customer" or "company" sheet? The customer would show only layers 1,250,253,256 and the company would show only 1,250,251,253. Thanks again! Much Appreciated!

AngieL

Try this version:

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

If IsNothing(theSession.Parts.Display) Then
'no part open
Return
End If

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "toggle sheet size")

lw.Open()

Dim sheetSizeList As New List(Of SheetSizes)
'... New SheetSizes(Length1, Height1, Length2, Height2)
Dim Bsize As New SheetSizes(16.25, 10.25, 18.5, 12.5)
Dim Csize As New SheetSizes(41.25, 16, 24.5, 18.5)
Dim Dsize As New SheetSizes(41.5, 23.5, 36.5, 24.5)
Dim Esize As New SheetSizes(59.5, 41.5, 48.5, 36.5)
sheetSizeList.Add(Bsize)
sheetSizeList.Add(Csize)
sheetSizeList.Add(Dsize)
sheetSizeList.Add(Esize)

Dim companyLayerList As New List(Of Integer)
companyLayerList.AddRange(New Integer() {1, 250, 251, 253})
Dim customerLayerList As New List(Of Integer)
customerLayerList.AddRange(New Integer() {1, 250, 253, 256})

Const sizeTolerance As Double = 0.1
Dim sizeFound As Boolean = False

Dim currentSheetLength As Double = theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet.Length
Dim currentSheetHeight As Double = theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet.Height

'lw.WriteLine("currentSheetLength: " & currentSheetLength.ToString)
'lw.WriteLine("currentSheetHeight: " & currentSheetHeight.ToString)
'lw.WriteLine("")

For Each tempSheetSize As SheetSizes In sheetSizeList

'lw.WriteLine("company sheet length: " & tempSheetSize.CompanySheetLength.ToString)
'lw.WriteLine("company sheet height: " & tempSheetSize.CompanySheetHeight.ToString)
'lw.WriteLine("")
'lw.WriteLine("customer sheet length: " & tempSheetSize.CustomerSheetLength.ToString)
'lw.WriteLine("customer sheet height: " & tempSheetSize.CustomerSheetHeight.ToString)
'lw.WriteLine("")

If Math.Abs(currentSheetLength - tempSheetSize.CompanySheetLength) < sizeTolerance AndAlso Math.Abs(currentSheetHeight - tempSheetSize.CompanySheetHeight) < sizeTolerance Then
'current sheet matches company size
'change sheet to customer size
sizeFound = True
ChangeSheetSize(theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet, tempSheetSize.CustomerSheetLength, tempSheetSize.CustomerSheetHeight)
ChangeLayers(customerLayerList)
Exit For
End If

If Math.Abs(currentSheetLength - tempSheetSize.CustomerSheetLength) < sizeTolerance AndAlso Math.Abs(currentSheetHeight - tempSheetSize.CustomerSheetHeight) < sizeTolerance Then
'current sheet matches customer size
'change sheet to company size
sizeFound = True
ChangeSheetSize(theSession.Parts.Work.DraftingDrawingSheets.CurrentDrawingSheet, tempSheetSize.CompanySheetLength, tempSheetSize.CompanySheetHeight)
ChangeLayers(companyLayerList)
Exit For
End If

Next

If Not sizeFound Then
lw.WriteLine("the current drawing sheet size does not match known sheet sizes")
End If

lw.Close()

End Sub

Sub ChangeSheetSize(ByVal theSheet As Drawings.DraftingDrawingSheet, ByVal newLength As Double, ByVal newHeight As Double)

Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "ChangeSheetSize")

Dim draftingDrawingSheetBuilder1 As NXOpen.Drawings.DraftingDrawingSheetBuilder = Nothing
draftingDrawingSheetBuilder1 = theSession.Parts.Work.DraftingDrawingSheets.CreateDraftingDrawingSheetBuilder(theSheet)

draftingDrawingSheetBuilder1.Option = NXOpen.Drawings.DrawingSheetBuilder.SheetOption.CustomSize

draftingDrawingSheetBuilder1.Height = newHeight

draftingDrawingSheetBuilder1.Length = newLength

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Sheet")

Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = draftingDrawingSheetBuilder1.Commit()

theSession.DeleteUndoMark(markId3, Nothing)

draftingDrawingSheetBuilder1.Destroy()

End Sub

Sub ChangeLayers(ByVal layerList As List(Of Integer))

'first integer in the list is the work layer
'others in list are selectable
'all others are hidden

Dim stateArray1(255) As Layer.StateInfo
'set work layer, turn off all others
For i As Integer = 0 To 255
If i + 1 = layerList.Item(0) Then
stateArray1(i) = New Layer.StateInfo(i + 1, Layer.State.WorkLayer)
Else
stateArray1(i) = New Layer.StateInfo(i + 1, Layer.State.Hidden)
End If
Next
theSession.Parts.Display.Layers.ChangeStates(stateArray1, False)

'set selectable layers
For i As Integer = 1 To layerList.Count - 1
Dim stateArray2(0) As NXOpen.Layer.StateInfo
stateArray2(0) = New NXOpen.Layer.StateInfo(layerList.Item(i), NXOpen.Layer.State.Selectable)
theSession.Parts.Display.Layers.ChangeStates(stateArray2, False)
Next

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

Public Class SheetSizes

Private _customerSheetLength As Double
Public ReadOnly Property CustomerSheetLength() As Double
Get
Return _customerSheetLength
End Get
End Property

Private _customerSheetHeight As Double
Public ReadOnly Property CustomerSheetHeight() As Double
Get
Return _customerSheetHeight
End Get
End Property

Private _companySheetLength As Double
Public ReadOnly Property CompanySheetLength() As Double
Get
Return _companySheetLength
End Get
End Property

Private _companySheetHeight As Double
Public ReadOnly Property CompanySheetHeight() As Double
Get
Return _companySheetHeight
End Get
End Property

Public Sub New(ByVal companySheetLength As Double,
ByVal companySheetHeight As Double,
ByVal customerSheetLength As Double,
ByVal customerSheetHeight As Double)

_companySheetLength = companySheetLength
_companySheetHeight = companySheetHeight
_customerSheetLength = customerSheetLength
_customerSheetHeight = customerSheetHeight

End Sub

End Class

Works great... thanks so much! Greatly appreciated!

AngieL

We do have templates for our customer and for us. We use different layers in our templates to produce a customer print and our company print that has everything else (views, dims, etc) the same on the print. We have a custom program to generate plots and pdfs and other exports. The designer will need to jump back and forth quickly between the "C" sizes of the one sheet. So I found a journal to read the sheet size and create expression. Then I created IF Then Else expressions to change to the other sheet sizes. But when I create a journal or macro to edit the sheet to the new values by entering the name of the new expression, it does not record the entry of the expression name, just records the new value of the expression. So any suggestions on how to do this would be appreciate. Hope this explains our issue more.

AngieL