Hi,
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
Next
' Increase Balloon Counter by 1 within For loop
BalloonCount = BalloonCount + 1
Next
oAsmDoc.Close (True)
End Sub
Best Regards,
Vas