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

iLogic code to change a drawings sheet "name"...

chris
Advisor

iLogic code to change a drawings sheet "name"...

chris
Advisor
Advisor

I was wondering if someone could write an iLogic code that would rename a drawing sheet name to match the file name of the part detailed on that sheet. In this case, there would only be one part per sheet, ( no multiple parts per sheet), however, the first few sheets might have assembly views. so the code would need to only rename sheets that has parts only, not assemblies.

0 Likes
Reply
Accepted solutions (1)
433 Views
2 Replies
Replies (2)

CCarreiras
Mentor
Mentor
Accepted solution

Hi!

 

Run this iLogic rule in your drawing:

This rule will rename the sheet name to the name of the model (part or assembly) present in the main view of each sheet.

If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then
MessageBox.Show("Please run this rule from the Multi-Sheet DRAWING file.", "iLogic")
Exit Sub
End If

'ilogic rule renames each drawing sheet to first part/model/ipn/etc view inserted into each drawing sheet
'Purpose: Push file name to sheet name

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
Dim oSheets As Sheets
oSheets = oDoc.Sheets
Dim oSheet As Sheet
Dim oDrawingView As DrawingView

'Iterate through sheets
For Each oSheet In oSheets
	Try 
		'Grab the first drawing view on the sheet
		oDrawingView = oSheet.DrawingViews(1)
	
		'Grab the model of the first drawing view
		oModel = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument 
	
		'Assign the sheet name based off of the file name, with the path and extension removed
		oSheet.Name = System.IO.Path.GetFileNameWithoutExtension(oModel.FullFileName)
	Catch
		'There is no drawing views
	End Try
Next 
  
InventorVb.DocumentUpdate()

 Tip:

You can add this rule to your template and start to use it in the new files, or use it as an external rule to use it when you like in any drawing.

I use it as an external Rule.

CCarreiras

EESignature

0 Likes

m_mirasadi
Observer
Observer

Many thanks for sharing this awesome code.

Could you set this code to rename sheets from custom iProperties ?

0 Likes