How to add parts list row to object collection inventor vba

How to add parts list row to object collection inventor vba

adiazLRYTC
Explorer Explorer
953 Views
2 Replies
Message 1 of 3

How to add parts list row to object collection inventor vba

adiazLRYTC
Explorer
Explorer

Hello everyone, I am working on a coding project that requires me to add the following to a list (Part Number, Description, Category, G_L, Component Type, Revision Number). Rather then adding them each into their separate lists, I was thinking that adding the entire row from the parts list onto an object collection would be much faster. That way if I need info I can just call from the collection rather then each individual list. it would be much easier and faster. But I am having trouble on adding an entire row to a collection. Any ideas? here is what I have to far.

Public Sub CheckRevised()
Dim ThisDrwing As Inventor.DrawingDocument
Dim oSheet As Sheet
Dim oDrawingView As DrawingView
Dim oModelDoc As Document
Dim ThisAssem As Inventor.AssemblyDocument
Dim oBom As BOM
Dim oBOMView As BOMView
Dim compDef As ComponentDefinition
Dim doc As Document
Dim row As BOMRow
Dim prop As Property
Dim PartNumList As Variant
Dim DescripList As Variant
Dim CategList As Variant
Dim glList As Variant
Dim CompTypeList As Variant
Dim ObjColl As ObjectCollection
'Check if they wanted to run function
IntMsg = MsgBox("This Function initiates a drawing check, would you like to continue?", vbYesNo)
If IntMsg = 6 Then
'Check if drawing
If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
Set ThisDrwing = ThisApplication.ActiveDocument
'If first sheet not active then prompt that we will default to use the first sheet "Ok?"
If ThisDrwing.ActiveSheet.Name <> ThisDrwing.Sheets(1).Name Then
IntMsgs = MsgBox("First sheet not found active, will default to use first sheet. Ok?", vbYesNo)
End If
If IntMsgs = 7 Then
MsgBox ("Function canceled.")
End
End If
'On sheet look at first views scource, and get scource model
Set oSheet = ThisDrwing.ActiveSheet
Set oDrawingView = oSheet.DrawingViews.Item(1)
Set oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
Set ThisAssem = ThisApplication.Documents.Open(oModelDoc.FullDocumentName, True)
Set ThisAssem = ThisApplication.ActiveDocument
Set oBom = ThisAssem.ComponentDefinition.BOM
oBom.StructuredViewEnabled = False
oBom.StructuredViewFirstLevelOnly = False
oBom.PartsOnlyViewEnabled = True
Set oBOMView = oBom.BOMViews(2)
'load parts list into array (Part Number, Description, Category, G_L, Component Type, Revision Number)
ReDim PartNumList(1)
For Each row In oBOMView.BOMRows
Set compDef = row.ComponentDefinitions(1)
Set doc = compDef.Document
ObjColl.Add (doc.PropertySets("Design Tracking Properties")) << HERE IS THE TROUBLE

Next

Else
MsgBox ("File opened must me drawing document, function canceled.")
End
End If
Else
MsgBox ("Function canceled.")
End
End If
End Sub

0 Likes
954 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor

Hi @adiazLRYTC 

Just looking through your code, I see that you never create the ObjectCollection, you're just declaring a variable of type ObjectCollection. You also need to create it for the variable to not just be Nothing.

Dim ObjColl As ObjectCollection
Set ObjColl = ThisApplication.TransientObjects.CreateObjectCollection 'Create object collection

 When it's created it'll exist and you can add objects to it 🙂

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Just curious...what are you planning on doing with this ObjectCollection full of PropertySet objects after you have collected them into it?  If you are planning on reducing processing time, this may not be the best option.  If there are a select few properties within each set that you are interested in, it may be more advantageous to just collect their values into something like a collection of collections, or an Array of Arrays, or similar instead.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes