John Alexander

Entries in GetAttachedEntityTypes and GetAttachedEntities3 do not correspond

Discussion created by John Alexander on Jun 9, 2017

I'm still working on the macro described in this post: GetVisibleEntities causes crash when type is swViewEntityType_SilhouetteEdge

 

I've implemented a sort of roundabout workaround that was described therein. Now the existence of silhouette edges has introduced a new problem.

 

Part of my macro's functionality is to update existing machine mark annotations so that they agree with the values saved into the face to which they are attached. Those values could change after the annotations are created so it is necessary to traverse all annotations and update their style (single,double, triple nabla).

 

 

This worked fine until I started inserting machine marks on silhouette edges. With marks attached to silhouette edges, I'm getting type mismatch errors.

 

In order to determine which face a machine mark corresponds to, I need to call Annotation::GetAttachedEntities3. This function returns an array of entities. The type of those entities is obtained by calling Entity::GetType on each entity in that array or by calling Annotation::GetAttachedEntityTypes. The latter returns an "Array of longs or integers (see Long vs. Integer) that indicate the attached entity types as defined in swSelectType_e".

 

The bold line in the following function is where "type mismatch" is being thrown. Clearly I am checking whether or not this is an edge before attempting to assign it to swEntity.

 

Public Function getExistingMark(swVisibleEdge As SldWorks.edge, existingMarks As Variant) As SldWorks.SFSymbol

    Dim swAnnotation    As SldWorks.Annotation

    Dim swSFSymbol      As SldWorks.SFSymbol

    Dim swEntity    As SldWorks.Entity

    Dim swEdge      As SldWorks.edge

   

    Dim swAttachedEntityType    As swSelectType_e

   

    Dim vSFSymbol   As Variant

    Dim vAttachedEntityTypes    As Variant

    Dim vAttachedEntity         As Variant

    Dim vAttachedEntities       As Variant

   

    Dim i As Integer

    Dim which_mark As Integer

    Dim oldID As Integer

    Dim newID As Integer

   

   

    oldID = swVisibleEdge.GetID

    newID = oldID + 11

    swVisibleEdge.SetId newID

   

    Set getExistingMark = Nothing

    which_mark = 0

   

    If IsArrayAllocated(existingMarks) Then

        For Each vSFSymbol In existingMarks

            Set swSFSymbol = vSFSymbol

            If Not swSFSymbol Is Nothing Then

                Set swAnnotation = swSFSymbol.GetAnnotation

                vAttachedEntityTypes = swAnnotation.GetAttachedEntityTypes

                vAttachedEntities = swAnnotation.GetAttachedEntities3

                If IsArrayAllocated(vAttachedEntityTypes) And IsArrayAllocated(vAttachedEntities) Then

                    For i = LBound(vAttachedEntityTypes) To UBound(vAttachedEntityTypes)

                       

                        If vAttachedEntityTypes(i) = swSelectType_e.swSelEDGES Then

                            Set swEntity = vAttachedEntities(i)

                            Set swEdge = swEntity

                            If swEdge.GetID = swVisibleEdge.GetID Then

                                Set getExistingMark = swSFSymbol

                                Set existingMarks(which_mark) = Nothing

                                Exit For

                            End If

                        End If

                    Next i

                End If

                If Not getExistingMark Is Nothing Then

                    Exit For

                End If

            End If

            which_mark = which_mark + 1

        Next vSFSymbol

    End If

    swVisibleEdge.SetId oldID

End Function

 

Upon further investigation, I can see that there is no guarantee of correspondence between the types returned by GetAttachedEntityTypes and the type of the objects that are returned by GetAttachedEntities3.

 

a) I would expect this function to always return an array of entities. The fact that there are objects in that returned array that raise a type mismatch when I attempt to assign them to entities would indicate that the function was given the wrong name.

 

b) When the function manages to return actual entities, I would expect the order of entities returned to correspond to the order of types returned by the two aforementioned functions.

Outcomes