Inventor Customization

Inventor Customization

Reply
Contributor
stian-j
Posts: 19
Registered: ‎10-27-2010
Message 1 of 8 (1,518 Views)
Accepted Solution

Renumber Balloons for iLogic

1518 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

 

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.

Employee
MjDeck
Posts: 959
Registered: ‎02-24-2009
Message 2 of 8 (1,490 Views)

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.

Contributor
stian-j
Posts: 19
Registered: ‎10-27-2010
Message 3 of 8 (1,481 Views)

Re: Renumber Balloons for iLogic

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

Works great, THANK YOU!

Mentor
TONELLAL
Posts: 162
Registered: ‎01-17-2010
Message 4 of 8 (1,079 Views)

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 ?

Employee
MjDeck
Posts: 959
Registered: ‎02-24-2009
Message 5 of 8 (1,069 Views)

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.

Mentor
TONELLAL
Posts: 162
Registered: ‎01-17-2010
Message 6 of 8 (1,043 Views)

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...

Employee
MjDeck
Posts: 959
Registered: ‎02-24-2009
Message 7 of 8 (1,027 Views)

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.

Distinguished Contributor
m.teleguz1
Posts: 193
Registered: ‎04-01-2013
Message 8 of 8 (938 Views)

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?

Image and video hosting by TinyPic
..........................................................................................................................
Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
..........................................................................................................................
Privacy warning: Since I live in a country that has traded liberty for the illusion of security, all of your posts to me are being monitored and saved by the United States Government.


See My LinkedIn Profile
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
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.