I think this will be a better fit for what you need. It works with the View Document and Partslist Row Document to bring back the Partslist Value for 'ITEM" and "ITEM QTY". Then Retrieves the View Document iproperty " stock type" and changes the view label.
It is currently looping through all the views on the sheet. this will work assuming the criteria is correct and you don't mind overwriting view labels. The criteria may need to be changed or you can take out the view loop and use a pick function for each view.
If Not ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then MessageBox.Show("Not a drawing! Exiting") : Return
Dim DrawDoc As DrawingDocument = ThisDoc.Document
Dim ActiveSheet As Sheet = DrawDoc.ActiveSheet
'Dim View As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view")
For Each View In ActiveSheet.DrawingViews
Dim ViewDoc As Document = View.ReferencedDocumentDescriptor.ReferencedDocument
If View.Parent.PartsLists.Count = 0 Then MessageBox.Show("No Partlist Exiting") : Return
Dim PartsList As PartsList = View.Parent.PartsLists.Item(1)
For Each Row As PartsListRow In PartsList.PartsListRows
Dim DBomRow As DrawingBOMRow = Row.ReferencedRows.Item(1)
Dim RowDoc As Document = DBomRow.BOMRow.ComponentDefinitions.Item(1).Document
If ViewDoc Is RowDoc Then
Try
Dim ItemCell As PartsListCell = Row.Item("ITEM")
Dim QtyCell As PartsListCell = Row.Item("ITEM QTY")
Dim Item As String = ItemCell.Value
Dim Qty As String = QtyCell.Value
Dim stocktype As String = ViewDoc.PropertySets.Item("User Defined Properties").Item("stock type").Value
View.ShowLabel = True 'show label for selected view
View.Label.FormattedText = "ITEM " & Item & vbLf & stocktype & vbLf & Qty & " X OFF "
Catch
MessageBox.Show("Error in Setting View Label of View: " & View.Name & vbLf & "Check if the iproperty / Partslist Value exists" , "Error Message")
End Try
End If
Next
Next
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan