Creating 2 Components with the Same Name

Hi,

I want to create 2 components as a children of another component. When manually copy-paste one component under the same parent, new component is created successfully. But when trying to create a component with journal, i can't create component with the same name. It gives me an error that i can't do that.

For Example:

Below hierarchy is valid when copy 'pXXX0101' and paste to same place. I can create many of them without problem with manually. But, when trying to create with NX Journal, it doesn't permit that. aXXX010000 is parent of pXXX010100 components.

-- aXXX010000
-- pXXX010100
-- pXXX010100

Actually, i know that even component names looks same in hierarchy, they hidden their real names. So, their names relatively:

-- aXXX010000
-- pXXX010100 (1)
-- pXXX010100 (2)

So my question is that how can i create a component with full name such as 'pXXX010100 (1)' ?

Thanks in advance.
Best regards.

Do you get any error message? Can you post the code that you have so far? Are you working in native NX or with a PLM such as Teamcenter?

You should be able to add as many instances of the component as you need. I don't know of any limitation due to the component name. Also, I don't know anything about a "hidden real name"; each instance will have its own tag (and internal ID).

Hi,

We are using NX with TeamCenter.
I created a journal that create one component at a time. When i attempted to create second component with the same name, it gives me below error:

NXOpen.NXException: The new filename is not a valid file specification
at NXOpen.Builder.Commit()
at NXJournal.Main(String[] args) in C:\Users\musan\AppData\Local\Temp\NXJournals188\journal.vb:line:380

I want to immitate copy-paste as if i am in 'Assembly Navigator'. When i copy one component in Assembly Navigator and paste it in same place, two component with the same name appear. Because NXJournal doesn't allow to copy-paste operation, i want to create components with same name via below code. So if there is a elegant way to do same thing, it is also OK and welcome.


Option Strict Off
Imports System
Imports NXOpen

Module NXJournal

Dim cadItemName as String = "a52016_211CAP110FXZ050000"

Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Assemblies->Components->Create New Component...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Create New Component")

Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim fileNew1 As NXOpen.FileNew
fileNew1 = theSession.Parts.FileNew()

Try
' The selected template doesn't exist
fileNew1.TemplateFileName = "Blank"
Catch ex As NXException
ex.AssertErrorCode(3815003)
End Try

fileNew1.UseBlankTemplate = True

fileNew1.ApplicationName = "AssemblyTemplate"

fileNew1.Units = NXOpen.Part.Units.Millimeters

fileNew1.RelationType = ""

fileNew1.UsesMasterModel = "No"

fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item

fileNew1.TemplatePresentationName = ""

fileNew1.ItemType = ""

fileNew1.Specialization = ""

fileNew1.SetCanCreateAltrep(False)

Dim partOperationCreateBuilder1 As NXOpen.PDM.PartOperationCreateBuilder
partOperationCreateBuilder1 = theSession.PdmSession.CreateCreateOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.Create)

fileNew1.SetPartOperationCreateBuilder(partOperationCreateBuilder1)

partOperationCreateBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCreateBuilder.OperationSubType.FromTemplate)

partOperationCreateBuilder1.SetModelType("master")

partOperationCreateBuilder1.SetItemType("Item")

Dim logicalobjects1() As NXOpen.PDM.LogicalObject
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects1)

Dim sourceobjects1() As NXOpen.NXObject
sourceobjects1 = logicalobjects1(0).GetUserAttributeSourceObjects()

Dim tableEditorDefaultDataProvider1 As NXOpen.TableEditorDefaultDataProvider
tableEditorDefaultDataProvider1 = theSession.CreateTableEditorDefaultDataProvider(workPart)

tableEditorDefaultDataProvider1.RowCount = 0

tableEditorDefaultDataProvider1.ColumnCount = 4

partOperationCreateBuilder1.DefaultDestinationFolder = ":Newstuff"

Dim sourceobjects2() As NXOpen.NXObject
sourceobjects2 = logicalobjects1(0).GetUserAttributeSourceObjects()

tableEditorDefaultDataProvider1.RowCount = 1

tableEditorDefaultDataProvider1.ColumnCount = 2

Dim sourceobjects3() As NXOpen.NXObject
sourceobjects3 = logicalobjects1(0).GetUserAttributeSourceObjects()

tableEditorDefaultDataProvider1.RowCount = 3

tableEditorDefaultDataProvider1.ColumnCount = 2

partOperationCreateBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCreateBuilder.OperationSubType.FromTemplate)

theSession.SetUndoMarkName(markId2, "New Component File Dialog")

fileNew1.TemplateFileName = "@DB/CAD/A"

