- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been piecing together a bit of code, trying to accomplish a few goals:
*Note: This is all occurring with an assembly drawing that utilizes multiple parts list, assemblies, parts, and drawing views.
1.) Automatically setting view labels - I want to pull both parts list data and iproperty data to be used in the view label. I have figured out the code to this point and it is working as intended.
2.) This plays into goal number 1. I am pulling the quantity data directly from the parts list. This works great, however, we have times where we are building the same assembly, multiple times. I have played with making a multiplier column in the parts list, however this seems cumbersome to effectively modify on larger assemblies, as I have to enter in a multiplier value to each individual row. If possible, I would like to be able to have a form, wherein you enter a Total Assembly Quantity, and it maps that value you enter there to either a parameter or a new custom property, that could then be used to multiply the quantities accordingly. Here is a screenshot of basically what I am doing now:
3.) The majority of our drawings have multiple parts lists within them. The code I have so far works great - for the very first parts list found in the drawing. However, whenever I am working my way through the drawing, and have come to the next sub-assembly and it's respective parts list, the code stops working, and it will not update the view labels. This is the one that I have been stumped on the most, as, like I said, I have mostly pieced my current code together using other forum posts and such.
' 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
oSheets = oDrawDoc.Sheets
Dim oSheet As Sheet'Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim oPartsLists As PartsLists
Dim oPartsList As PartsList
For Each oSheet In oSheets
'declare the PartsLists
oPartsLists = oSheet.PartsLists
'try and get the parts list from the table of this sheet
Try
'this doesn't work when you have a material list like on frame drawings
'oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
'place a parts list on the drawing and search for it
'rather than using an id number
For i=1 To oPartsLists.Count
If oPartsLists.Item(i).Title = "PARTS LIST" Then
'MessageBox.Show("found table", "ilogic")
oPartsList = oPartsLists.Item(i)
Exit For
Else
'do nothing
End If
Next
Catch 'on error try and search all sheets for first found parts list
'iterate through each sheet
Dim j As Long
For j = 1 To oDrawDoc.Sheets.Count
If oDrawDoc.Sheets.Item(j).PartsLists.Count > 0 Then Exit For
Next
'this doesn't work when you have other parts lists like a
'"material list" like on frame drawing
'oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
'place a parts list on the drawing and search for it
'rather than using an id number to locate the first
For i=1 To oPartsLists.Count
If oPartsLists.Item(i).Title = "PARTS LIST" Then
'MessageBox.Show("found table", "ilogic")
oPartsList = oPartsLists.Item(i)
Exit For
Else
'do nothing
End If
Next
'MessageBox.Show("parts list found on: " & j, "Title")
End Try
oViews = oSheet.DrawingViews
'get view from user
While True
oView = ThisApplication.CommandManager.Pick( _
SelectionFilterEnum.kDrawingViewFilter, "Select a View")
'Get the full filename Of the view model
Dim oModelFileName As String
oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
'MessageBox.Show("view model name" & oModelFileName, "Title")
' Iterate through the contents of the parts list.
Dim j As Long
For j = 1 To oPartsList.PartsListRows.Count
' Get the current row.
Dim oRow As PartsListRow
oRow = oPartsList.PartsListRows.Item(j)
'get filename of model in row
Dim oRowFileName As String
Try ' try and get the full file name of the PL item
oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
Catch 'on error go to next item
' Dim oCellValue As String
' oCellValue = oRow.Item("Item").Value
' MessageBox.Show("Error Processing item: " & oCellValue, "Title")
Continue For
End Try
'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 = oPartsList.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 next line
oStringItem = "<StyleOverride Underline='True' FontSize='0.25'> ITEM " & oItemValue & " </StyleOverride>"
'format the next line
'Scale is not being utilized at this time
'oStringScale = "<Br/><StyleOverride FontSize='0.2'>Scale <DrawingViewScale/></StyleOverride>"
'format the next line
'This pulls the part number iProperty from the reference file
oStringPNumber = "<Br/><StyleOverride Underline='False' FontSize='0.2'> P#: <Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>"
'format the next line
'This pulls the revision iProperty from the reference file
oRev = iProperties.Value(docFName,"Project","Revision Number")
'oStringViewRev = "<StyleOVerride Underline='False' FontSize='0.2'> REV: " & oRev & " </StyleOverride>"
'format the next line
'This pulls the description iProperty from the reference file
oStringViewDesc = "<Br/><StyleOverride Underline='False' FontSize='0.2'> DESC: <Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>DESCRIPTION</Property></StyleOverride>"
'format the next line
'This pulls the material iProperty data from the reference file
oStringViewMat = "<Br/><StyleOverride Underline='False' FontSize='0.2'> MATERIAL: <Property Document='model' PropertySet='Design Tracking Properties' Property='Material' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='29'>MATERAIL</Property></StyleOverride>"
'format the next line
'This pulls quantity data from the parts list
oCellQuantity = oPartsList.PartsListRows.Item(j).Item("Item QTY")
Dim oListQuantity As String
oListQuantity = oCellQuantity.Value
oStringListQuantity = "<Br/><StyleOverride Underline='False' FontSize='0.2'> QTY: " & oListQuantity & " </StyleOverride>"
'add to the view label
oView.Label.FormattedText = oStringItem & oStringViewDesc & oStringPNumber & oStringViewMat & oStringListQuantity
End If
Next
End While
Next
Solved! Go to Solution.