niedzviedz
Mechanical
- Apr 1, 2012
- 307
Hello. I need journal which automatically adds Order number to each parts in assembly and sub assemblies.
What I have done for now, I create code which works, but:
[ul]
[li]only on parts in main assembly gets value. I would like improve it to sets the same value to all parts[/li]
[Li]when I set part as work part, journal doesn't work. I would like improve code to automatically set main assembly as work part[/li]
[Li]I set properties to "apply to part", but it doesn't automatic set to "apply to component" and apply to "instance"[/li]
[/ul]
Below Is my code:
Can anyone can help me?
With best regards
Michael
What I have done for now, I create code which works, but:
[ul]
[li]only on parts in main assembly gets value. I would like improve it to sets the same value to all parts[/li]
[Li]when I set part as work part, journal doesn't work. I would like improve code to automatically set main assembly as work part[/li]
[Li]I set properties to "apply to part", but it doesn't automatic set to "apply to component" and apply to "instance"[/li]
[/ul]
Below Is my code:
Code:
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Public theSession As Session = Session.GetSession()
Dim blnCancel As Boolean = False
Sub Main()
Dim workpart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
Dim assm As Assemblies.Component = workpart.ComponentAssembly.RootComponent
Dim comp as component
Dim children() As Assemblies.Component = assm.GetChildren
Dim Order As String
Order = InputBox("Enter Order number:", "Order Number", "14/xxxx")
If Order = "14/xxxx" Then
'user pressed cancel
blnCancel = True
Exit Sub
End If
If UBound(children) > -1 Then
For Each obj As Assemblies.Component In children
Try
Dim objects(0) As NXObject
objects(0) = obj
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
Dim assembliesParameterPropertiesBuilder1 As Assemblies.AssembliesParameterPropertiesBuilder
attributePropertiesBuilder1 = workpart.PropertiesManager.CreateAttributePropertiesBuilder(objects)
attributePropertiesBuilder1.ObjectPicker =
AttributePropertiesBaseBuilder.ObjectOptions.ComponentAsPartAttribute
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = "Zlecenie"
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.StringValue = order.ToString.PadLeft(3, "0"c)
Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
attributePropertiesBuilder1.Destroy()
Catch ex As NXException
If ex.ErrorCode = 512008 Then
'add code to handle error
Else
MsgBox(ex.ErrorCode & ": " & ex.Message)
'code to handle other error
End If
End Try
Next
End If
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module
Can anyone can help me?
With best regards
Michael