Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: Fazlur_Rahaman

Hi @Fazlur_Rahaman.  You can try this version of your code:

'This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheets As Sheets = oDrawDoc.Sheets
Dim oSheet As Inventor.Sheet = oDrawDoc.ActiveSheet
Dim oViews As DrawingViews = oSheet.DrawingViews
Dim oView As DrawingView
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 = Nothing
	'try and get the parts list form the table of this sheet
	Try
		oPartList = oSheet.PartsLists.Item(1)
	Catch 'on error try and search all sheets for first found parts list            
		'iterate trough each sheet
		For Each oSht As Sheet In oSheets
			If oSht.PartsLists.Count > 0 Then
				oPartList = oSht.PartsLists.Item(1)
				Exit For
			End If
		Next
		'MessageBox.Show("parts list found on: " & i, "Title")
	End Try
	If oPartList Is Nothing Then Return '<<< or show message about it >>>
	' Iterate through the contents of the parts list.
	For Each oRow As PartsListRow In oPartList.PartsListRows
		'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 = oRow.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 = 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

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) :thumbs_up:.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)