Wrtie text string to parts list coloum with iLogic

Wrtie text string to parts list coloum with iLogic

Anonymous
Not applicable
913 Views
3 Replies
Message 1 of 4

Wrtie text string to parts list coloum with iLogic

Anonymous
Not applicable

Hello,

I'm trying to create an iLogic rule that will print a text string to a cell or coloum of a parts list in inventor.

 

My code so far...

 

Sub Main()
On Error Resume Next
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oPartsList1 As PartsList
oPartsList1 = oDrawDoc.ActiveSheet.PartsLists.Item(1)
oPartsList1.Sort("ITEM")

Dim DWGNUM As String = iProperties.Value("custom", "DWG Number")
SheetNumber = Mid(ThisDoc.Document.ActiveSheet.Name, InStr(1, ThisDoc.Document.ActiveSheet.Name, ":") + 1)
Dim j As String = 1
MessageBox.Show(DWGNUM+"-"+SheetNumber+"-"+j, "DXF Number")
End Sub

 

I want to print what is in the MessageBox into a cell in the parts list, and i am stumped.

The cell i am trying to print to is a custom property in the Parts List.

Any help is greatly appreciated!

0 Likes
Accepted solutions (1)
914 Views
3 Replies
Replies (3)
Message 2 of 4

Vladimir.Ananyev
Alumni
Alumni

Suppose you have at least one parts list in the active drawing.

Run this VBA sample.  It gives you access to the content of the parts list cell by row and column numbers. 

In this sample Row number = 5, Column number = 3.

 

Property Value of the PartsListCell object is read/wrtite. So you may assign your values to it.

 

Private Sub AccessToCells()

  Dim oDoc As DrawingDocument
  Set oDoc = ThisApplication.ActiveDocument
  Dim oSheet As Sheet
  Set oSheet = oDoc.ActiveSheet
  
  'reference to the 1st parts list
  Dim oPartsList As PartsList
  Set oPartsList = oSheet.PartsLists.Item(1)
  
  'collection of all rows
  Dim oRows As PartsListRows
  Set oRows = oPartsList.PartsListRows
  Debug.Print "Rows Count: "; oRows.Count
  
  'reference to the specified row
  Dim oRow As PartsListRow
  Set oRow = oRows.Item(5)
  
  'reference to the specified cell in the given row
  Dim oCell As PartsListCell
  Set oCell = oRow.Item(3)
  
  'content of this cell
  Dim St As String
  St = oCell.value
  Debug.Print St

  Beep
End Sub 

 Hope the idea is clear.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

Anonymous
Not applicable
Accepted solution

Thanks Vladimir_Ananyev,

We found a solution similar to the one you provided.

The only difference is it is calling out the columns in the parts list by headding name, instead of number.

 

Autodesk Inventor Write to Parts List iLogic.png

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
   
' Set a reference to the first parts list on the active sheet.
' This assumes that a parts list is on the active sheet.
Dim oPartList As PartsList
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
  
' Iterate through the contents of the parts list.
Dim i As Long
For i = 1 To oPartList.PartsListRows.Count
'look at only the part number column
oCell  = oPartList.PartsListRows.Item(i).Item("PART NUMBER")
'find a specific part number
If oCell.Value = "12-345" Then
'identify the cell in the description column for the row that
'the part number was found in
oCell2 = oPartList.PartsListRows.Item(i).Item("DESCRIPTION")
'write to the target cell
oCell2.Value = "Bingo!"
End if
Next

0 Likes
Message 4 of 4

Vladimir.Ananyev
Alumni
Alumni

Great!


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes