Copying Text to Other Sheets

Forums: 

This Snap program works and came from the Snap Reference Guide. Everything is all right with one exception. When running this journal the fruits are straight across on a "D" size drawing and price, interest, and vendor are away and form a general note. My objective is to have what is run on the 1st sheet and only the fruits (Apple, Banana, and Cherry) take over on the rest of the sheets in the NX9 spec file.I could have a 100 sheets so who cares how many sheets there are.

Could somebody help me with the rest of the puzzle.

Imports Snap, Snap.Create

Public Class MyProgram

Public Shared Sub Main()

' Create a very simple one-line note.
' We pass "Nothing", so formatting will be controlled by preferences
Dim p As New Position(30, 65)
Note(p, Nothing, "Hello")

' A more interesting three-line note,
' again using formatting from annotation preferences
Dim lines As String() = New String(3) {}
lines(0) = "Price: €247 ± €5 for 25cm³"
lines(1) = "Interest: about ¼% per month"
lines(2) = "Vendor: Nuñez Mfg, Grüberstraße"
Note(New Position(10, 10), Nothing, lines)

' Create a TextStyle object representing annotation preferences,
' and modify a few things about it (color, font, size)
Dim blueCambria12 As New NX.TextStyle()
blueCambria12.Color = System.Drawing.Color.Blue
blueCambria12.FontName = "Cambria"
blueCambria12.FontSize = 12

' Now use this TextStyle to create three notes
Note(New Position(10, 20), blueCambria12, "Apple")
Note(New Position(20, 20), blueCambria12, "Banana")
Note(New Position(30, 20), blueCambria12, "Cherry")

End Sub

End Class

Let me make sure that I understand what you are after. You have 2 notes; one should only show up on the first sheet and the other should show up on every sheet. Something like:
"Note 1"
"Note 2"
Where "Note 1" is only on the first sheet and "Note 2" is on every sheet. Is this correct?

The .CreateNote method will place the annotation on the current drawing sheet. To create a note on each sheet, activate each sheet in turn and create the note. I can work up a quick example if this is the result you are after.

With the present Program the notes are all put on Sheet 1. Now I need just only fruits to be put on sheets to what ever the file has. If the file has 10 sheets then sheets 2 thru 10 will have only fruits and sheet 1 will have both fruits and the other notes on sheet 1.

The journal below shows one way to add a note to each drawing sheet.

Option Strict Off
Imports System
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()

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

lw.Open()

Dim note1(0) As String
note1(0) = "First Note"
Dim noteLocation1 As New Point3d(5, 5, 0)

Dim note2(0) As String
note2(0) = "Common Note"
Dim noteLocation2 As New Point3d(5, 4, 0)

For i As Integer = 0 To theSession.Parts.Work.DrawingSheets.ToArray.Length - 1
theSession.Parts.Work.DrawingSheets.ToArray(i).Open()
If i = 0 Then
AddNote(note1, noteLocation1)
End If

AddNote(note2, noteLocation2)
Next

lw.Close()

End Sub

Sub AddNote(ByVal noteText() As String, ByVal location As Point3d)

Dim newNote As Annotations.Note
newNote = theSession.Parts.Work.Annotations.CreateNote(noteText, location, AxisOrientation.Horizontal, Nothing, Nothing)

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

This will work. Thanks a lot!!!Now to see if I can rewrite Using SNAP

There's no real need to "rewrite using SNAP" as you can use the code above as is along with your other code. Using SNAP does not exclude you from using the normal API calls.

Was wondering as this program cycles thru and puts text on other sheets the program ends on the last page. What could be written in the Journal to bring the drawing back to Page 1? Once page 1 is noticed there I would be Running a Pdf Journal to save on my Local drive.

Just .Open the first sheet in the array at the end of your journal.

If you have been adding, removing, and rearranging the sheets in your drawing, the first one in the array may not be sheet number 1. To find a sheet's page number, you can use the .DrawingSheetBuilder object. There is some example code below that sorts the drawing sheets by sheet page number.

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()

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

lw.Open()

Dim dwgSheets As New List(Of Drawings.DrawingSheet)

For Each temp As Drawings.DrawingSheet In theSession.Parts.Work.DrawingSheets
dwgSheets.Add(temp)
Next

'report current sheet order
For Each temp As Drawings.DrawingSheet In dwgSheets
lw.WriteLine("sheet name: " & temp.Name & ", page number: " & SheetNumber(temp).ToString)
Next
lw.WriteLine("")

'sort sheets by sheet number
dwgSheets.Sort(AddressOf CompareSheetNumbers)

'report sorted sheet order
For Each temp As Drawings.DrawingSheet In dwgSheets
lw.WriteLine("sheet name: " & temp.Name & ", page number: " & SheetNumber(temp).ToString)
Next
lw.WriteLine("")

' Roll back to avoid marking the part as Modified
theSession.UndoToMark(markId1, "NXJ")
theSession.DeleteUndoMark(markId1, "NXJ")

lw.Close()

End Sub

Private Function CompareSheetNumbers(ByVal x As Drawings.DrawingSheet, ByVal y As Drawings.DrawingSheet) As Integer

Dim xNum As Integer = SheetNumber(x)
Dim yNum As Integer = SheetNumber(y)

If xNum > yNum Then
Return 1
End If

If xNum < yNum Then
Return -1
End If

If xNum = yNum Then
Return 0
End If

End Function

Function SheetNumber(ByVal theSheet As Drawings.DrawingSheet) As Integer

Dim sheetNum As Integer
Dim theSheetBuilder As Drawings.DrawingSheetBuilder = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(theSheet)
sheetNum = theSheetBuilder.Number

theSheetBuilder.Destroy()

Return sheetNum

End Function

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