Balloon update

Balloon update

CADMonkey4Life
Enthusiast Enthusiast
1,688 Views
5 Replies
Message 1 of 6

Balloon update

CADMonkey4Life
Enthusiast
Enthusiast

Got this snippet for code from a friend that said they used it to update the balloon number thru all the sheets in a drawing document to follow the part list on the first sheet.

This is usefull for ex. steel drawings where the customer wants the assembly on first sheet and the parts on the following sheets.

But I get an error men trying to copy paste it into an ilog rule.

 

Any smart ppl out there that can have a look at this?

 

' User-defined type used in the code code below.
Private Type udtPartInfo
   Number As Integer
   ReferencedFile As String
End Type


Public Sub RenumberBalloonsToFirstSheet()
   ' Get the active drawing document.
   If ThisApplication.ActiveDocumentType <> _
                                         kDrawingDocumentObject Then
      MsgBox "A drawing must be active."
      Exit Sub
   End If
 
   Dim drawDoc As DrawingDocument
   Set drawDoc = ThisApplication.ActiveDocument
   
   ' Get the first sheet
   Dim baseSheet As Sheet
   Set baseSheet = drawDoc.Sheets.Item(1)
   
   ' Get the drawing BOM from a balloon.  An assumption is that
   ' there is only one assembly represented on the sheet since
   ' this is arbitrarily using the BOM data of assembly associated
   ' with the first balloon found.
   Dim valSet As BalloonValueSet
   Set valSet = baseSheet.Balloons.Item(1).BalloonValueSets.Item(1)
   Dim drawBOM As DrawingBOM
   Set drawBOM = valSet.ReferencedRow.Parent
   Dim partInfo() As udtPartInfo
   ReDim partInfo(drawBOM.DrawingBOMRows.Count - 1)
  
   ' Determine which column contains the item number information.
   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
      Set drawBOMRow = drawBOM.DrawingBOMRows.Item(i)

      ' Get the filename of the file associated with this
      ' row of the BOM.
      Dim partDef As PartComponentDefinition
      Set partDef = drawBOMRow.BOMRow.ComponentDefinitions.Item(1)
      partInfo(i - 1).ReferencedFile = partDef.Document.FullFileName
     
      ' Get the part number from the drawing BOM.  This could
      ' be different than the assembly BOM since it can be
      ' overridden in the drawing.
      partInfo(i - 1).Number = drawBOMRow.Item(itemColumn).Value
   Next
   
   ' Iterate through the other sheets setting the balloon values
   ' to match these. If a balloon to a new part is found it will
   ' be set to the next highest value so all parts have unique
   ' balloon values.
   For i = 2 To drawDoc.Sheets.Count
      Dim currentSheet As Sheet
      Set currentSheet = drawDoc.Sheets.Item(i)

      ' Look through the balloons on this sheet.
      Dim checkBalloon As Balloon
      For Each checkBalloon In currentSheet.Balloons
         ' Initialize the flag indicating a match was found.
         Dim matchFound As Boolean
         matchFound = False
         Dim valueSet As BalloonValueSet
         Set valueSet = checkBalloon.BalloonValueSets.Item(1)
         Dim checkFilename As String
         checkFilename = _
                      valueSet.ReferencedFiles.Item(1).FullFileName 

         ' Find the data that matches this balloon.
         Dim j As Integer
         For j = 0 To UBound(partInfo)
            If checkFilename = partInfo(j).ReferencedFile Then
               ' Override the balloon value to match, if
               ' it's different.
               matchFound = True
               If valueSet.ItemNumber <> partInfo(j).Number Then
                  valueSet.OverrideValue = partInfo(j).Number
               End If
               Exit For
            End If
         Next
      Next
   Next
End Sub

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

CAD Monkey 4 Life!
0 Likes
Accepted solutions (1)
1,689 Views
5 Replies
Replies (5)
Message 2 of 6

bshbsh
Collaborator
Collaborator

this seems like vba syntax. it won't work in ilogic without some modification.

0 Likes
Message 3 of 6

CADMonkey4Life
Enthusiast
Enthusiast

So the easy way is macro instead right?

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

CAD Monkey 4 Life!
0 Likes
Message 4 of 6

Anonymous
Not applicable

The easy way is just remove the 'set' and 'let' syntax. Most everything else will be adapted.

0 Likes
Message 5 of 6

Anonymous
Not applicable
Accepted solution

Normally its just the Let/Set syntax that you can get away with. This also uses some other items like a custom type. So a bit more difficult.

 

Another bit of code that was posted a while back regarding a similar situation, is below. This relates to setting view labels rather than the balloon numbers.

 

'Places Item Numbers of Part from Drawing Parts List
' into the Respective View Labels, except projected views
''
'Originally at : http://forums.autodesk.com/t5/inventor-customization/exsisting-ilogic-rule-view-label-fitted-with-item-number/m-p/6323006/highlight/true#M63823


' Set a reference to the drawing document.' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oSheets As Sheets Dim Sheet As Inventor.Sheet Dim oViews As DrawingViews Dim oView As DrawingView For Each oSheet In oDrawDoc.Sheets 'For Each oSheet In oSheets oViews = oSheet.DrawingViews For Each oView In oViews If oView.ViewType <> 10504 Then ' Not kProjectedDrawingViewType 'Get the full filename Of the view model Dim oModelFileName As String oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName 'MessageBox.Show("view model name" & oModelFileName, "Title") Dim oPartList As PartsList 'try and get the parts list form the table of this sheet Try oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1) Catch 'on error try and search all sheets for first found parts list 'iterate trough each sheet Dim i As Long For i = 1 To oDrawDoc.Sheets.Count If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For Next oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1) 'MessageBox.Show("parts list found on: " & i, "Title") End Try ' Iterate through the contents of the parts list. Dim oRow As PartsListRow Dim oRowFileName As String Dim j As Long For j = 1 To oPartList.PartsListRows.Count ' Get the current row. oRow = oPartList.PartsListRows.Item(j) 'get filename of model in row oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName 'compare the filenames 'Performs a text comparison, based on a case-insensitive text sort order 'If strings equal returns 0 If StrComp(oModelFileName, oRowFileName, CompareMethod.Text)=0 Then 'Get the value of Item from the Parts List 'Row name needs to be case sensitive or use 1 for first 2 for second etc. oCell = oPartList.PartsListRows.Item(j).Item("Item") 'Row name needs to be case sensitive or use 1 for first 2 for second etc. 'get the value of text in cell Dim oItemValue As String oItemValue = oCell.Value 'Show the view label oView.ShowLabel = True 'format the text first line oStringItem = " ITEM " & oItemValue & " " 'format the text second line oStringScale = " (Scale )" 'add to the view label oView.Label.FormattedText = oStringItem & oStringScale End If Next End If Next Next
0 Likes
Message 6 of 6

Anonymous
Not applicable

Hi.

 

Can this code be changed to show balloons instead of labels?  That could help me o lot.

 

Regards!

0 Likes