fileNew1.UseBlankTemplate = False

fileNew1.ApplicationName = "ModelTemplate"

fileNew1.Units = NXOpen.Part.Units.Millimeters

fileNew1.RelationType = "master"

fileNew1.UsesMasterModel = "No"

fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item

fileNew1.TemplatePresentationName = "CAD Item"

fileNew1.ItemType = "Al4_CAD"

fileNew1.Specialization = ""

fileNew1.SetCanCreateAltrep(False)

partOperationCreateBuilder1.SetAddMaster(False)

partOperationCreateBuilder1.SetItemType("Al4_CAD")

Dim logicalobjects2() As NXOpen.PDM.LogicalObject
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects2)

Dim sourceobjects4() As NXOpen.NXObject
sourceobjects4 = logicalobjects2(0).GetUserAttributeSourceObjects()

tableEditorDefaultDataProvider1.RowCount = 3

tableEditorDefaultDataProvider1.ColumnCount = 2

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

Dim objects1(0) As NXOpen.NXObject
objects1(0) = logicalobjects2(0)
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.Create)

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.String

attributePropertiesBuilder1.Units = "MilliMeter"

Dim objects2(0) As NXOpen.NXObject
objects2(0) = sourceobjects4(0)
attributePropertiesBuilder1.SetAttributeObjects(objects2)

attributePropertiesBuilder1.Units = "MilliMeter"

theSession.SetUndoMarkName(markId3, "Attributes Dialog")

attributePropertiesBuilder1.DateValue.DateItem.Day = NXOpen.DateItemBuilder.DayOfMonth.Day29

attributePropertiesBuilder1.DateValue.DateItem.Month = NXOpen.DateItemBuilder.MonthOfYear.Jun

attributePropertiesBuilder1.DateValue.DateItem.Year = "2020"

attributePropertiesBuilder1.DateValue.DateItem.Time = "00:00:00"

' ----------------------------------------------
' Dialog Begin Attributes
' ----------------------------------------------
attributePropertiesBuilder1.Title = ""

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.Category = "CAD"

attributePropertiesBuilder1.Title = "DB_PART_NO"

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.LockOnSave = True

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

'attributePropertiesBuilder1.StringValue = "a52016_211CAP110FXZ020000"
attributePropertiesBuilder1.StringValue = cadItemName

Dim markId4 As NXOpen.Session.UndoMarkId
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Add New Attribute From Template")

attributePropertiesBuilder1.ValueAlias = ""

Dim changed1 As Boolean
changed1 = attributePropertiesBuilder1.CreateAttribute()

attributePropertiesBuilder1.Category = ""

attributePropertiesBuilder1.Title = ""

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.LockOnSave = False

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.IsArray = False

Dim markId5 As NXOpen.Session.UndoMarkId
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Attributes")

theSession.DeleteUndoMark(markId5, Nothing)

Dim markId6 As NXOpen.Session.UndoMarkId
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Attributes")

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

theSession.DeleteUndoMark(markId6, Nothing)

theSession.SetUndoMarkName(markId3, "Attributes")

attributePropertiesBuilder1.Destroy()

theSession.DeleteUndoMark(markId4, Nothing)

theSession.DeleteUndoMark(markId3, Nothing)

Dim objects3(0) As NXOpen.NXObject
objects3(0) = logicalobjects2(0)
Dim errorList1 As NXOpen.ErrorList
errorList1 = partOperationCreateBuilder1.AutoAssignAttributes(objects3)

Dim errorList2 As NXOpen.ErrorList
errorList2 = partOperationCreateBuilder1.GetOperationFailures()

Dim markId7 As NXOpen.Session.UndoMarkId
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId7, "Assign to Project Dialog")

' ----------------------------------------------
' Dialog Begin Assign to Project
' ----------------------------------------------
Dim markId8 As NXOpen.Session.UndoMarkId
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Assign to Project")

theSession.DeleteUndoMark(markId8, Nothing)

Dim markId9 As NXOpen.Session.UndoMarkId
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Assign to Project")

theSession.DeleteUndoMark(markId9, Nothing)

theSession.SetUndoMarkName(markId7, "Assign to Project")

theSession.DeleteUndoMark(markId7, Nothing)

Dim markId10 As NXOpen.Session.UndoMarkId
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New Component File")

theSession.DeleteUndoMark(markId10, Nothing)

Dim markId11 As NXOpen.Session.UndoMarkId
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "New Component File")

fileNew1.MasterFileName = ""

fileNew1.MakeDisplayedPart = False

partOperationCreateBuilder1.ValidateLogicalObjectsToCommit()

