I currently have a journal file to delete all of my old titleblocks (from all sheets at once). Then I have to go to each sheet individually and run smaller journal files to import the titleblock of choice. Instead, I would like to import my new titleblock into every sheet in 1 step. Does anyone know of a journal file out there that could accomplish something like this? I show both of my journals that I currently use below. How do I run a loop for the import-part function to add my selected part to all sheets in the drawing? Any help would be greatly appreciated as this is a huge time waster for me. I have to open each sheet individually to add my titleblocks.
The journal I use to delete all the titleblocks (from all sheets at once) is:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Module group_delete
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Const targetGroup As String = "MD"
Dim groupsToDelete As New List(Of Group)
Dim groupTag As NXOpen.Tag = NXOpen.Tag.Null
Dim myGroup As Group
'use Do loop to find all groups with the given name
Do
theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_group_type, groupTag)
'skip the initial null tag
If groupTag = NXOpen.Tag.Null Then
Continue Do
End If
myGroup = Utilities.NXObjectManager.Get(groupTag)
If myGroup.Name.ToUpper.Contains(targetGroup) Then
groupsToDelete.Add(myGroup)
End If
Loop Until groupTag = NXOpen.Tag.Null
'delete all the groups that we found
theSession.UpdateManager.ClearErrorList()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete group")
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(groupsToDelete.ToArray)
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
End Sub
End Module
The journal I use (which I hope to replace) to import a part to the current sheet is:
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
Dim displayPart As Part = theSession.Parts.Display
' ----------------------------------------------
' Menu: File->Import->Part...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Import Part")
Dim partImporter1 As PartImporter
partImporter1 = workPart.ImportManager.CreatePartImporter()
partImporter1.FileName = "N:\NX9\Titleblocks\Drawing-A0-Detail-template.prt"
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = True
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work
Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)
partImporter1.DestinationCoordinateSystem = nXMatrix1
Dim destinationPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
partImporter1.DestinationPoint = destinationPoint1
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Import Part Commit")
Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()
theSession.DeleteUndoMark(markId2, Nothing)
partImporter1.Destroy()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
re: import title block to each sheet
I'd suggest taking the code that imports the title block and turning it into a subroutine (or function). For the example, let's assume the subroutine is named ImportTitleBlock. Then you can call the subroutine for each drawing sheet; the code will look something like below:
For Each tempSheet As Drawings.DrawingSheet In workPart.DrawingSheets
tempSheet.Open()
ImportTitleBlock()
Next
Different title block templates for different sheet numbers
With the above Suggestions, I can assign title block template to all sheets in one go.
Could you please suggest modifications in my code below to assign title block template 1 to sheet number 1 and title block template 2 for rest all sheets in the drawing.
We need modifications in the program because we have 02 different templates, one is only for sheet number 1 and another is common for rest all sheets.
Thanks in advance.
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
'***********************************************************************
Sub Main
For Each tempSheet As Drawings.draftingDrawingSheet In workPart.draftingDrawingSheets
tempSheet.Open()
'----------------------------
' RESiZE SHEETS TO D SIZE
'----------------------------
Dim draftingDrawingSheetBuilder1 As NXOpen.Drawings.DraftingDrawingSheetBuilder = Nothing
draftingDrawingSheetBuilder1 = workPart.draftingDrawingSheets.CreatedraftingDrawingSheetBuilder(tempsheet)
draftingDrawingSheetBuilder1.Height = 22.0
draftingDrawingSheetBuilder1.Length = 34.0
Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Sheet")
theSession.DeleteUndoMark(markId2, Nothing)
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()
'--------------------------------
' DELETE OLD TEMPLATE ENTITIES
'--------------------------------
Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Delete")
theSession.UpdateManager.ClearErrorList()
Dim markId5 As NXOpen.Session.UndoMarkId = Nothing
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete")
Dim objects1(1) As NXOpen.TaggedObject
Dim displayableObject1 As NXOpen.DisplayableObject = CType(workPart.FindObject("ENTITY 10 2 1"), NXOpen.DisplayableObject)
objects1(0) = displayableObject1
Dim displayableObject2 As NXOpen.DisplayableObject = CType(workPart.FindObject("ENTITY 10 1 1"), NXOpen.DisplayableObject)
objects1(1) = displayableObject2
Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.AddObjectsToDeleteList(objects1)
Dim id1 As NXOpen.Session.UndoMarkId = Nothing
id1 = theSession.NewestVisibleUndoMark
Dim nErrs2 As Integer = Nothing
nErrs2 = theSession.UpdateManager.DoUpdate(id1)
theSession.DeleteUndoMark(markId4, Nothing)
'----------------------------------------------
' IMPORT NEW TEMPLATE WITH IMPORT PART OPTION
'----------------------------------------------
Dim markId6 As NXOpen.Session.UndoMarkId = Nothing
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Import Part")
Dim partImporter1 As NXOpen.PartImporter = Nothing
partImporter1 = workPart.ImportManager.CreatePartImporter()
partImporter1.FileName = "C:\Users\temp\Desktop\NX\NX_Template\Test_1.prt"
partImporter1.Scale = 1.0
partImporter1.CreateNamedGroup = True
partImporter1.ImportViews = False
partImporter1.ImportCamObjects = False
partImporter1.LayerOption = NXOpen.PartImporter.LayerOptionType.Work
partImporter1.DestinationCoordinateSystemSpecification = NXOpen.PartImporter.DestinationCoordinateSystemSpecificationType.Work
Dim element1 As NXOpen.Matrix3x3 = Nothing
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXOpen.NXMatrix = Nothing
nXMatrix1 = workPart.NXMatrices.Create(element1)
partImporter1.DestinationCoordinateSystem = nXMatrix1
Dim destinationPoint1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
partImporter1.DestinationPoint = destinationPoint1
Dim markId7 As NXOpen.Session.UndoMarkId = Nothing
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Import Part Commit")
Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = partImporter1.Commit()
theSession.DeleteUndoMark(markId7, Nothing)
partImporter1.Destroy()
Next
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