Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Attributes to Properties with Journal (NX9) 1

Status
Not open for further replies.

Kenja824

Automotive
Joined
Nov 5, 2014
Messages
958
Location
US
Language = Visual Basic
File Format = Unicode

I created a journal to go into Properties of a file and add three attributes. However, it only seems to add the last of the three attributes. If I turn off the lines for the third attribute, it then adds the second attribute.

When doing Drafting Preferences, I could add a bunch of changes to them all in a row and it would do all of them. I figured adding attributes would be the same way but its not working out that way.

Here is what my code looks like.....

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 markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim objects3(0) As NXObject
objects3(0) = workPart

Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects3, AttributePropertiesBuilder.OperationType.None)

theSession.SetUndoMarkName(markId1, "Displayed Part Properties Dialog")

attributePropertiesBuilder1.Title = "F_ENGR"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = "JOHN SMITH"

attributePropertiesBuilder1.Title = "F_ENGRPH"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = "248-555-5555"

attributePropertiesBuilder1.Title = "PROGRAM"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = "XXXX"

Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()

attributePropertiesBuilder1.Destroy()
' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
End Sub
End Module


I know the change will be simple but I just dont know Journal well enough yet to see what I need to change or add.
Also, I will likely be adding more attributes in the future, if that makes any difference.
Thanks
 
OOPS.....

Where it says OBJECTS3, used to say OBJECTS1. I changed that hoping to figure this out for myself and forgot to put it back when I posted this. Sorry for any confusion.
 
Hello kenja824, below is working code with my changes:
Code:
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal

	Sub Main ()

	Dim theSession As Session = Session.GetSession()
	Dim workPart As Part = theSession.Parts.Work
	Dim markId1 As Session.UndoMarkId
	markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
	Dim objects(0) As NXObject
	objects(0) = workPart

	Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
		attributePropertiesBuilder1 = workpart.PropertiesManager.CreateAttributePropertiesBuilder(objects)

	Dim attributePropertiesBuilder2 As AttributePropertiesBuilder
		attributePropertiesBuilder2 = workpart.PropertiesManager.CreateAttributePropertiesBuilder(objects)

	Dim attributePropertiesBuilder3 As AttributePropertiesBuilder
		attributePropertiesBuilder3 = workpart.PropertiesManager.CreateAttributePropertiesBuilder(objects)


	theSession.SetUndoMarkName(markId1, "Displayed Part Properties Dialog")

		attributePropertiesBuilder1.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
		attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
		attributePropertiesBuilder1.Title = "F_ENGR"
		attributePropertiesBuilder1.IsArray = False
		attributePropertiesBuilder1.StringValue = "JOHN SMITH"

		attributePropertiesBuilder2.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
		attributePropertiesBuilder2.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
		attributePropertiesBuilder2.Title = "F_ENGRPH"
		attributePropertiesBuilder2.IsArray = False
		attributePropertiesBuilder2.StringValue = "248-555-5555"

		attributePropertiesBuilder3.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
		attributePropertiesBuilder3.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
		attributePropertiesBuilder3.Title = "PROGRAM"
		attributePropertiesBuilder3.IsArray = False
		attributePropertiesBuilder3.StringValue = "XXXX"

	Dim nXObject1 As NXObject
		nXObject1 = attributePropertiesBuilder1.Commit()
		attributePropertiesBuilder1.Destroy()

	Dim nXObject2 As NXObject
		nXObject2 = attributePropertiesBuilder2.Commit()
		attributePropertiesBuilder2.Destroy()

	Dim nXObject3 As NXObject
		nXObject3 = attributePropertiesBuilder3.Commit()
		attributePropertiesBuilder3.Destroy()

	End Sub

End Module





With best regards
Michael
 
Thanks niedzviedz. This worked perfect. Easy to figure out how to add more too.
 
Hi Niedzviedz,
This is awesome journal, Is it possible to add same attributes in all components in assembly file.


Regards,
Ganesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top