How to get our Project Number in a Part and Assembly?

How to get our Project Number in a Part and Assembly?

checkcheck_master
Advocate Advocate
1,129 Views
9 Replies
Message 1 of 10

How to get our Project Number in a Part and Assembly?

checkcheck_master
Advocate
Advocate

What is the best way to get our project number in a part or assembly?

I know how to add iProperties but there is no path available for a new file. 

We are working with Vault Professional 2022.
Our method is that we first save a file locally and at a certain point check in to the Vault, I don't know any better.
Now to get our project number as iProperty in the file I use a rule that determines in which project directory the file is located.
However, this only works when the file has already been saved, only then is the path known.
So the second time the file is saved, the project number is assigned.
Does anyone have any tips to make that happen automatically the first time?
How do other companies do this?

0 Likes
1,130 Views
9 Replies
Replies (9)
Message 2 of 10

A.Acheson
Mentor
Mentor

Here is a rule  should work for this.

Set  up this  external rule on the new documents events trigger or just run it as a manual external rule

 

Dim oDoc As Document = ThisApplication.ActiveDocument
	
	Dim oNewFileName, oPN, Ext As String
	
	If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		Ext = ".iam"
	ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Ext = ".ipt"
	End If
	
	oPN = InputBox("Enter a Project Number", "Project Number", "Default Entry")
	iProperties.Value("Project", "Project") = oPN 
	
	Dim oFileDialog As Inventor.FileDialog = Nothing
	ThisApplication.CreateFileDialog (oFileDialog)
	'oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
	oFileDialog.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	
	oNewFileName = oPN & Ext
	
	oFileDialog.FileName = oNewFileName
	oFileDialog.DialogTitle = "Save File"
	oFileDialog.CancelError = True
	
	On Error Resume Next
	oFileDialog.ShowSave
	If Err.Number <> 0 Then
	    MsgBox("No File Saved.", vbOKOnly, "Save Canceled")
	
	ElseIf oFileDialog.FileName <> "" Then
	    oNewFileName = oFileDialog.FileName
	    oDoc.SaveAs(oNewFileName, False)
	End If

 

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

checkcheck_master
Advocate
Advocate

Thanks A.Acheson for your response.
I'm actually looking for a method that doesn't require additional user input.
The user has already selected in which project folder the part or composition should be saved.
So I wonder whether this can be retrieved before the component is actually saved and written to an iProperty.
As an alternative I thought to write that info to a text file and then get from there that the component should be saved again to assign the iProperties based on the Path.
Might be a bit cumbersome but could work just fine, hence my question how others view it.

0 Likes
Message 4 of 10

A.Acheson
Mentor
Mentor

Do I have this correct in that the part number is to be sourced from the folder name and you want the to retrieve that path before save?

 

“The user has already selected in which project folder the part or composition should be saved”


How is the user selecting the project folder, is it through an 
Inventor.FileDialog 

driven by code or manual selection?

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

checkcheck_master
Advocate
Advocate

Do I have this correct in that the part number is to be sourced from the folder name and you want the to retrieve that path before save?

Yes, the Project Number is sourced from the folder name.

 

“The user has already selected in which project folder the part or composition should be saved”


How is the user selecting the project folder, is it through an 
Inventor.FileDialog 

driven by code or manual selection?

Correct yes, the 'normal' Inventor save dialog.

0 Likes
Message 6 of 10

WCrihfield
Mentor
Mentor

If retrieving the project number from the file path is the only way to know what the project number is, and you don't want to have to manually input the project number, then it seems the only option left is that you must save the file, before any type of automation solution can retrieve, then write that data into the file's property.  To do so, you would then have to use the 'After Save Document' event in the Event Triggers dialog.

 

Then that rule you would need to put under that event, would need to check to see if that iProperty is empty.  If empty, retrieve the project number from the file's path, then write it to the iProperty, then re-save the document.  If not empty, then do nothing.

Do you create a new actual 'Project File' for each project, or do you just use the same main project all the time?  If you create a new one for each project, then you would likely have that project 'active' before starting to save files into that project space, so you could retrieve that 'active' project without needing to know any file structure of the current new document.  But I don't know if you name your project the same as the directory which defines the project number, so I don't know if this idea would work for you.

    1.  

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 10

checkcheck_master
Advocate
Advocate

Good options, thanks for the insights and tips.
I wonder what a better option is, 'After Save Document' or through a text file that is checked.
There should be exclusions for both methods.
Which files should be excluded?
Content Center and Library parts?
Other ones?

0 Likes
Message 8 of 10

WCrihfield
Mentor
Mentor

I can't imagine how you would use a text file.  What are your thoughts there?

As far as filtering for content center & library files, I'm not 100% sure what you may mean by library files, but I know how to check if a document is a content center member, iPart factory, iPart member, iAssembly factory, iAssembly member, ModelState factory.  First you would need to check the document type.  If it is a part, get its PartComponentDefinition.  If it is an assembly, get its AssemblyComponentDefinition.  Using a generic ComponentDefinition won't work.  Within each of those specific types of component definitions, there are properties for checking all these things.  It also seems to me like the one variation of the DocumentTypeEnum called kDesignElementDocumentObject was supposed to represent something like an iPart member or iAssembly member, but I've never seen any 'official' documentation that better explains what it is, and I almost never use iPart/iAssembly stuff, in favor of automated configuration templates and iLogic (among other things).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 10

checkcheck_master
Advocate
Advocate
No, properly considered, I wouldn't even know what to do with a text file.
I thought to mention in the text file that the file just saved should be checked again, nice and smart, after all, nothing is known about the file yet, that was exactly the point 🙂
So it seems that 'After Save Document' remains.
By library parts I mean the parts that we have in 'our' library that are not project specific. Purchase parts etc.
Thanks for the tips on checking the different file types, if you have code samples available I'd appreciate it.
0 Likes
Message 10 of 10

A.Acheson
Mentor
Mentor

I had another look at this and while the folder (project number) is easy enough to pick up the issue is when you should stop putting the folder name into the filename. 

Would running this rule manually work something like a save new document with project number rule? 

 

Running on After Save/New Document events works for a new assembly/part but will also run for any other places these files are triggered like step file imports, master part to be assembly creation, iParts, iAssembly etc.

 

 

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