I am creating an addin to add the area of selected faces in an assembly to get the square meterage for painting.
The addin works but to make it a bit more user friendly i would like keep a track of the faces selected so that there is no duplication. I want to use the reference keys for the faces selected to achieve this however the reference keys are identicle for a number of faces.
I am using a collection to save the reference keys and String.Compare to compare the selected face with the collection.
Why are the reference keys the same for different faces?
Public Global_SelectedFace As New Collection
Public Global_AreaTotal As Double
Private Sub oSelect_OnSelect(ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, _
ByVal SelectionDevice As Inventor.SelectionDeviceEnum, _
ByVal ModelPosition As Inventor.Point, _
ByVal ViewPosition As Inventor.Point2d, _
ByVal View As Inventor.View) Handles oSelect.OnSelect
If TypeOf JustSelectedEntities.Item(1) Is Inventor.Face Then
Dim I As Integer
Dim oFace As Face
Dim sFace As String
Dim bool As Boolean = True
Dim bKey() As Byte = New Byte() {}
Dim oAssm As Inventor.AssemblyDocument
oAssm = ThisApplication.ActiveDocument
Dim oRefKeyManager As ReferenceKeyManager
oRefKeyManager = oAssm.ReferenceKeyManager
' Get the key context
' Calling this method is a must
Dim nKeyCont As Integer
nKeyCont = oRefKeyManager.CreateKeyContext()
oFace = JustSelectedEntities.Item(1)
oFace.GetReferenceKey(bKey, nKeyCont)
sFace = oRefKeyManager.KeyToString(bKey)
If Global_SelectedFace.Count > 0 Then
For I = 1 To Global_SelectedFace.Count
If String.Compare(sFace, Global_SelectedFace(I)) = 0 Then
bool = False
Exit For
End If
Next
If bool Then
'Save the key and add the area of this face
Global_SelectedFace.Add(sFace)
Global_AreaTotal = Global_AreaTotal + JustSelectedEntities.Item(1).Evaluator.Area
Else
MsgBox("This face has already been selected.")
End If
Else
'Save the key and add the area of this the first face
Global_SelectedFace.Add(sFace)
Global_AreaTotal = Global_AreaTotal + JustSelectedEntities.Item(1).Evaluator.Area
End If
End If
End Sub
I'm sorry to be a pain but can anyone help with my problem? As i understand it reference keys should be unique for each face so why is my code comming up with the sane key for different faces? Has it got something to do with assemblies or my method of comparing the keys?
Thanks in advance
Malcolm
Hi Big_Mack
I recommend you to use property InternalName to compare. That property you can find in PartDocument.ComponentDefinition.SurfaceBodies(1).Faces(Y).InternalName
Y=1...number of faces.
Regards,
Nedeljko.
Hi Nedeljko
Thanks for the sugestion it is better than I had but multiple faces bo turn up in the assembly because a part can be present more than once. However I may be able to multiply the face area by the number of parts now there is consistency to the duplication.
Regards Malcolm