PLEASE CHECK THIS DRAWING CODE. (MODIFYING SHEET NAME iLOGIC)

PLEASE CHECK THIS DRAWING CODE. (MODIFYING SHEET NAME iLOGIC)

youneedtodonow
Participant Participant
438 Views
4 Replies
Message 1 of 5

PLEASE CHECK THIS DRAWING CODE. (MODIFYING SHEET NAME iLOGIC)

youneedtodonow
Participant
Participant

 

 

Here's an iLogic code that modifying sheet name automatically "<Part Number> <Stock Number>".

 

For example, Part number is "BS100" , Stock Number is "Shaft" then sheet name changed as BS100 Shaft.

 

This is my code below. There's an error but I couldn't check it and fix it.

 

Sub Main()
    ModifySheetName()
End Sub

Sub ModifySheetName()
    ' Get the active drawing document.
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    
    ' Check if it's a drawing document.
    If oDrawDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
        MsgBox("This rule is intended to be used with drawing documents only.", MsgBoxStyle.Information)
        Exit Sub
    End If
    
    ' Get the part number and stock number from iProperties.
    Dim partNumber As String = iProperties.Value("Project", "Part Number")
    Dim stockNumber As String = iProperties.Value("Project", "Stock Number")
    
    ' Modify the sheet name.
    For Each oSheet As Sheet In oDrawDoc.Sheets
        If oSheet.SheetType = DrawingSheetTypeEnum.kSheetTypeDrawing Then
            oSheet.Name = partNumber & " " & stockNumber
        End If
    Next
    
    MsgBox("Sheet names have been modified.", MsgBoxStyle.Information)
End Sub

' Call the subroutine to modify sheet names.
Main()

 

 

Please check it and let me know how to do.

 

Thank you all.

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

Michael.Navara
Advisor
Advisor

Here is fixed version

  • Function Main() is called automatically by iLogic. iLogic is not a scripting language like JavaScript.
  • I don't know where you get DrawingSheetTypeEnum, but it is not defined in Inventor API

 

 

Sub Main()
    ModifySheetName()
End Sub

Sub ModifySheetName()
    ' Get the active drawing document.
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    
    ' Check if it's a drawing document.
    If oDrawDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
        MsgBox("This rule is intended to be used with drawing documents only.", MsgBoxStyle.Information)
        Exit Sub
    End If
    
    ' Get the part number and stock number from iProperties.
    Dim partNumber As String = iProperties.Value("Project", "Part Number")
    Dim stockNumber As String = iProperties.Value("Project", "Stock Number")
    
    ' Modify the sheet name.
    For Each oSheet As Sheet In oDrawDoc.Sheets
        'If oSheet.SheetType = DrawingSheetTypeEnum.kSheetTypeDrawing Then ' THIS IS NOT DEFINED
            oSheet.Name = partNumber & " " & stockNumber
        'End If
    Next
    
    MsgBox("Sheet names have been modified.", MsgBoxStyle.Information)
End Sub

' Call the subroutine to modify sheet names.
'Main() ' iLogic IS NOT A SCRIPTING LANGUAGE. YOU DON'T NEED TO CALL MAIN FUNCTION IT IS CALLED AUTOMATICALLY

 

Message 3 of 5

MartinPapez
Contributor
Contributor

 

Hi  @Michael.Navara and @youneedtodonow,

 

that code works, but rename all the sheets with the same name.  In case that every sheet target different model, can be used something like the code below. Unluckily I am have not find out how to reach IProperties for the targeted models, so I just used the name of the model. Maybe You can take it further.

 

Sub Main()
    ModifySheetName()
End Sub

Sub ModifySheetName()
    ' Get the active drawing document.
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    
    ' Check if it's a drawing document.
    If oDrawDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
        MsgBox("This rule is intended to be used with drawing documents only.", MsgBoxStyle.Information)
        Exit Sub
    End If
    
     
    For Each oSheet As Sheet In oDrawDoc.Sheets
		
		oSheet.Activate()
	
		Dim oView As DrawingView
		oView = oSheet.DrawingViews(1)

	
		Dim viewModelDoc = ActiveSheet.View(oView.Name).ModelDocument

		
	
	'Doesn't work.
	'Dim partNumber As String = iProperties.Value(viewModelDoc, "Project", "Part Number")
	'Dim stockNumber As String = iProperties.Value(viewModelDoc, "Project", "Stock Number")
     'oSheet.Name = partNumber & " " & stockNumber
	
	
	 oSheet.Name = viewModelDoc.DisplayName.Remove(viewModelDoc.DisplayName.LastIndexOf("."))
       
    Next
    
    MsgBox("Sheet names have been modified.", MsgBoxStyle.Information)
End Sub 

 

Message 4 of 5

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi @MartinPapez,

 

Maybe somehting linke this ?

Sub main
    ' Get the active drawing document.
    Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
    
    ' Check if it's a drawing document.
    If oDrawDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
        MsgBox("This rule is intended to be used with drawing documents only.", MsgBoxStyle.Information)
        Exit Sub
		
    End If
       
    For Each oSheet As Sheet In oDrawDoc.Sheets
		oSheet.Activate()	
		Dim oView As DrawingView
		oView = oSheet.DrawingViews(1)

		Dim viewModelDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		Dim propertyset As Inventor.PropertySet = viewModelDoc.PropertySets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
			
		Dim partNumber As String = propertyset.Item("Part Number").Value.ToString
		Dim stockNumber As String =  propertyset.Item("Stock Number").Value.ToString
    	oSheet.Name = partNumber & " " & stockNumber
	
	 	'oSheet.Name = viewModelDoc.DisplayName.Remove(viewModelDoc.DisplayName.LastIndexOf("."))
       
    Next
    
    MsgBox("Sheet names have been modified.", MsgBoxStyle.Information)
	
End Sub        

The commented line works too.

 

Kind regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 5 of 5

MartinPapez
Contributor
Contributor

Hi @FINET_Laurent ,

 

great! I did not realized I can go throw Api, I was hopelessly searching in iLogic.