在下面的代码中,我获得了唯一的{
"YELLOW":{
"Count":124,
"pop":1
},
"BLACK":{
"Count":124,
"pop":1
},
"BLUE":{
"Count":124,
"pop":1
}
}
部件名称,但在workPart
这种情况下,还将处理所有重复的部件。即我得到重复的行作为输出。
If density <> 7830640 Then
当前结果:
Dim j As Integer = 0
Dim PartDictionary As New Dictionary(Of String, Integer)
For Each workPart In parts
theSession.Parts.SetWork(workPart)
j += 1
If Not PartDictionary.ContainsKey(workPart.Name) Then
PartDictionary.Add(workPart.Name, j)
bodies = GetBodiesInReferenceSet("MODEL")
Dim attributeName As String = "Material"
Dim attributeInfo As NXObject.AttributeInformation
'lw.WriteLine("Unique part names:" & workPart.Name) ''' Unique component names are printed but in below code, all instances are processed
For Each b In bodies
ufs.Modl.AskBodyDensity(b.Tag, UFModl.DensityUnits.KilogramsMeters, density)
If density = 0 Then
If Not theSession.Parts.Work Is Nothing Then
lw.WriteLine("change body density from 0 to 1")
ufs.Modl.SetBodyDensity(b.Tag, UFModl.DensityUnits.KilogramsMeters, 1.0)
End If
Else
If density <> 7830640 Then
''' http://nxjournaling.com/content/part-attribute
If workPart.HasUserAttribute(attributeName, NXObject.AttributeType.String, 0) Then ''' This evaluates to False, why???
attributeInfo = workPart.GetUserAttribute(attributeName, NXObject.AttributeType.String, 0)
lw.WriteLine("Part: " & workPart.name & "-> body density: " & density & " kg/m3 | " & attributeInfo.StringValue)
Else
attributeInfo = workPart.GetUserAttribute(attributeName, NXObject.AttributeType.String, 0)
lw.WriteLine("Part: " & workPart.name & "-> body density: " & density & " kg/m3")
End if
End If
End If
Next
End If
Next
预期结果:
Part: wav3_pkg_battery_latch-> body density: 7830.64 kg/m3
Part: wav3_pkg_battery_latch_spring-> body density: 7830.64 kg/m3
Part: wav3_pkg_battery_latch_spring-> body density: 7830.64 kg/m3