Sheet name to equal active model file name & revision number

Sheet name to equal active model file name & revision number

GKPByDesign
Advocate Advocate
427 Views
2 Replies
Message 1 of 3

Sheet name to equal active model file name & revision number

GKPByDesign
Advocate
Advocate

Hey I had this code solved on here before which grabs the active model's file name to name the sheet the same name, I now want to add the revision to the file name: eg File name & "-" & Rev number. I know illogic well, but logic in drawings is hard! 

 

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) & "-" & o_iProp
Next 
  
End Sub
Accepted solutions (1)
428 Views
2 Replies
Replies (2)
Message 2 of 3

chandra.shekar.g
Autodesk Support
Autodesk Support

@GKPByDesign,

 

Try below iLogic code to rename the sheet.

 

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
    Dim oModel As Document
	oModel = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
	Msgbox("1")
	Dim oRev As String 
	oRev = oModel.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value 

     'Assign the sheet name based off of the file name, with the path and extension removed
    oSheet.Name = System.IO.Path.GetFileNameWithoutExtension(oModel.FullFileName) & "-" & oRev
Next 
  
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 3

GKPByDesign
Advocate
Advocate
Accepted solution

Hey the code almost worked, but you had a rouge bit of code to show a message box? 

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
    Dim oModel As Document
	oModel = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oRev As String 
	oRev = oModel.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value 

     'Assign the sheet name based off of the file name, with the path and extension removed
    oSheet.Name = System.IO.Path.GetFileNameWithoutExtension(oModel.FullFileName) & "-" & oRev
Next 
  
End Sub
0 Likes