Item Number, description call out under drawing view

Item Number, description call out under drawing view

Fazlur_Rahaman
Advocate Advocate
316 Views
4 Replies
Message 1 of 5

Item Number, description call out under drawing view

Fazlur_Rahaman
Advocate
Advocate

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
0 Likes
Accepted solutions (2)
317 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Fazlur_Rahaman
Advocate
Advocate

Hi @WCrihfield 

Thanks again for your help with this code. I want to make couple of minor revision. Currently the code populates the label under all the views, is there way to just have it visible under the main base view? And also I would like to add a condition which checks if the 'ITEM' is between 200 & 299 and add an additional line that says "SHIPPED LOOSE"
Example:

Fazlur_Rahaman_0-1732552524195.png

'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
			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
			oQty = oRow.Item("QTY")
			'get the value of text in cell
			Dim oQtyValue As String = oQty.Value
			'Show the view label
			oView.ShowLabel = True
			'format the text first line
			
			If oView.ViewType = 10501 Then
				oItem = "<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
				oQty_txt = "<Br/><StyleOverride Underline='False' FontSize='0.25'> REQUIRED QUANTITY</StyleOverride>"
				'Add the text line
				oQty_value = "<StyleOverride Underline='False' Bold = 'True' FontSize='0.25'>  ''" & oQtyValue & "'' </StyleOverride>"
				'Add the Quantity value
				
		
		End If
				'add to the view label
			oView.Label.FormattedText = oItem & oPartNumber & oDescription & oDXF & oQty_txt & oQty_value
		End If
	Next
Next

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

Fazlur_Rahaman
Advocate
Advocate

@WCrihfieldThank you So much for this. It works flawlessly.

0 Likes