jiloebel
Mechanical
- Aug 7, 2012
- 14
All,
I currently have a .vb journal program (not written by me) that takes one attribute value (DB_Sequence_No) and sets it to another attribute value (Callout). This journal worked great in NX 6, but after upgrading to NX 8.0.3, the attribute is set using "Apply to Occurrence in Assembly". For some reason, attributes applied to occurrence in assembly do not sync with teamcenter, resulting in the attributes being lost after re-opening the part. Applying attributes to component instances DOES sync the callout to Teamcenter.
I am trying to modify this program to apply the attributes to component instance rather than occurrence in assembly.
After looking through the programming help files, I can not find any way to use obj.SetAttribute to apply to component instance, however, I have found that the AttributePropertiesBaseBuilder.ObjectOptions.ComponentInstance may do what I want. Knowing that, I have this code that does not cause an error, but also doesn't work.
I'm not very experienced with visual basic programming, so any help you guys can offer on setting attributes to component instances would be great!
I currently have a .vb journal program (not written by me) that takes one attribute value (DB_Sequence_No) and sets it to another attribute value (Callout). This journal worked great in NX 6, but after upgrading to NX 8.0.3, the attribute is set using "Apply to Occurrence in Assembly". For some reason, attributes applied to occurrence in assembly do not sync with teamcenter, resulting in the attributes being lost after re-opening the part. Applying attributes to component instances DOES sync the callout to Teamcenter.
I am trying to modify this program to apply the attributes to component instance rather than occurrence in assembly.
Code:
Option Strict Off
Imports System
Imports NXOpen
Module NXJournal
Sub Main()
Dim attributesetter As AttributePropertiesBaseBuilder
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim workpart As part = thesession.parts.work
Dim assm As assemblies.component = workpart.ComponentAssembly.RootComponent
Dim children() As assemblies.component = assm.getchildren
Dim callout As String
Dim seq_num As Integer
If UBound(children) > -1 Then
For Each obj As Assemblies.Component In children
Try
seq_num = obj.getstringattribute("DB_SEQUENCE_NO")
If CType(seq_num, Integer) < 10 Then
OBJ.SETATTRIBUTE("CALLOUT", "00" & CType(seq_num, String))
ElseIf CType(seq_num, Integer) < 100 Then
OBJ.SETATTRIBUTE("CALLOUT", "0" & CType(seq_num, String))
ElseIf CType(seq_num, Integer) < 10000 Then
OBJ.SETATTRIBUTE("CALLOUT", CType(seq_num, String))
End If
Catch
End Try
Next
End If
End Sub
End Module
After looking through the programming help files, I can not find any way to use obj.SetAttribute to apply to component instance, however, I have found that the AttributePropertiesBaseBuilder.ObjectOptions.ComponentInstance may do what I want. Knowing that, I have this code that does not cause an error, but also doesn't work.
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Module NXJournal
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim attributesetter As AttributePropertiesBaseBuilder
Dim workpart As part = thesession.parts.work
Dim assm As assemblies.component = workpart.ComponentAssembly.RootComponent
Dim children() As assemblies.component = assm.getchildren
Dim callout As String
Dim seq_num As Integer
Dim calloutcheck As String
If UBound(children) > -1 Then
For Each obj As Assemblies.Component In children
Try
list.add(obj)
seq_num = obj.getstringattribute("DB_SEQUENCE_NO")
attributesetter.ObjectPicker = AttributePropertiesBaseBuilder.ObjectOptions.ComponentInstance
attributesetter.Title = "Callout"
attributesetter.IsArray = "false"
attributesetter.StringValue = seq_num
End Try
Next
End If
End Sub
End Module
I'm not very experienced with visual basic programming, so any help you guys can offer on setting attributes to component instances would be great!