Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Renumber Balloons for iLogic

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
stian-j
2936 Views, 7 Replies

Renumber Balloons for iLogic

I want to add the Balloon Renumbering function to our templates using iLogic, but when I run it I get an error message saying: "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))". I have narrowed it down and think it has to do with the following line: partInfo(i - 1).Number = drawBOMRow.Item(itemColumn).Value. When I remove that line I don't get an error message, but every balloon is set to item no 0. The function I want to achieve with the code is to renumber separate part files against the assembly BOM. Anyone have a suggestion on what the error might be? Thanks!

 

    Public Structure udtPartInfo
        Public udNumber As Integer
        Public ReferencedFile As String
    End Structure

    Sub Main()
        Dim drawDoc As DrawingDocument
        drawDoc = ThisApplication.ActiveDocument

        Dim baseSheet As Sheet
        baseSheet = drawDoc.Sheets.Item(1)

        Dim valSet As BalloonValueSet
        valSet = baseSheet.Balloons.Item(1).BalloonValueSets.Item(1)
        Dim drawBOM As DrawingBOM
        drawBOM = valSet.ReferencedRow.Parent
        Dim partInfo() As udtPartInfo
        ReDim partInfo(drawBOM.DrawingBOMRows.Count - 1)

        Dim itemColumn As Integer
        Dim i As Integer
        For i = 1 To drawBOM.DrawingBOMColumns.Count
            If drawBOM.DrawingBOMColumns.Item(i).PropertyType = kItemPartsListProperty Then
               itemColumn = i
                Exit For
            End If
        Next

        For i = 1 To drawBOM.DrawingBOMRows.Count
            Dim drawBOMRow As DrawingBOMRow
            drawBOMRow = drawBOM.DrawingBOMRows.Item(i)

            Dim partDef As PartComponentDefinition
            partDef = drawBOMRow.BOMRow.ComponentDefinitions.Item(1)
            partInfo(i - 1).ReferencedFile = partDef.Document.FullFileName
			partInfo(i - 1).udNumber = drawBOMRow.Item(itemColumn).Value
        Next

        For i = 1 To drawDoc.Sheets.Count
            Dim currentSheet As Sheet
            currentSheet = drawDoc.Sheets.Item(i)

            Dim checkBalloon As Balloon
            For Each checkBalloon In currentSheet.Balloons
                Dim matchFound As Boolean
                matchFound = False
                Dim valueSet As BalloonValueSet
                valueSet = checkBalloon.BalloonValueSets.Item(1)
                Dim checkFilename As String
                checkFilename = valueSet.ReferencedFiles.Item(1).FullFileName

                Dim j As Integer
                For j = 0 To UBound(partInfo)
                    If checkFilename = partInfo(j).ReferencedFile Then
                        matchFound = True
                        If valueSet.ItemNumber <> partInfo(j).udNumber Then
                           valueSet.OverrideValue = partInfo(j).udNumber
                        End If
                        Exit For
                    End If
                Next
            Next
        Next
    End Sub

 

7 REPLIES 7
Message 2 of 8
MjDeck
in reply to: stian-j

Here's a modified version of your rule in the attached file RenumberBalloons.txt.  The main change required was to use PropertyTypeEnum.kItemPartsListProperty instead of just kItemPartsListProperty.  When you convert a VBA macro to iLogic (or VB.NET), you have to specify the Enum type for any Inventor API Enum constants.

 I also changed the type of udNumber to String instead of Integer.  This may not be required for your drawings, but it would help the rule to work with dotted item numbers such as 2.1.


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 8
stian-j
in reply to: MjDeck

Works great, THANK YOU!

Message 4 of 8
TONELLAL
in reply to: stian-j

Hello,

I tried it on Inventor 2012, I have this error :

 

Impossible d'effectuer un cast d'un objet COM de type 'System.__ComObject' en type d'interface 'Inventor.PartComponentDefinition'. Cette opération a échoué, car l'appel QueryInterface sur le composant COM pour l'interface avec l'IID '{DA33F1A3-7C3F-11D3-B794-0060B0F159EF}' a échoué en raison de l'erreur suivante : Cette interface n’est pas prise en charge (Exception de HRESULT : 0x80004002 (E_NOINTERFACE)).

 

The error seems to be from this line :

partDef = drawBOMRow.BOMRow.ComponentDefinitions.Item(1)

Perhaps a difference between Inventor versions ?

Message 5 of 8
MjDeck
in reply to: TONELLAL

Try replacing the line:
Dim partDef As PartComponentDefinition
with:
Dim partDef As ComponentDefinition

That should work.  There doesn't seem to be a need to work with parts specifically at that point in the code.


Mike Deck
Software Developer
Autodesk, Inc.

Message 6 of 8
TONELLAL
in reply to: MjDeck

Ok, there is is no error any more... but... what it is supposed to do ? I see nothing...

Message 7 of 8
MjDeck
in reply to: TONELLAL

The rule was converted from the VBA source in this Mod the Machine post:
http://modthemachine.typepad.com/my_weblog/2011/02/index.html
In subassembly views, the balloon numbers of components may be different than in the top-level assembly view. This program will renumber a balloon in other views if it finds the same component in the top-level view.


Mike Deck
Software Developer
Autodesk, Inc.

Message 8 of 8
DeerSpotter
in reply to: MjDeck

iLogic Rule Error in rule: Balloon Renumber, in document: Balloon Renumber.iLogicVb

Public member 'ItemNumber' on type 'BalloonValueSet' not found.

 

any help please?

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................


See My LinkedIn Profile

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report