Inventor General Discussion

Inventor General Discussion

Posts: 23
Registered: ‎07-09-2010
Message 1 of 5 (2,997 Views)

iLogic Assembly Component Occurrence Definition

2997 Views, 4 Replies
09-28-2012 11:49 AM



I have a simple code below trying to iterate through all the assembly component and copy the iProperties > Occurrece Name (i.e. "Part1:1") and paste it to iProperties > Project tab > Part Number field for each individual part in assembly.


' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
    Dim oName As String
    oName = oOccurrence.Name
    iProperties.Value(oOccurrence.Name, "Project", "Part Number") = oName
    MessageBox.Show(oOccurrence.Name, "iLogic")


The Debug message shows the correct output for every iteration, but when I check each part's properties they all have the Occurrence Name of the last part in the aseembly.


I am obivously doing something wrong with the code, but I can't get my head around it at the moment and was hoping someone could help me.


Many thanks,


*Expert Elite*
Posts: 3,002
Registered: ‎03-08-2006
Message 2 of 5 (2,948 Views)

Re: iLogic Assembly Component Occurrence Definition

10-01-2012 08:29 AM in reply to: vampelas

Hi vampelas,


I took just a moment to test the code as written and it seemed to work as expected. I can't offer much of a guess as to why you were seeing different results, but you might try testing it on a new simple assembly to see if it works.


I hope this helps.
Best of luck to you in all of your Inventor pursuits,

  solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

Posts: 23
Registered: ‎07-09-2010
Message 3 of 5 (2,936 Views)

Re: iLogic Assembly Component Occurrence Definition

10-01-2012 03:01 PM in reply to: Curtis_Waguespack

Hi Curtis,


Thank you for prompt resonse!


The assembly I am actually trying this is a basic assy template with multiple instaces \ occurrences of the same .ipt file... Maybe that's where the problem is, not sure .


It seems to iterate through the part occurrences properly, but eveytime it copies the iproperty value, it copies it to all the occurrence at once for however many times it iterates.


I hope this makes some sense...


Best Regards,


Posts: 23
Registered: ‎07-09-2010
Message 4 of 5 (2,917 Views)

Re: iLogic Assembly Component Occurrence Definition

10-02-2012 09:28 AM in reply to: Curtis_Waguespack



I think I've answered my own question there, because even in the assembly environment, when I try and change an iProperty of one of the part occurrences (i.e.. Part1:4), that iProperty value gets copied to all the Part occurrences in the assembly. Unless there is a particular code that will give me access to just one of the occurrence properties then I don't think this is possible.


I also failed to explain my initial issue properly the first time. My initial reason behind this code comes a customer support request... The customer has a lot of DWG drawings with views of an assembly, and within that assembly there are multiple instances of Parts (i.e.. Part1:1, Part1:2, ... , Part7).


The customer is then using the Auto-Balloon command to annotate those parts, with "Ignore Multiple Instances" option activated. And wants the Balloon text to show the Part name as shown in the Model Browser ((i.e.. Part1:1) to indicate the Occurrence number after the name.


My initial thought was trying the Inventor Style Manager > Dimensions > ISO Balloons and see which properties from the drawing and model can be tagged on the balloons.


This didn't really help, one because there was no property available that would accommodate that, and moreover because the way I see it, the Balloons take information from the Drawing file and the BOM table of the model, and not from the Model directly.


And also when you Auto-Balloon, by box selecting all parts in the view, the placement of Balloons does not start with Part1:1 for example, which makes it difficult to relate to the assembly information though vba or iLogic code.


In any case, I have developed the VBA code below so the user can add and add and run this  through his ribbon button. With a major disadvantage to the code, in that when the user performs an Auto-balloon annotation command and is about to select the Components, he needs to hold Ctrl button and select every part occurrence from the Model Browser individually and in a Decremental order (i.e..: Part1:7, Part1:6, ... , Part1:1) in order for the appropriate balloon text values to be overridden with the Occurrence names for the appropriate part.


I hope this makes some sense... I haven't got much experience with VBA code to be honest, but I enjoy playing around with Inventor API, and was hoping someone could check through this case and give some advise. Many thanks in advanced!


Sub UpdateBalloons()

' Set a reference to the Drawing Document.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the the Full File Name of the Drawing.
Dim oFullFileName As String
oFullFileName = oDrawDoc.FullFileName

' Set a reference to the Full File name of the drawing,
' remove ".dwg" from name, and add ".iam" extension.
Dim oAsmName As String
oAsmName = Left(oFullFileName, Len(oFullFileName) - 4) & ".iam"

' Set Reference to the Assembly and Open Silently
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.Documents.Open(oAsmName, False)

' Set a reference to the assembly component definintion.
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = oAsmDoc.ComponentDefinition

' Set reference to Balloon Counter
Dim BalloonCount As Long
' Set Ballon Counter to 1
BalloonCount = 1

' Iterate through all of the Part Occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences

    ' Set Reference to Occurrence Name
    Dim oOccName As String
    oOccName = oOccurrence.Name
    ' Set Reference to Part Document
    Dim invPart As Document
    Set invPart = oOccurrence.Definition.Document

    ' Set Reference to Part's iProperies
    Dim oPropertySet As PropertySet
    Set oPropertySet = invPart.PropertySets.Item("Design Tracking Properties")
    ' Set Reference to Part's iProperty "Part Number"
    Dim oPartNumber As Property
    Set oPartNumber = oPropertySet.Item("Part Number")
    ' Set Value of "Part Number" iProperty to Occurrence Name
    oPartNumber.Value = oOccName
    ' Set Reference to Active Sheet
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    ' Set Reference to Ballon in sheet
    Dim oBalloon As Balloon
    Set oBalloon = oSheet.Balloons.Item(BalloonCount)
    ' Set Balloon stype to Hexagon
    oBalloon.SetBalloonType (kHexagonBalloonType)

    ' Set Reference to Ballon Set within Sheet
    Dim oBalloonValueSet As BalloonValueSet
    ' Iterate through all the balloons in sheet
    For Each oBalloonValueSet In oBalloon.BalloonValueSets
        ' Override Balloon text with Occurrence Name
        oBalloonValueSet.OverrideValue = oOccName
    ' Increase Balloon Counter by 1 within For loop
    BalloonCount = BalloonCount + 1

oAsmDoc.Close (True)
End Sub


Best Regards,



Active Contributor
Posts: 43
Registered: ‎10-11-2010
Message 5 of 5 (2,724 Views)

Re: iLogic Assembly Component Occurrence Definition

12-04-2012 07:28 AM in reply to: vampelas

Is there anyway to make this code loop through sub assemblies?




Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.