Dim logicalobjects3(0) As NXOpen.PDM.LogicalObject
logicalobjects3(0) = logicalobjects2(0)
partOperationCreateBuilder1.CreateSpecificationsForLogicalObjects(logicalobjects3)

Dim errorList3 As NXOpen.ErrorList
errorList3 = partOperationCreateBuilder1.GetOperationFailures()

Dim cliNames1(0) As String
'cliNames1(0) = "@DB/%#MFK#%,=item_id=a52016_211CAP110FXZ020000,object_type=Al4_CAD/A"
cliNames1(0) = "@DB/%#MFK#%,=item_id=" & cadItemName & ",object_type=Al4_CAD/A"

Dim objectTypes1(0) As NXOpen.Session.ProjectAssignmentObjectType
objectTypes1(0) = NXOpen.Session.ProjectAssignmentObjectType.Partrev
Dim projectNames1(9) As String
projectNames1(0) = "00_000-MET_LIBRARY"
projectNames1(1) = "10_005-ALTINAY_STANDART_URUN"
projectNames1(2) = "335_02-COMARO_X52"
projectNames1(3) = "501_01-MARTUR_X52"
projectNames1(4) = "502_01-AHLE_COILING"
projectNames1(5) = "520_16-CX482"
projectNames1(6) = "530_04-MBT-KAPAK_HATTI"
projectNames1(7) = "530_05-MBT_ALTYAPI_KAYNAK"
projectNames1(8) = "630_30-TOFAS_356_T3_ON_TRAVERS"
projectNames1(9) = "test_project"
Dim assignmentStates1(9) As NXOpen.Session.ProjectAssignmentState
assignmentStates1(0) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(1) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(2) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(3) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(4) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(5) = NXOpen.Session.ProjectAssignmentState.Full
assignmentStates1(6) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(7) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(8) = NXOpen.Session.ProjectAssignmentState.None
assignmentStates1(9) = NXOpen.Session.ProjectAssignmentState.None
theSession.AssignRemoveProjects(cliNames1, objectTypes1, projectNames1, assignmentStates1)

theSession.DeleteUndoMark(markId11, Nothing)

theSession.SetUndoMarkName(markId2, "New Component File")

tableEditorDefaultDataProvider1.Destroy()

Dim markId12 As NXOpen.Session.UndoMarkId
markId12 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim createNewComponentBuilder1 As NXOpen.Assemblies.CreateNewComponentBuilder
createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder()

'createNewComponentBuilder1.NewComponentName = "A52016_211CAP110FXZ020000"
createNewComponentBuilder1.NewComponentName = cadItemName

createNewComponentBuilder1.ReferenceSet = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentReferenceSetType.EntirePartOnly

createNewComponentBuilder1.ReferenceSetName = "Entire Part"

createNewComponentBuilder1.ComponentOrigin = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Absolute

theSession.SetUndoMarkName(markId12, "Create New Component Dialog")

' ----------------------------------------------
' Dialog Begin Create New Component
' ----------------------------------------------
Dim markId13 As NXOpen.Session.UndoMarkId
markId13 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create New Component")

theSession.DeleteUndoMark(markId13, Nothing)

Dim markId14 As NXOpen.Session.UndoMarkId
markId14 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Create New Component")

createNewComponentBuilder1.NewFile = fileNew1

Dim markId15 As NXOpen.Session.UndoMarkId
markId15 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Create New component")

Dim nXObject2 As NXOpen.NXObject
nXObject2 = createNewComponentBuilder1.Commit()

theSession.DeleteUndoMark(markId14, Nothing)

theSession.SetUndoMarkName(markId12, "Create New Component")

createNewComponentBuilder1.Destroy()

theSession.DeleteUndoMark(markId15, Nothing)

theSession.DeleteUndoMarksUpToMark(markId2, Nothing, False)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Servet Birlik
Automation Engineer

The error message points to line 380, but 380 is a blank line in the code posted above. I assume the issue is coming from this line:

createNewComponentBuilder1.NewFile = fileNew1

The "fileNew1" is a "new file builder", it tries to create a brand new file that did not exist before. If you are intending to create new files, bear in mind that 2 different files cannot share the same ID number in Teamcenter.

If you want to create a new file and add it multiple times in an assembly, I'd suggest recording 2 different journals as a reference. First, record a journal while creating a new file. Second, record a journal while adding an existing part as a component to an assembly. Once you understand what is needed for each individual operation, you can combine them into a single journal, if desired. Create a new file, then add the newly created part one or more times into a given assembly.

Thanks for your suggestion. Creating 2 journal solved my problem.

Servet Birlik
Automation Engineer