Hi,
I would like to save the current material of all bodies (max. 5) in one part. After doing this I will delete assignment and local material, and then reasign the material to the bodies. Reason is some change of material handling in NX1899.
For deleting the assignment und local material I have a working code. So next (first) step is to save the material-information of each body in part, to reassign it later.
I have tried this code for test:
Dim bodyStr() as String
Dim i as integer = -1
For Each tempBody As Body In workPart.Bodies
i += 1
lw.WriteLine("body tag: " & tempBody.Tag.ToString)
bodyStr(i) = tempBody.Tag.ToString
lw.WriteLine("Nummer:" & i)
lw.WriteLine("Body:" & bodyStr(i))
Next
But I only get some errors:
System.NullReferenceException: The object reference was not set to an object instance.
Can someone help me?
Thanks
Michael
re: bodyStr()
When "bodyStr()" is declared, it is an empty array with no dimensions. Normally, you would dimension the array at the time it is declared. If you need to add elements later, you can use the ReDim statement to resize the array.
Alternatively, I'd suggest using a list instead of an array. A list provides all the functionality of an array, but is easier to use. Using a list, your code would look something like this:
'Add the import statement to the top of your code
Imports System.Collections.Generic
Dim bodyStr as New List(of String)
Dim i as integer = -1
For Each tempBody As Body In workPart.Bodies
i+=1
lw.WriteLine("body tag: " & tempBody.Tag.ToString)
bodyStr.Add(tempBody.Tag.ToString)
lw.WriteLine("Nummer:" & i)
lw.WriteLine("Body:" & bodyStr.Item(i))
Next
re: bodyStr()
Hi,
I have also tried to use a list, but I didn´t know how to extract single Items from it. Know I now it. So I can try it when I´m back in my Home Office.
Thank you!