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

Change Drawing Sheet name to match active file name

I currently have a drawing template that picks up the file of the part on that particular sheet. So i have "part A" on "sheet 1", the file name for "sheet 1" is "part a" - i then have "part b" on "sheet 2", therefore the file name for "sheet 2" is "part b."

 

Now with this in mind i need to modify this code (below) which automatically fills in the sheet name (eg sheet 1, sheet 2, sheet 3, etc) with the relevant part number. But i need to modify it so it picks up the active sheet file name. If i modify the code and put in the " iProperties.Value("Project", "Project") " it picks up the drawing file, and not the part on that drawing. Can someone help by making the code below pick up model information on the active sheet.

 

Sub Main
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim dwgDoc as DrawingDocument = ThisDoc.Document
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
modelFile = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
prtNumber = modelDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
If Not String.IsNullOrEmpty(prtNumber) Then
dwgSheet.Name = prtNumber
End If
End If
Next
End If
End Sub

 

 

 The information i need to have automatically filled is the code below, but it must be looking at the active sheet file name and not the documemnt file name. Hopefully i've made sense

 

SyntaxEditor Code Snippet

SyntaxEditor Code Snippet
Sub Main
If TypeOf ThisDoc.Document Is DrawingDocument Then
Dim dwgDoc as DrawingDocument = ThisDoc.Document
For Each dwgSheet As Sheet In dwgDoc.Sheets
If dwgSheet.DrawingViews.Count > 0 Then
modelFile = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.FullDocumentName
modelDoc = dwgSheet.DrawingViews(1).ReferencedDocumentDescriptor.ReferencedDocument
prtNumber = modelDoc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").ItemByPropId(5).Value
If Not String.IsNullOrEmpty(ThisDoc.FileName) Then
dwgSheet.Name = ThisDoc.FileName
End If
End If
Next
End If
End Sub
Anonymous
in reply to: Anonymous

I have been playing with this, but i still cannot archive what ive request, does anyone know how i can solve this? 

timothy_berg
in reply to: Anonymous

i am no expert on code i did find this in a similar post maybe it will work for you:

 

SyntaxEditor Code Snippet

Dim oSheets As Sheets = ThisDrawing.Document.sheets
Dim oSheet As Sheet

For Each oSheet In oSheets
    oSheet.activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
    PartNumb = iProperties.Value(oModel.DisplayName, "Project", "Part Number")

    

    ActiveSheet.Sheet.Name = PartNumb
Next
MechMachineMan
in reply to: Anonymous

Ignore this... was typos and bugged posting...


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
MechMachineMan
in reply to: Anonymous

This should get ya goin'.

 

Sub Main()
'Purpose: Push file name to sheet name
'21-Sept-16

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

'Iterate through sheets For Each oSheet In oDoc.Sheets
'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) Next 
  
End Sub

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type

Hello, I am trying to Copy/Paste this rule into my Drawing and it errors out when I try to Save/Run. We are basically looking to do this exact same thing I believe. After I detail an ipt I want the name on the tree to match the name in the title block. The title block is pulling the FILENAME from the Model Parameters, but I can't figure out how to make the tree name it the same. Thanks in advance!

A.Acheson
in reply to: mbrightonNPXL8

The only error I could bring up is when no model was present in one of the sheets. As this rule loops through all sheets and looks for view (1) if missing it will error out. Included in the rule below is an error trap for skipping the sheet renaming when no view is present. If this still doesn't work can you post the error message that you have received?

 

Sub Main()
'Purpose: Push file name to sheet name
'21-Sept-16

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


'Iterate through sheets
For Each oSheet In oDoc.Sheets
	
	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
		'Error no view so skip
	End Try
Next 
  
End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
GKPByDesign
in reply to: A.Acheson

You have to have a model file or iam file on the sheet, otherwise it will error

mbrightonNPXL8
in reply to: A.Acheson

That did it! Thanks so much! This stuff is a bit confusing. We are going to look into a training program for the coding side of inventor as we seem to run into a lot of issues lately.