iLogic to change sheet name to equal Part Number.

iLogic to change sheet name to equal Part Number.

Anonymous
Not applicable
10,157 Views
58 Replies
Message 1 of 59

iLogic to change sheet name to equal Part Number.

Anonymous
Not applicable

I would like to have an iLogic rule that changes the active sheet name to the Models Part Number property.

 

I tried ActiveSheet.name = iProperties.Value("Project", "Part Number"), but

 

get an Error: Property 'Name' is 'ReadOnly'.

 

 

Any help would be greatly appreciated.

 

Thanks,

 

 

 

 
0 Likes
Accepted solutions (1)
10,158 Views
58 Replies
Replies (58)
Message 41 of 59

rjay75
Collaborator
Collaborator
Message 42 of 59

Dopey1993
Enthusiast
Enthusiast
THANKS MAN
0 Likes
Message 43 of 59

Anonymous
Not applicable

Tried this and it worked perfect. Having trouble changing the part number to the stock number. Any advise would be much appreciated. Thanks

0 Likes
Message 44 of 59

MechMachineMan
Advisor
Advisor

"This" is very descriptive. Definitely provides all of the information needed to know which code you are working on and where you could possibly going wrong.

 

Can't help those who don't help themselves....


--------------------------------------
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
0 Likes
Message 45 of 59

rjay75
Collaborator
Collaborator

Not sure which code set you've tried but changing

 

modelDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value

 

to

 

modelDoc.PropertySets("Design Tracking Properties").Item("Stock Number").Value

 

This can be used to get any value on the project tab of the iProperties. The name of the iProperty is inside the Item("iPropertyName").

0 Likes
Message 46 of 59

dbowerU62F5
Explorer
Explorer

Hi All,

 

Total newbie at Inventor iLogic, but for the work I am doing this function would greatly save time in the design office.

 

Would someone be so kind as to give me a step-by-step instruction of how to implement the function that will automatically set the sheet name in the browser to the name of the part that is first placed in the base view of the drawing sheet as is discussed in this post. It would be much appreciated.

 

Many thanks in advance

0 Likes
Message 47 of 59

Anonymous
Not applicable

Hello everyone. Please, does enyone know what the code that will copy the data from "Custom" is to be copied to the Sheet name, as shown in the attached image? I am particularly interested in the code that will rewrite the quantity.
Thanks in advance

0 Likes
Message 48 of 59

Anonymous
Not applicable

Hello everyone! I'm a total amateur at writing iLogic rules, so I need some help. How to write an iLogic rule that overwrites data from "iProperties, Custom" (picture 1. in attacment) to sheetname?
The iLogic from picture 2 and 3 does not always work.
Please help.

0 Likes
Message 49 of 59

rjay75
Collaborator
Collaborator

Yo say it does not always work. In the instances where it doesn't work try manually changing a sheet name to the name you want. This way you can see if it's to many characters or invalid characters. Also check to see if any of the iProperties are blank. In your code it's just adding it all the values together with no checks which could fail if one of the values are empty.

Message 50 of 59

doug.johnston
Advocate
Advocate

Here is a rule that I use to get the Sheet Number as Part Number.  

 

It uses the Part Number from the model using the first placed view on the idw on each individual sheet.  And all our Part Numbers are a Custom iProperty (PART_ID).

 

'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
'21-Sept-16


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()

---------------------------------------------------
It's not easy maintaining this level of insanity !!!!!
Message 51 of 59

Anonymous
Not applicable

Thank you very much

0 Likes
Message 52 of 59

Anonymous
Not applicable

Thanks, but i need a comprehensive name.

0 Likes
Message 53 of 59

Anonymous
Not applicable

How to write a command that will skip a blank iProperties box and continue to the next iProperties box?

0 Likes
Message 54 of 59

rjay75
Collaborator
Collaborator

On the lines where you are setting the iProperties value modify the lines to this.

If(iProperties.Value(oModelName, "Custom", "dimX"), "")

 

This will set the value to an empty string if the value is Nothing.

Message 55 of 59

Anonymous
Not applicable

Can you send me some tutorials i literature so i can practice and study?

0 Likes
Message 56 of 59

Jonathan.WVB
Participant
Participant

Hi, can you send the code that shows the not valid characters in sheet names? I've a similar  code that renames the sheet based on Part Number too but there are some of them with that issue, if that code throw an error message when this happens will help me a lot.

 

 
 
0 Likes
Message 57 of 59

A.Acheson
Mentor
Mentor

Not 100% certain but I would start with regular characters not valid in windows. 

Here is a function to replace these if found. Some testing of your sheet name manually should highlight the errors. Try put your string for new sheet name in an input box and then manually copy to sheet name for testing. 

 https://stackoverflow.com/questions/45458954/replace-invalid-characters-when-saving-excel-as-pdf

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 58 of 59

rjay75
Collaborator
Collaborator

Here's a snippet of code that will show an error message if it can't set the name for some reason or errors.

 

oldName = dwgSheet.Name
Try
    dwgSheet.Name = prtNumber
Catch
    dwgSheet.Name = oldName
    MessageBox.Show("Error setting sheet name to " + prtNumber)
End Try
Message 59 of 59

maxim.teleguz
Advocate
Advocate

@doug.johnston wrote:

Here is a rule that I use to get the Sheet Number as Part Number.  

 

It uses the Part Number from the model using the first placed view on the idw on each individual sheet.  And all our Part Numbers are a Custom iProperty (PART_ID).

 

'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
'21-Sept-16


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()

 

how would this code look like if it would grab all the views of each sheet and consolidate them in the sheet name?