Hello,
I have four journal files and needs to combine all in one, so that my work can be done faster.
The complexity is I have two journal files which have similar functionality with different parameters.
I hope this should cause any Problem for combining.
Let me know if this is possible to do.
I have attached all four journal files for your reference, the journal file name starts from "JOURNAL FILE 1", "JOURNAL FILE 2", "JOURNAL FILE 3" & "JOURNAL FILE 4".
And the code starts from below the journal file names.
JOURNAL FILE 1
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: Tools->Expressions...
' ----------------------------------------------
theSession.Preferences.Modeling.UpdatePending = False
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression")
Dim expression1 As Expression = CType(workPart.Expressions.FindObject("setDESCRIPTION"), Expression)
workPart.Expressions.Delete(expression1)
Dim expression2 As Expression = CType(workPart.Expressions.FindObject("setHEAT_TREAT"), Expression)
workPart.Expressions.Delete(expression2)
Dim expression3 As Expression = CType(workPart.Expressions.FindObject("setPART_NO"), Expression)
workPart.Expressions.Delete(expression3)
Dim expression4 As Expression = CType(workPart.Expressions.FindObject("setSTAGE"), Expression)
workPart.Expressions.Delete(expression4)
Dim expression5 As Expression = CType(workPart.Expressions.FindObject("DESCRIPTION"), Expression)
workPart.Expressions.Delete(expression5)
Dim expression6 As Expression = CType(workPart.Expressions.FindObject("PART_NO"), Expression)
workPart.Expressions.Delete(expression6)
Dim expression7 As Expression = CType(workPart.Expressions.FindObject("DETAIL_NO"), Expression)
workPart.Expressions.Delete(expression7)
Dim expression8 As Expression = CType(workPart.Expressions.FindObject("DIE_NO"), Expression)
workPart.Expressions.Delete(expression8)
Dim expression9 As Expression = CType(workPart.Expressions.FindObject("DWG_TITLE"), Expression)
workPart.Expressions.Delete(expression9)
Dim expression10 As Expression = CType(workPart.Expressions.FindObject("DWG_TITLE_2"), Expression)
workPart.Expressions.Delete(expression10)
theSession.Preferences.Modeling.UpdatePending = False
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module
JOURNAL FILE 2
Option Strict Off
Imports System
Imports NXOpen
Module Module4
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const attributeName1 As String = "DWG_TITLE"
Const attributeName2 As String = "DWG_TITLE_2"
Const expName As String = "DESCRIPTION"
If Not workPart.HasUserAttribute(attributeName1, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName1 & " not found, journal exiting")
Return
End If
If Not workPart.HasUserAttribute(attributeName2, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName2 & " not found, journal exiting")
Return
End If
'get the underlying attribute expressions
Dim attExp1 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName1, NXObject.AttributeType.String, -1)
Dim attExp2 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName2, NXObject.AttributeType.String, -1)
'create/update the description expression using the attribute expressions
Dim expDescription As Expression = Nothing
Try
expDescription = workPart.Expressions.CreateExpression("String", expName & " = "& attExp1.Name &"+"" """&"+" & attExp2.Name)
Catch ex As NXException
If ex.ErrorCode = 1050017 Then
'expression already exists
'get the existing expression
expDescription = workPart.Expressions.FindObject(expName)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Expression edit")
'update the formula
expDescription.RightHandSide = attExp1.Name & "+"" """ & " +"& attExp2.Name
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)
Else
'other error
lw.WriteLine("NX exception: " & ex.ErrorCode & ", " & ex.Message)
End If
End Try
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
JOURNAL FILE 3
Option Strict Off
Imports System
Imports NXOpen
Module Module4
Sub Main()
Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const attributeName1 As String = "DIE_NO"
Const attributeName2 As String = "DETAIL_NO"
Const expName As String = "PART_NO"
If Not workPart.HasUserAttribute(attributeName1, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName1 & " not found, journal exiting")
Return
End If
If Not workPart.HasUserAttribute(attributeName2, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName2 & " not found, journal exiting")
Return
End If
'get the underlying attribute expressions
Dim attExp1 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName1, NXObject.AttributeType.String, -1)
Dim attExp2 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName2, NXObject.AttributeType.String, -1)
'create/update the description expression using the attribute expressions
Dim expDescription As Expression = Nothing
Try
expDescription = workPart.Expressions.CreateExpression("String", expName & " = "& attExp1.Name &"+""-"""&"+" & attExp2.Name)
Catch ex As NXException
If ex.ErrorCode = 1050017 Then
'expression already exists
'get the existing expression
expDescription = workPart.Expressions.FindObject(expName)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Expression edit")
'update the formula
expDescription.RightHandSide = attExp1.Name & "+"" """ & " +"& attExp2.Name
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)
Else
'other error
lw.WriteLine("NX exception: " & ex.ErrorCode & ", " & ex.Message)
End If
End Try
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
JOURNAL FILE 4
JOURNALOption 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->Properties
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim objects1(0) As NXObject
objects1(0) = workPart
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Units = "MilliMeter"
Dim objects2(0) As NXObject
objects2(0) = workPart
Dim massPropertiesBuilder1 As MassPropertiesBuilder
massPropertiesBuilder1 = workPart.PropertiesManager.CreateMassPropertiesBuilder(objects2)
Dim selectNXObjectList1 As SelectNXObjectList
selectNXObjectList1 = massPropertiesBuilder1.SelectedObjects
Dim objects3() As NXObject
objects3 = selectNXObjectList1.GetArray()
massPropertiesBuilder1.UpdateOnSave = MassPropertiesBuilder.UpdateOptions.No
massPropertiesBuilder1.LoadPartialComponents = True
massPropertiesBuilder1.Accuracy = 0.99
Dim objects4(0) As NXObject
objects4(0) = workPart
Dim previewPropertiesBuilder1 As PreviewPropertiesBuilder
previewPropertiesBuilder1 = workPart.PropertiesManager.CreatePreviewPropertiesBuilder(objects4)
previewPropertiesBuilder1.StorePartPreview = True
previewPropertiesBuilder1.StoreModelViewPreview = True
previewPropertiesBuilder1.ModelViewCreation = PreviewPropertiesBuilder.ModelViewCreationOptions.OnViewSave
Dim objects5(0) As NXObject
objects5(0) = workPart
attributePropertiesBuilder1.SetAttributeObjects(objects5)
attributePropertiesBuilder1.Units = "MilliMeter"
theSession.SetUndoMarkName(markId1, "Displayed Part Properties Dialog")
attributePropertiesBuilder1.DateValue.DateItem.Day = DateItemBuilder.DayOfMonth.Day29
attributePropertiesBuilder1.DateValue.DateItem.Month = DateItemBuilder.MonthOfYear.Apr
attributePropertiesBuilder1.DateValue.DateItem.Year = "2016"
attributePropertiesBuilder1.DateValue.DateItem.Time = "00:00:00"
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DESCRIPTION"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = "SET SCREW "
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Link to Expression")
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Launch Expression Editor")
' ----------------------------------------------
' Dialog Begin Expressions
' ----------------------------------------------
attributePropertiesBuilder1.StringValue = "SET SCREW "
attributePropertiesBuilder1.IsReferenceType = False
Dim expression1 As Expression = CType(workPart.Expressions.FindObject("DESCRIPTION"), Expression)
attributePropertiesBuilder1.Expression = expression1
theSession.DeleteUndoMarksUpToMark(markId3, Nothing, False)
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Accept Edit")
Dim changed1 As Boolean
changed1 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsReferenceType = False
Dim nullExpression As Expression = Nothing
attributePropertiesBuilder1.Expression = nullExpression
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "CHECKED_DATE"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "PART_NO"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = "D220-30X-70800"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Link to Expression")
Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Launch Expression Editor")
' ----------------------------------------------
' Dialog Begin Expressions
' ----------------------------------------------
attributePropertiesBuilder1.StringValue = "D220-30X-70800"
attributePropertiesBuilder1.IsReferenceType = False
Dim expression2 As Expression = CType(workPart.Expressions.FindObject("PART_NO"), Expression)
attributePropertiesBuilder1.Expression = expression2
theSession.DeleteUndoMarksUpToMark(markId6, Nothing, False)
Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Accept Edit")
Dim changed2 As Boolean
changed2 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsReferenceType = False
attributePropertiesBuilder1.Expression = nullExpression
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Displayed Part Properties")
theSession.DeleteUndoMark(markId8, Nothing)
Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Displayed Part Properties")
Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
Dim updateoption1 As MassPropertiesBuilder.UpdateOptions
updateoption1 = massPropertiesBuilder1.UpdateOnSave
Dim nXObject2 As NXObject
nXObject2 = massPropertiesBuilder1.Commit()
workPart.PartPreviewMode = BasePart.PartPreview.OnSave
Dim nXObject3 As NXObject
nXObject3 = previewPropertiesBuilder1.Commit()
Dim id1 As Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)
theSession.DeleteUndoMark(markId9, Nothing)
theSession.SetUndoMarkName(markId1, "Displayed Part Properties")
attributePropertiesBuilder1.Destroy()
massPropertiesBuilder1.Destroy()
previewPropertiesBuilder1.Destroy()
theSession.DeleteUndoMark(id1, Nothing)
theSession.DeleteUndoMark(markId5, Nothing)
theSession.DeleteUndoMark(markId4, Nothing)
theSession.DeleteUndoMark(markId2, Nothing)
' ----------------------------------------------
' Menu: File->Save
' ----------------------------------------------
Dim part1 As Part
part1 = theSession.Parts.Display
theSession.LogFile.WriteLine("")
theSession.LogFile.WriteLine("Drafting Attributes User Exit starts here ############## ")
theSession.LogFile.WriteLine("We are not in drafting, so let's not continue the user exit")
Dim partSaveStatus1 As PartSaveStatus
partSaveStatus1 = workPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False)
partSaveStatus1.Dispose()
Dim partCloseResponses1 As PartCloseResponses
partCloseResponses1 = theSession.Parts.NewPartCloseResponses()
workPart.Close(BasePart.CloseWholeTree.False, BasePart.CloseModified.UseResponses, partCloseResponses1)
workPart = Nothing
displayPart = Nothing
partCloseResponses1.Dispose()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module FILE 4
re: combined journals
Here's a quick combine job. Post back if you run into issues.
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 lw As ListingWindow = theSession.ListingWindow
Sub Main()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
lw.Open()
Const undoMarkName As String = "Praveen's journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim expsToBeDeleted As New List(Of String)
With expsToBeDeleted
.Add("setDESCRIPTION")
.Add("setHEAT_TREAT")
.Add("setPART_NO")
.Add("setSTAGE")
.Add("DESCRIPTION")
.Add("PART_NO")
.Add("DETAIL_NO")
.Add("DIE_NO")
.Add("DWG_TITLE")
.Add("DWG_TITLE_2")
End With
Call DeleteExpressions(expsToBeDeleted)
Const attributeName1 As String = "DWG_TITLE"
Const attributeName2 As String = "DWG_TITLE_2"
Const expName As String = "DESCRIPTION"
If Not workPart.HasUserAttribute(attributeName1, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName1 & " not found, journal exiting")
Return
End If
If Not workPart.HasUserAttribute(attributeName2, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName2 & " not found, journal exiting")
Return
End If
'get the underlying attribute expressions
Dim attExp1 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName1, NXObject.AttributeType.String, -1)
Dim attExp2 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName2, NXObject.AttributeType.String, -1)
'create/update the description expression using the attribute expressions
Dim expDescription As Expression = Nothing
Try
expDescription = workPart.Expressions.CreateExpression("String", expName & " = " & attExp1.Name & "+"" """ & "+" & attExp2.Name)
Catch ex As NXException
If ex.ErrorCode = 1050017 Then
'expression already exists
'get the existing expression
expDescription = workPart.Expressions.FindObject(expName)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Expression edit")
'update the formula
expDescription.RightHandSide = attExp1.Name & "+"" """ & " +" & attExp2.Name
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)
Else
'other error
lw.WriteLine("NX exception: " & ex.ErrorCode & ", " & ex.Message)
End If
End Try
Const attributeName3 As String = "DIE_NO"
Const attributeName4 As String = "DETAIL_NO"
Const expName2 As String = "PART_NO"
If Not workPart.HasUserAttribute(attributeName3, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName3 & " not found, journal exiting")
Return
End If
If Not workPart.HasUserAttribute(attributeName4, NXObject.AttributeType.String, -1) Then
lw.WriteLine("attribute " & attributeName4 & " not found, journal exiting")
Return
End If
'get the underlying attribute expressions
Dim attExp3 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName3, NXObject.AttributeType.String, -1)
Dim attExp4 As Expression = workPart.Expressions.GetAttributeExpression(workPart, attributeName4, NXObject.AttributeType.String, -1)
'create/update the description expression using the attribute expressions
Dim expDescription2 As Expression = Nothing
Try
expDescription2 = workPart.Expressions.CreateExpression("String", expName2 & " = " & attExp3.Name & "+""-""" & "+" & attExp4.Name)
Catch ex As NXException
If ex.ErrorCode = 1050017 Then
'expression already exists
'get the existing expression
expDescription2 = workPart.Expressions.FindObject(expName2)
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Expression edit")
'update the formula
expDescription2.RightHandSide = attExp3.Name & "+"" """ & " +" & attExp4.Name
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)
Else
'other error
lw.WriteLine("NX exception: " & ex.ErrorCode & ", " & ex.Message)
End If
End Try
Try
AddPartAttribute("DESCRIPTION", "DESCRIPTION")
Catch ex As NXException
lw.WriteLine("error while adding 'DESCRIPTION' attribute: " & ex.Message)
End Try
Try
AddPartAttribute("PART_NO", "PART_NO")
Catch ex As NXException
lw.WriteLine("error while adding 'PART_NO' attribute: " & ex.Message)
End Try
lw.Close()
End Sub
Sub DeleteExpressions(ByVal expNames As List(Of String))
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "delete expressions")
For Each tempName As String In expNames
Try
Dim tempExp As Expression = theSession.Parts.Work.Expressions.FindObject(tempName)
theSession.Parts.Work.Expressions.Delete(tempExp)
Catch ex As Exception
End Try
Next
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
End Sub
Sub AddPartAttribute(ByVal attributeTitle As String, ByVal expressionName As String)
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "part attribute")
Dim objects1(0) As NXObject
objects1(0) = theSession.Parts.Work
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(theSession.Parts.Work, objects1, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = expressionName
Dim expression1 As Expression = Nothing
Try
expression1 = CType(theSession.Parts.Work.Expressions.FindObject(expressionName), Expression)
Catch ex As NXException
theSession.UndoToMark(markId1, "part attribute")
Throw ex
End Try
attributePropertiesBuilder1.Expression = expression1
Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
Dim id1 As Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)
attributePropertiesBuilder1.Destroy()
theSession.DeleteUndoMark(id1, 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
Thank you very much
The quick combine code is working as expected, there are no errors found on the combined code. Thank you very much for the code. I have one question.
In future if I need to add one more journal to this, how I can add ? I have one more journal which has to be attached to the combined code.
' NX 9.0.2.5
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->Properties
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim objects1(0) As NXObject
objects1(0) = workPart
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Units = "MilliMeter"
Dim objects2(0) As NXObject
objects2(0) = workPart
Dim massPropertiesBuilder1 As MassPropertiesBuilder
massPropertiesBuilder1 = workPart.PropertiesManager.CreateMassPropertiesBuilder(objects2)
Dim selectNXObjectList1 As SelectNXObjectList
selectNXObjectList1 = massPropertiesBuilder1.SelectedObjects
Dim objects3() As NXObject
objects3 = selectNXObjectList1.GetArray()
massPropertiesBuilder1.UpdateOnSave = MassPropertiesBuilder.UpdateOptions.No
massPropertiesBuilder1.LoadPartialComponents = True
massPropertiesBuilder1.Accuracy = 0.99
Dim objects4(0) As NXObject
objects4(0) = workPart
Dim previewPropertiesBuilder1 As PreviewPropertiesBuilder
previewPropertiesBuilder1 = workPart.PropertiesManager.CreatePreviewPropertiesBuilder(objects4)
attributePropertiesBuilder1.DateValue.FromDateItem.Year = "2014"
attributePropertiesBuilder1.DateValue.ToDateItem.Year = "2014"
previewPropertiesBuilder1.StorePartPreview = True
previewPropertiesBuilder1.StoreModelViewPreview = True
previewPropertiesBuilder1.ModelViewCreation = PreviewPropertiesBuilder.ModelViewCreationOptions.OnViewSave
Dim objects5(0) As NXObject
objects5(0) = workPart
attributePropertiesBuilder1.SetAttributeObjects(objects5)
attributePropertiesBuilder1.Units = "MilliMeter"
theSession.SetUndoMarkName(markId1, "Displayed Part Properties Dialog")
attributePropertiesBuilder1.DateValue.DateItem.Day = DateItemBuilder.DayOfMonth.Day06
attributePropertiesBuilder1.DateValue.DateItem.Month = DateItemBuilder.MonthOfYear.Nov
attributePropertiesBuilder1.DateValue.DateItem.Year = "2015"
attributePropertiesBuilder1.DateValue.DateItem.Time = "00:00:00"
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DETAIL_NO"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Category = "All TE Drawings"
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Accept Edit")
Dim changed1 As Boolean
changed1 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DIE_NO"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Category = "All TE Drawings"
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Accept Edit")
Dim changed2 As Boolean
changed2 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DWG_TITLE"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Category = "All TE Drawings"
Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Accept Edit")
Dim changed3 As Boolean
changed3 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DWG_TITLE_2"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Category = "All TE Drawings"
Dim markId5 As Session.UndoMarkId
markId5 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Accept Edit")
Dim changed4 As Boolean
changed4 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DOC_NUMBER"
attributePropertiesBuilder1.Category = "All TE Drawings"
attributePropertiesBuilder1.Category = "All TE Mandatory"
Dim markId6 As Session.UndoMarkId
markId6 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Link to Expression")
Dim markId7 As Session.UndoMarkId
markId7 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Launch Expression Editor")
' ----------------------------------------------
' Dialog Begin Expressions
' ----------------------------------------------
attributePropertiesBuilder1.StringValue = "-"
attributePropertiesBuilder1.IsReferenceType = False
Dim expression1 As Expression = CType(workPart.Expressions.FindObject("PART_NO"), Expression)
attributePropertiesBuilder1.Expression = expression1
theSession.DeleteUndoMarksUpToMark(markId7, Nothing, False)
Dim markId8 As Session.UndoMarkId
markId8 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add New Attribute")
Dim changed5 As Boolean
changed5 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsReferenceType = False
Dim nullExpression As Expression = Nothing
attributePropertiesBuilder1.Expression = nullExpression
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DOC_TITLE"
attributePropertiesBuilder1.Category = "All TE Mandatory"
Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Link to Expression")
Dim markId10 As Session.UndoMarkId
markId10 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Launch Expression Editor")
' ----------------------------------------------
' Dialog Begin Expressions
' ----------------------------------------------
attributePropertiesBuilder1.StringValue = " "
attributePropertiesBuilder1.IsReferenceType = False
Dim expression2 As Expression = CType(workPart.Expressions.FindObject("DESCRIPTION"), Expression)
attributePropertiesBuilder1.Expression = expression2
theSession.DeleteUndoMarksUpToMark(markId10, Nothing, False)
Dim markId11 As Session.UndoMarkId
markId11 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add New Attribute")
Dim changed6 As Boolean
changed6 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsReferenceType = False
attributePropertiesBuilder1.Expression = nullExpression
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DOC_STATUS"
attributePropertiesBuilder1.Category = "All TE Mandatory"
attributePropertiesBuilder1.StringValue = "Active"
Dim markId12 As Session.UndoMarkId
markId12 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add New Attribute")
Dim changed7 As Boolean
changed7 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "DOC_TYPE"
attributePropertiesBuilder1.Category = "All TE Mandatory"
attributePropertiesBuilder1.StringValue = "Tooling Drawing"
Dim markId13 As Session.UndoMarkId
markId13 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add New Attribute")
Dim changed8 As Boolean
changed8 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "MBD_COMPLIANT"
attributePropertiesBuilder1.Category = "All TE Mandatory"
attributePropertiesBuilder1.StringValue = "NO"
Dim markId14 As Session.UndoMarkId
markId14 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add New Attribute")
Dim changed9 As Boolean
changed9 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Title = "SEND_TO_STARTEC"
attributePropertiesBuilder1.Category = "All TE Mandatory"
attributePropertiesBuilder1.StringValue = "FALSE"
Dim markId15 As Session.UndoMarkId
markId15 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add New Attribute")
Dim changed10 As Boolean
changed10 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Category = ""
attributePropertiesBuilder1.Title = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = ""
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.IsArray = False
Dim markId16 As Session.UndoMarkId
markId16 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Displayed Part Properties")
theSession.DeleteUndoMark(markId16, Nothing)
Dim markId17 As Session.UndoMarkId
markId17 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Displayed Part Properties")
Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
Dim updateoption1 As MassPropertiesBuilder.UpdateOptions
updateoption1 = massPropertiesBuilder1.UpdateOnSave
Dim nXObject2 As NXObject
nXObject2 = massPropertiesBuilder1.Commit()
workPart.PartPreviewMode = BasePart.PartPreview.OnSave
Dim nXObject3 As NXObject
nXObject3 = previewPropertiesBuilder1.Commit()
Dim id1 As Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)
theSession.DeleteUndoMark(markId17, Nothing)
theSession.SetUndoMarkName(markId1, "Displayed Part Properties")
attributePropertiesBuilder1.Destroy()
massPropertiesBuilder1.Destroy()
previewPropertiesBuilder1.Destroy()
theSession.DeleteUndoMark(id1, Nothing)
theSession.DeleteUndoMark(markId14, Nothing)
theSession.DeleteUndoMark(markId13, Nothing)
theSession.DeleteUndoMark(markId12, Nothing)
theSession.DeleteUndoMark(markId11, Nothing)
theSession.DeleteUndoMark(markId9, Nothing)
theSession.DeleteUndoMark(markId8, Nothing)
theSession.DeleteUndoMark(markId6, Nothing)
theSession.DeleteUndoMark(markId5, Nothing)
theSession.DeleteUndoMark(markId4, Nothing)
theSession.DeleteUndoMark(markId3, Nothing)
theSession.DeleteUndoMark(markId2, Nothing)
End Sub
End Module
Thanks,
Praveen
re: add journal code
After recording journal code, I suggest removing the redundant and useless code added by the recorder. For example, if you see the same property being set multiple times in the recorded code, it is only the last one that takes effect. Try commenting out the other lines and running the journal; if it still runs correctly, the other lines can be removed.
If your final journal needs to do a similar process multiple times (such as setting part attributes), it would be beneficial to rework the recorded journal code into a subroutine or function that can be called with the desired values to be set. This will make your final code more "re-usable" and therefore easier to maintain and extend in the future.
Thank you very much for your
Thank you very much for your suggestions. I will try as per your suggestion and let you know if I can get it.