Submitted by infc011 on Fri, 05/01/2020 - 04:56
Forums:
Hello
I have a user attribute that is synced with Teamcenter. If I try to set it via script it doesn't create it, even tho the documentation says it should:
workPart.SetUserAttribute("MD_DIMENSION", -1, "123", Update.Option.Now)
But if I set it via TeamCenter I'm able to update it via this function.
Am I missing something? How can I set this attribute even if it wasn't set before?
re: SetUserAttribute
If you set the attribute in NX using interactive commands (not using the script), does the attribute get set? If yes, then there is something wrong with the script. If no, then the attribute is controlled by TC.
I figured out that the
I figured out that the problem isn't setting the attribute, but saving as a new file. I tested this in the newest NX version and there I can set the Attribute, save As and also have it in the new part. But my save function I recorded in the last NX version doesn't do this for some reason:
Sub save_part(name, boxIdentNumber, formatNumber, machineNumber)
Dim databaseAttributeManager As PDM.DatabaseAttributeManager
Dim partFromPartBuilder As NXOpen.PDM.PartFromPartBuilder = theSession.Parts.PDMPartManager.NewPartFromPartBuilder()
partFromPartBuilder.CreatePartSpec("Item", Nothing, Nothing, "master", "")
databaseAttributeManager = partFromPartBuilder.NewDatabaseAttributeManager()
databaseAttributeManager.SetAttribute("DB_PART_NAME", name) 'Dateinamen in Teamcenter pflegen
databaseAttributeManager.StoreAttributes()
databaseAttributeManager.Dispose()
partFromPartBuilder.CreateNonmasterList()
partFromPartBuilder.DependentFileSaveAsOption = NXOpen.PDM.PartFromPartBuilder.FileSaveAs.Some
partFromPartBuilder.Commit()
partFromPartBuilder.Dispose()
End Sub
So I recorded saving as in the new NX version and its way longer. How can I simplify this?
Dim partOperationCopyBuilder1 As NXOpen.PDM.PartOperationCopyBuilder = theSession.PdmSession.CreateCopyOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.SaveAs)
partOperationCopyBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCopyBuilder.OperationSubType.Default)
partOperationCopyBuilder1.DefaultDestinationFolder = ":"
partOperationCopyBuilder1.DependentFilesToCopyOption = NXOpen.PDM.PartOperationCopyBuilder.CopyDependentFiles.All
partOperationCopyBuilder1.ReplaceAllComponentsInSession = True
partOperationCopyBuilder1.SetDialogOperation(NXOpen.PDM.PartOperationBuilder.OperationType.Revise)
Dim selectedparts1(0) As NXOpen.BasePart
selectedparts1(0) = workPart
Dim failedparts1() As NXOpen.BasePart
partOperationCopyBuilder1.SetSelectedPartsToCopy(selectedparts1, failedparts1)
partOperationCopyBuilder1.SetDialogOperation(NXOpen.PDM.PartOperationBuilder.OperationType.SaveAs)
Dim selectedparts2(0) As NXOpen.BasePart
selectedparts2(0) = workPart
Dim failedparts2() As NXOpen.BasePart
partOperationCopyBuilder1.SetSelectedPartsToCopy(selectedparts2, failedparts2)
Dim logicalobjects2() As NXOpen.PDM.LogicalObject
partOperationCopyBuilder1.CreateLogicalObjects(logicalobjects2)
Dim sourceobjects7() As NXOpen.NXObject
sourceobjects7 = logicalobjects2(0).GetUserAttributeSourceObjects()
Dim attributetitles1(0) As String
attributetitles1(0) = "DB_PART_NO"
Dim titlepatterns1(0) As String
titlepatterns1(0) = "NNNNNNN"
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = partOperationCopyBuilder1.CreateAttributeTitleToNamingPatternMap(attributetitles1, titlepatterns1)
Dim nullNXOpen_BasePart As NXOpen.BasePart = Nothing
Dim objects2(-1) As NXOpen.NXObject
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder = theSession.AttributeManager.CreateAttributePropertiesBuilder(nullNXOpen_BasePart, objects2, NXOpen.AttributePropertiesBuilder.OperationType.None)
Dim objects3(-1) As NXOpen.NXObject
attributePropertiesBuilder1.SetAttributeObjects(objects3)
Dim objects4(0) As NXOpen.NXObject
objects4(0) = sourceobjects7(0)
attributePropertiesBuilder1.SetAttributeObjects(objects4)
attributePropertiesBuilder1.Title = "DB_PART_NAME"
attributePropertiesBuilder1.Category = "Item"
attributePropertiesBuilder1.StringValue = "New_Name"
attributePropertiesBuilder1.CreateAttribute()
partOperationCopyBuilder1.ValidateLogicalObjectsToCommit()
partOperationCopyBuilder1.Commit()
partOperationCopyBuilder1.Destroy()
attributePropertiesBuilder1.Destroy()
theSession.CleanUpFacetedFacesAndEdges()
Is there a way to update the old function so it works with updating the Attribute?