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.  I'm kind of busy at the moment, but on a quick review of your code, I see a couple things that could quickly/easily be changed.

The code on Lines 48 & 49 (for showing the Label) could be moved down just below Line 52 (where it checks ViewType), so that it only shows the Label if it is that Type of view.  But it can be tricky determining which view is 'base', because usually our 'ISO' view is also created as a 'base' view, even though it is often created while we are in the 'mode' for placing 'projected' views around the base view, because it is not considered 'projected', even though it was created while creating the other projected views.  For me, my base view is pretty much never an ISO, but of course there are exceptions to pretty much every thing.  Another thing I often check is seeing if the DrawingView.Parent is Nothing, but I believe that is also true for most ISO views.

 

Another thing I would change is moving the portion of our code that checks for and gets the PartsList on that sheet to up before the start of the Views loop begins.  You only need to get it once per sheet, not once per view.

 

And if you only want those labels on the 'base view', you might even consider moving that ViewType check way up to just inside the Views loop, so you can avoid a whole lot of processing when it is not the right view type.

 

If you move your ViewType check up near the top of the main loop, then the If statement checking Item value can be about where your current ViewType check is.  But you will likely want to use a secondary variable to represent the current Item value (which is a String from the Cell) which you will need to convert to an Integer (or Double, if appropriate), before checking if its value is 'less than' (<) or 'greater than' (>), because that is a mathematical operation.  Then only when that condition is met, will it proceed with all the specific FormattedText lines of code.

 

Edit:  See if this edited version of your code will work the way you want.  I don't do formatted text by code that often, and I was not sure how you wanted that last line formatted, so I hope that extra line works OK for you.

'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
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
End Try
If oPartList Is Nothing Then Return '<<< or show message about it >>>
For Each oView In oViews
	'if its not a 'standard' (orthogonal like Top or ISO) view type, then skip to nect view
	If Not oView.ViewType = DrawingViewTypeEnum.kStandardDrawingViewType Then Continue For
	'Get the full filename Of the view model
	Dim sModelFileName As String
	sModelFileName = oView.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName
	'MessageBox.Show("view model name" & sModelFileName, "Title")
	' Iterate through the contents of the parts list.
	For Each oRow As PartsListRow In oPartList.PartsListRows
		'get filename of model in row
		Dim sRowFileName As String
		Try 'and get the full file name of the PL item 
			sRowFileName = 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(sModelFileName, sRowFileName, 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.
			Dim sItem As String = oRow.Item("Item").Value
			Dim sQty As String = oRow.Item("QTY").Value
			'Show the view label
			oView.ShowLabel = True
			'format the text first line
			Dim sItem_FText As String = "<StyleOverride Underline='True' FontSize='0.35'> ITEM" & " ''" & sItem & "''" & " DETAIL" & " </StyleOverride>"
			'format the text second line
			Dim sPartNumber As String = "<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				
			Dim sDescription As String = "<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
			Dim sQty_Text_FText As String = "<Br/><StyleOverride Underline='False' FontSize='0.25'> REQUIRED QUANTITY</StyleOverride>"
			'Add the text line
			Dim sQty_Value_FText As String = "<StyleOverride Underline='False' Bold = 'True' FontSize='0.25'>  ''" & sQty & "'' </StyleOverride>"
			Dim sShippedLoose As String = "<Br/><StyleOverride Underline='False' Bold = 'True' FontSize='0.25'>  ''" & "SHIPPED LOOSE" & "'' </StyleOverride>"
			Dim iItemValue As Integer = CInt(sItem)
			If iItemValue >= 200 And iItemValue <= 299 Then
				oView.Label.FormattedText = sItem_FText & sPartNumber & sDescription & oDXF & sQty_Text_FText & sQty_Value_FText & sShippedLoose
			Else
				oView.Label.FormattedText = sItem_FText & sPartNumber & sDescription & oDXF & sQty_Text_FText & sQty_Value_FText
			End If
		End If
	Next oRow
Next oView
oDrawDoc.Update2(True)

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)