Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change sheet name to part number and revision number

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
cliff.kelly
1753 Views, 9 Replies

Change sheet name to part number and revision number

Hi Inventor Community,

I am currently using the following logic to rename my sheets to the "Part Number - iproperty"

 

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
    partnum = iProperties.Value(oModel.DisplayName, "Project", "Part Number")
    ActiveSheet.Sheet.Name = partnum
Next

 

This works great, but I would like to revise my current rule (but don't know how) to include the Revision Number (from the Part / Assembly iproperty).

Ideally my sheet name would read "Part Number" _REV "Revision Number". e.g. ATA101_REV1

 

Is this possible?

 

 

 

 

9 REPLIES 9
Message 2 of 10
mcgyvr
in reply to: cliff.kelly

This should do it..

I'm in a rush but I think its right..

Let me know if its not and I will fix it.

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
    partnum = iProperties.Value(oModel.DisplayName, "Project", "Part Number")
    oRev = iProperties.Value(oModel.DisplayName, "Project", "Revision Number")
    ActiveSheet.Sheet.Name = partnum & "_REV" & oRev
Next


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 10
cliff.kelly
in reply to: mcgyvr

Fantastic! Thank you.

Message 4 of 10
Anonymous
in reply to: cliff.kelly

I was looking to do the exact same operation as the original poster which is to change the sheet names to the respective part number in that sheet.

I created a rule in my drawing template with the exact syntax as previously posted.

However I get the following error while running the rule;

"Object reference not set to an instance of an object."

 

Any help would be greatly appreciated 🙂

 

 

Message 5 of 10
mcgyvr
in reply to: Anonymous


@Anonymous wrote:

I was looking to do the exact same operation as the original poster which is to change the sheet names to the respective part number in that sheet.

I created a rule in my drawing template with the exact syntax as previously posted.

However I get the following error while running the rule;

"Object reference not set to an instance of an object."

 

Any help would be greatly appreciated 🙂

 

 


@Anonymous  Have you placed drawing views into each sheet? (That code doesn't have any error checking which it really should)

Can you post your idw file here?

What version of Inventor?

 

You may have copied/pasted incorrectly too or something..



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 6 of 10
Anonymous
in reply to: mcgyvr

Yes there are drawing views in the sheet.

Currently using Inventor Professional 2018.

I cannot post my drawing template but here is a screenshot of the code;

Untitled.jpg

Message 7 of 10
mcgyvr
in reply to: Anonymous


@Anonymous wrote:

Yes there are drawing views in the sheet.

Currently using Inventor Professional 2018.

I cannot post my drawing template but here is a screenshot of the code;

Untitled.jpg


@Anonymous  The issue is specific to your files.

Have you tried the code with a different drawing/model?

Can you strip out anything proprietary and post the drawing? (Model a simple cube and send a drawing of that and strip out the titleblock or whatever is preventing you from sharing it)

 

Try this and let us know where it craps out.. 

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
Dim oSheet As Sheet
MessageBox.Show("Preparing to start the loop", "Step 0")

For Each oSheet In oSheets
	MessageBox.Show ("Sheet " & oSheet.Name, "Sheet Name")
    oSheet.Activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
	MessageBox.Show("Got a drawing View", "Step 1")
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
	MessageBox.Show("Got a model document", "Step 2")
    partnum = iProperties.Value(oModel.DisplayName, "Project", "Part Number")
	MessageBox.Show("Got a part number", "Step 3")

    ActiveSheet.Sheet.Name = partnum
Next


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 8 of 10
Anonymous
in reply to: mcgyvr

Yes I have tried different parts/assemblies, same error message.

I inserted the test code and the last message box displayed prior to receiving the error message was;

 

Step 2

Got a model document

 

Would you still need me to post a drawing?

 

Message 9 of 10
mcgyvr
in reply to: Anonymous

@Anonymous  Try this  (if this doesn't work then yes please post a drawing)

 

Dim oSheets As Sheets = ThisDrawing.Document.Sheets
Dim oSheet As Sheet
MessageBox.Show("Preparing to start the loop", "Step 0")

For Each oSheet In oSheets
	MessageBox.Show ("Sheet " & oSheet.Name, "Sheet Name")
    oSheet.Activate
    Dim oDrawingView As DrawingView = oSheet.DrawingViews(1)
	MessageBox.Show("Got a drawing View", "Step 1")
    oModel = ActiveSheet.View(oDrawingView.Name).ModelDocument
	MessageBox.Show("Got a model", "Step 2")
   ' partnum = iProperties.Value(oModel.DisplayName, "Project", "Part Number")
	partnum = oModel.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
	MessageBox.Show("Got a part number", "Step 3")


    ActiveSheet.Sheet.Name = partnum
Next

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 10 of 10
Anonymous
in reply to: mcgyvr

That did it!

Thank you very much for your help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report