• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor Customization

    Reply
    Contributor
    stian-j
    Posts: 19
    Registered: ‎10-27-2010
    Accepted Solution

    Renumber Balloons for iLogic

    605 Views, 7 Replies
    09-01-2011 03:54 AM

    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

     

    Please use plain text.
    Employee
    Posts: 932
    Registered: ‎02-24-2009

    Re: Renumber Balloons for iLogic

    09-08-2011 11:24 AM 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
    DLS - Mechanical Design
    Autodesk, Inc.

    Please use plain text.
    Contributor
    stian-j
    Posts: 19
    Registered: ‎10-27-2010

    Re: Renumber Balloons for iLogic

    09-08-2011 10:26 PM in reply to: MjDeck

    Works great, THANK YOU!

    Please use plain text.
    Distinguished Contributor
    Posts: 121
    Registered: ‎01-17-2010

    Re: Renumber Balloons for iLogic

    01-21-2013 09:35 AM 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 ?

    Please use plain text.
    Employee
    Posts: 932
    Registered: ‎02-24-2009

    Re: Renumber Balloons for iLogic

    01-21-2013 05:20 PM 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
    DLS - Mechanical Design
    Autodesk, Inc.

    Please use plain text.
    Distinguished Contributor
    Posts: 121
    Registered: ‎01-17-2010

    Re: Renumber Balloons for iLogic

    01-23-2013 09:22 AM in reply to: MjDeck

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

    Please use plain text.
    Employee
    Posts: 932
    Registered: ‎02-24-2009

    Re: Renumber Balloons for iLogic

    01-24-2013 07:55 AM 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
    DLS - Mechanical Design
    Autodesk, Inc.

    Please use plain text.
    Contributor
    Posts: 54
    Registered: ‎04-01-2013

    Re: Renumber Balloons for iLogic

    05-22-2013 05:23 AM 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?

    Please use plain text.