Get the GUID of each occurrence

Get the GUID of each occurrence

peter_ensingT5HML
Explorer Explorer
994 Views
5 Replies
Message 1 of 6

Get the GUID of each occurrence

peter_ensingT5HML
Explorer
Explorer

Hello all!

I'm trying to find the GUID or other unique string of each occurrence (VBA).

For example this assembly: 
Test_codes.iam
  Test_codes_P002:2
  Test_codes_P001:1
  Test_codes_P001:2
  Test_codes_P001:3
  Test_codes_P002:4
  Test_codes_P002:5

Every occurrence has a unique DisplayName.
So if I have occurrence Test_codes_P002:2 is there also a unique GUID or similar string connected to this occurrence that is different from the parent part itself?

So far I've been searching in locals at VBA but can only find strings that reflect the parent part.

Anyone know if there is a unique string per occurrence?

0 Likes
Accepted solutions (1)
995 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

I'm not sure what you try to accomplish but this will print out a unique string for each occurrence. (Btw this is done in iLogic. Plz, be aware that VBa is obsolete. Have a look at this blog post "Is VBA in Inventor obsolete?".)

If you need more than just a name have a look at reference keys.

Public Sub main()

    Dim doc As AssemblyDocument = ThisDoc.Document

    ListOccurences(String.Empty, doc.ComponentDefinition.Occurrences)

End Sub

Public Sub ListOccurences(parentName As String, occs As ComponentOccurrences)
    For Each occ As ComponentOccurrence In occs

        If (String.IsNullOrEmpty(parentName)) Then
            logger.Info(occ.Name)
        Else
            logger.Info(parentName & "\" & occ.Name)
        End If


        If (TypeOf occ.Definition Is AssemblyComponentDefinition) Then
            ListOccurences(occ.Name, occ.Definition.Occurrences)
        End If
    Next
End Sub

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 6

Frederick_Law
Mentor
Mentor
Message 4 of 6

peter_ensingT5HML
Explorer
Explorer

Thanks both for replying.
@JelteDeJong 
The link to refkeys is perfect.

I've already seen that post before but didnt know what to do with it that time.

Reading through it again this time it all make sense 🙂 


@Frederick_Law 
Yeah there is a code to retrieve the GUID or internal name of a part and writes it to custom iProperties.
But the thing is, the GUID is only made when you start a new part or assembly.
The moment you copy a part or assembly with "Save As" the GUID is also copied...
So that makes the GUID and internal name useless to refer to if you need unique referrences.

Also I agree with you that an Occurrence itself has no own GUID or internal name, it'll always refer to the "parent" part GUID or assembly GUID.

0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Hi @peter_ensingT5HML.  Just dropping a couple more ideas into your head about ways to 'control' identification between different components in an assembly, besides their names.  Have you considered the new 'instance properties' (ComponentOccurrence.OccurrencePropertySets).  When enabled (ComponentOccurrence.OccurrencePropertySetsEnabled), there is just 1 PropertySet within (the 'custom' set "Inventor User Defined Properties"), and there are no properties until you create them.  I know this is not exactly ideal, because it may be possible for you to have 2 (or more) components with them enabled, have a property with the same name, and the same value, but they were designed to give us more independent control over assembly components.  The other idea, using the ComponentOccurrence.AttributeSets , is similar to the Reference Keys idea, but a bit more basic, and maybe a bit easier to work with.  You could use a custom routine/utility to add specifically named AttributeSet and specifically named Attribute to the component, in which you can specify data type, and some sort of unique value (maybe something generated).  Just a couple more ideas to play around with.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6

peter_ensingT5HML
Explorer
Explorer

@WCrihfield, thanks for bringing this up!
I already did some testing with instance properties and they work oke for the model and coding.
Unfortunately they cant be exported to DWF at the moment, hope Autodesk will make it possible someday.
Always good to have many ideas in one post for others to read when searching, so thanks for posting.

0 Likes