Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey guys, I have the code below to call out the Item number, description and the Stock number. The code works flawlessly. But I want to modify it to just call out the Active sheet, not the whole document. Can someone help me with it please?
'This assumes a drawing document is active.
'Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheets As Sheets
Dim Sheet As Inventor.Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
For Each oSheet In oDrawDoc.Sheets
'For Each oSheet In oSheets
oViews = oSheet.DrawingViews
For Each oView In oViews
'Get the full filename Of the view model
Dim oModelFileName As String
oModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
'MessageBox.Show("view model name" & oModelFileName, "Title")
Dim oPartList As PartsList
'try and get the parts list form the table of this sheet
Try
oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1)
Catch 'on error try and search all sheets for first found parts list
'iterate trough each sheet
Dim i As Long
For i = 1 To oDrawDoc.Sheets.Count
If oDrawDoc.Sheets.Item(i).PartsLists.Count > 0 Then Exit For
Next
oPartList = oDrawDoc.Sheets.Item(i).PartsLists.Item(1)
'MessageBox.Show("parts list found on: " & i, "Title")
End Try
' Iterate through the contents of the parts list.
Dim j As Long
For j = 1 To oPartList.PartsListRows.Count
' Get the current row.
Dim oRow As PartsListRow
oRow = oPartList.PartsListRows.Item(j)
'get filename of model in row
Dim oRowFileName As String
''oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
Try 'and get the full file name of the PL item
oRowFileName = oRow.ReferencedFiles.Item(1).FullFileName
Catch 'on error go To Next item
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 = oPartList.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 text first line
''oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM " & "''" & oItemValue & "''" & " DETAIL" & " </StyleOverride>"
If oView.ViewType = 10501 Then
oStringItem = "<StyleOverride Underline='True' FontSize='0.35'> ITEM" & " ''" & oItemValue & "''" & " DETAIL" & " </StyleOverride>"
'format the text second line
oPartNumber = "<Br/><StyleOverride Underline='False' FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride>"
'format the text second line
oDescription = "<Br/><StyleOverride Underline='False' FontSize='0.25'><Property Document='model' PropertySet='Design Tracking Properties' Property='Description' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>DESCRIPTION</Property></StyleOverride>"
'format the text second line
oDXF = "<Br/><StyleOverride Underline='False' FontSize='0.25'>DXF FILE:<Property Document='model' PropertySet='Design Tracking Properties' Property='Stock Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>STOCK NUMBER</Property></StyleOverride>"
'add to the view label
End If
'format the text second line
'oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
'add to the view label
oView.Label.FormattedText = oStringItem & oPartNumber & oDescription & oDXF
End If
Next
Next
Next
Solved! Go to Solution.