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: 

Wrtie text string to parts list coloum with iLogic

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
TomTom111
786 Views, 3 Replies

Wrtie text string to parts list coloum with iLogic

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!

3 REPLIES 3
Message 2 of 4

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

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

Message 4 of 4

Great!


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

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

Post to forums  

Autodesk Design & Make Report