Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open File Using BOM in iLogic

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dalton98
324 Views, 2 Replies

Open File Using BOM in iLogic

Hello. I'm trying to make a rule that automatically places drawing views of my assembly. I figured using the BOM would be best since it gives the number of parts, the purchased parts, etc. I originally exported the BOM to an excel file and referenced that in my drawing rule. I'm trying to cut that step out.

 

I was wondering if there was an easy way to open files from the BOM. I tried adding "Filename" and "File Path" coulombs, but I couldn't get those to work outside of the excel file. Possibly because they're read only? Sorry if this is a dumb question, but I can't find a solution. 

 

Attached testing code:

Dim modelDoc = ThisDrawing.ModelDocument

Dim oBOM As BOM
oBOM = modelDoc.ComponentDefinition.BOM
 
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only")

Dim i As Long
For i = 1 To oBOMView.BOMRows.Count

  Dim oRow As BOMRow
  oRow = oBOMView.BOMRows.Item(i)
	  
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.Item(1)

Dim oPropSet As PropertySet
  oPropSet = oCompDef.Document.PropertySets.Item("Design Tracking Properties")
	  

MessageBox.Show(oPropSet.Item("Filename").Value, "Title")            '<<<<<<<<<<<<<<<<<< problems
ThisApplication.Documents.Open(oPropSet.Item("Filename").Value)      '<<<<<<<<<<<<<<<<<< 

Next

 

2 REPLIES 2
Message 2 of 3
A.Acheson
in reply to: dalton98

I would suggest having this moved over to the ilogic forum if you need more help with this.  Below you can retrieve the document from the definition and then the full file path. You could also just navigate through the referenced documents of the  assembly. If you let us know the full workflow your planning you should be able to eliminate the export to excel and work directly in the assemblies/drawings. 

 

Dim modelDoc = ThisDrawing.ModelDocument

Dim oBOM As BOM
oBOM = modelDoc.ComponentDefinition.BOM
 
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only")

Dim i As Long
For i = 1 To oBOMView.BOMRows.Count

  Dim oRow As BOMRow
  oRow = oBOMView.BOMRows.Item(i)
	  
Dim oCompDef As ComponentDefinition
oCompDef = oRow.ComponentDefinitions.Item(1)
Dim oDoc as Document = oCompDef.Document
Dim Fullfilename As String = oDoc.FullFileName
Dim oPropSet As PropertySet oPropSet = oCompDef.Document.PropertySets.Item("Design Tracking Properties")

If oPropSet
.Item("PartNumber").Value = " Enter part Number here" Then

ThisApplication.Documents.Open(Fullfilename,True) '<<<<<<<<<<<<<<<<<< Next

End If

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3
dalton98
in reply to: A.Acheson

Didn't know about reference documents. They seem to be the easiest way to go. Thanks!

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

Post to forums  

Autodesk Design & Make Report