Exsisting iLogic rule - View label fitted with Item number

Exsisting iLogic rule - View label fitted with Item number

Andrew2803
Advocate Advocate
1,679 Views
4 Replies
Message 1 of 5

Exsisting iLogic rule - View label fitted with Item number

Andrew2803
Advocate
Advocate

Hi Everybody!

 

I have this iLogic rule below, responsible for creting Item numbers into part's view label, of an existing assembly.

My problem is: this rule creates Item number into label of projected views also, what I don't want.

How this rule should be converted to show Item numbers only in main view labels?

I have basic knowledge about iLogic.

 

Many thanks in advance.

Andras

 

' Set a reference to the drawing document.' 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
                '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 & " </StyleOverride>"
                    'format the text second line
                    oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
                    
                    'add to the view label
                    oView.Label.FormattedText =  oStringItem & oStringScale
                End If  
            Next
      Next
Next

 

0 Likes
Accepted solutions (1)
1,680 Views
4 Replies
Replies (4)
Message 2 of 5

NSBowser
Advocate
Advocate
Accepted solution

Try This!  (modifications in bold)

 

' Set a reference to the drawing document.' 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
		If oView.ViewType <> 10504 Then ' Not kProjectedDrawingViewType
			'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
				'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 & " </StyleOverride>"
					'format the text second line
					oStringScale = "<Br/><StyleOverride FontSize='0.3'>(Scale <DrawingViewScale/>)</StyleOverride>"
					
					'add to the view label
					oView.Label.FormattedText =  oStringItem & oStringScale
				End If  
			Next
		End If
	Next
Next
 

Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
Message 3 of 5

Andrew2803
Advocate
Advocate

NSBowser!

 

Excellent job! Thank you!

0 Likes
Message 4 of 5

Andrew2803
Advocate
Advocate

Hi NSBowser! (Or anyone else)

 

Could you make a second version of this code? I'd like to be able to pick different assembly's BOM lists participating on a drawing!

I guess iLogic gives option to create a dropdown menu. This menu could offer which participating assembly's BOM I want to use

spreading Itemnumbers to views of participating parts... hope this solvable this way!

 

Many thanks in advance! 

 

Andras

0 Likes
Message 5 of 5

moduseng
Contributor
Contributor

Is it possible to modify this rule to work with the 'part number' iProperty instead of file name?

0 Likes