I currently use a ilogic code and form that trigger when a ipt/iam is saved for the first time. Its form made up of a number of required iproperties loops until all required iproperties are filled which then the save executes. This has worked fine and we’ve seen some improvements mainly consistencies when this information is brought to the bill of materials.
The one thing I didn’t have a great deal of control over was the browser name which in my experience is either populated by what it is saved under or the reverse if the browser name is filled first.
I didn’t see any reason to amend it “if it isn’t broke, don’t fix it” until recently having seen an example of code that takes part of the file name and path to populate the iproperties.
I’d be hoping to do the reverse of this and populate the browser name so that when it saves the information is already there. Namely I’d like to take advantage of the code I already use
I’ve played about with it a little but with no success because I’m not sure of to access file name information as its not available until you save.
The areas I was focusing on were parameters such as
File name =<Part Number>_<Description>
I’m pretty certain too that id need it within the code I currently use as it triggers before save so the information would need to be there before the save dialog appears.
Unfortunatly i dont have a copy of the template itself to show the form working but i do have a copy of the code which i will attach seperatly.
Does anyone have any suggestions... Thanks in advance.
Solved! Go to Solution.
Solved by JamieSENG. Go to Solution.
Title = iProperties.Value("Summary", "Title") Author = iProperties.Value("Summary", "Author") Category = iProperties.Value("Summary", "Category") PartNumber = iProperties.Value("Project", "Part Number") Desc = iProperties.Value("Project", "Description") RevisionNumber = iProperties.Value("Project", "Revision Number") Project = iProperties.Value("Project", "Project") Do Until String.IsNullOrWhiteSpace(Title) = False And String.IsNullOrWhiteSpace(Author) = False And String.IsNullOrWhiteSpace(Category) = False And String.IsNullOrWhiteSpace(PartNumber) = False And String.IsNullOrWhiteSpace(Desc) = False And String.IsNullOrWhiteSpace(Project) = False iLogicForm.Show("iProperty Check", FormMode.Modal) Title = iProperties.Value("Summary", "Title") Author = iProperties.Value("Summary", "Author") Category = iProperties.Value("Summary", "Category") PartNumber = iProperties.Value("Project", "Part Number") Desc = iProperties.Value("Project", "Description") RevisionNumber = iProperties.Value("Project", "Revision Number") Project = iProperties.Value("Project", "Project") Loop iProperties.Value("Custom", "Finish") = Finish iLogicVb.UpdateWhenDone = True
Here's some code. Set your form buttons to Ok Cancel to give the user the option to exit out. Set your trigger to run AfterSave so the document will have a name first.
Public Sub Main() 'Only do something if the properties are not all filled and this is the active document If ThisApplication.ActiveDocument Is ThisDoc.Document AndAlso Not AllPropsFilled() 'Set PartNumber and Description Based on FileName If ThisDoc.FileName.Contains("_") Then nameParts = ThisDoc.FileName.Split("_") If nameParts.Length >= 2 Then If Not String.IsNullOrWhitespace(nameParts(0)) Then iProperties.Value("Project", "Part Number") = nameParts(0) End If If Not String.IsNullOrWhitespace(nameParts(1)) Then iProperties.Value("Project", "Description") = nameParts(1) End If End If End If Dim frmReturn As FormReturnValue Do Until AllPropsFilled() frmReturn = iLogicForm.Show("iProperty Check", FormMode.Modal) If frmReturn.Result = FormResult.Cancel Then Exit Do End If Loop iProperties.Value("Custom", "Finish") = Finish 'Happy with results so update and save If frmReturn.Result = FormResult.OK Then InventorVb.DocumentUpdate() ThisDoc.Save() End If End If End Sub Public Function AllPropsFilled() As Boolean Title = iProperties.Value("Summary", "Title") Author = iProperties.Value("Summary", "Author") Category = iProperties.Value("Summary", "Category") PartNumber = iProperties.Value("Project", "Part Number") Desc = iProperties.Value("Project", "Description") RevisionNumber = iProperties.Value("Project", "Revision Number") Project = iProperties.Value("Project", "Project") Return String.IsNullOrWhiteSpace(Title) = False AndAlso String.IsNullOrWhiteSpace(Author) = False AndAlso String.IsNullOrWhiteSpace(Category) = False AndAlso String.IsNullOrWhiteSpace(PartNumber) = False AndAlso String.IsNullOrWhiteSpace(Desc) = False AndAlso String.IsNullOrWhiteSpace(Project) = False End Function
Hi rjay
Until tomorrow i wont get a chance to see how this works exactly. Reading through the code i see how it works but it seems the effect will be the opposite to what im trying to achieve. Line 4 "Set PartNumber and Description Based on FileName" is similer to the idea i originally saw. You see my idea is the oppisite where the file name is set using the part number and the description (ideally) used while filling the form. This way when it saves the file name will be filled already.
Thanks for your input up to now through. It gives me faith that the idea is possible with the right coding. Cheers.
Sorry about that. Misread the post. I wrote some code to try and do what you really asked and ran across a few issues.
The first issue I ran into is calling the SaveAs method (which allows you to pass a name) fails if you don't supply it with a fully qualified filename. It needs to include a full path. So you would need someway to identify the folder that it needs to be saved too.
Another issue is in the event workflow itself. The Save button appears to check rather or not a the file is a new file or not. If it's a new file it prompts for a filename After it gets the filename then it begins the save process. So the Save File dialog has shown before the rule runs. The next issue would be you're invoking a save while inside of another save event. (When I tried this the results were unpredictable.)
Explicitly running the rule outside of the Save events worked fine.So at the moment I don't see how you can accomplish what you wanted completely.
Here's the code for building the file name and saving.
If String.IsNullOrEmpty(ThisDoc.Document.FullFileName) Then fExt = "ipt" fFolder = "C:\\Temp\\" fName = String.Format("{0}{1}_{2}.{3}",fFolder, iProperties.Value("Project", "Part Number"), _ iProperties.Value("Project", "Description"), fExt) ThisDoc.Document.SaveAs(fName, False) Else ThisDoc.Save() End If
Hi rjay,
See the issues you presented and decided to play around with the triggers. Compromising a little I’ve changed the original trigger to "new document". Set up an external form using the code you provided and made it more universal to both ipt & iam.
Only thing stopping me using this right away is "folder="c:\\Temp\\". There’s such an array of folders for multiple projects id be moving files around constantly.
is there a way to bring up the save dialog box to select the save location?
Replace the fFolder = "C:\\Temp\\" with
Dim folderDlg As New FolderBrowserDialog() Dim dlgResult As DialogResult = folderDlg.ShowDialog() If dlgResult = DialogResult.Ok Then fFolder = folderDlg.SelectedPath & "\\"
Else
fFolder = "C:\\Temp\\" 'Could be replaced with working directory. End If
This will display a folder picker.
At the top of your rule try adding
Imports System.Windows.Forms
What version of Inventor are you using?
Also try putting the Folder picker code in a rule by itself just to test and see if the Folder browser dialog appears.
Dim folderDlg As New FolderBrowserDialog() Dim dlgResult As DialogResult = folderDlg.ShowDialog() If dlgResult = DialogResult.Ok Then MessageBox.Show(folderDlg.SelectedPath) End If
Hi rjay,
At the moment im between PDS 15/16. Also tested the folder picker on its own and it brings up the dialog for the save location. Unfortunatly using the added "Imports System.Windows.Forms" the error still occurs.
I’ve had a little look through the process I usually take when saving and decided to leave it be for now. The amount of steps included and the compromise having to manually select the run rule compared let’s say copy and pasting the pt Num and description into the browser isn’t feasible.
My thought now is to use a custom property named File Name and in the text using =<Part Number> <Description> have the custom property appear in the form.
I’d have to change the form buttons to “Ok, Cancel and Apply” to apply the changes and update the file name box in the form. Essentially I can just copy the information from that box and paste the information to the browser.
Well thanks for your help and patients rjay with this matter. Im sure we will talk again.
Hi RJay,
Sorry for Positng this here, but i am not sure where to get help.Can you please help with the Below request.
I have used your previous i logic rule to change the sheet name. also attached.
I need help to change the IDW File name same as sheet name when saving.
i Do not have any software background and i tried to create a ilogic for this, but always get some kind of error.
Searched through internet and could not find any soution.
So, This forum is my Last resort.
Please write a ilogic code...
I need the IDW file name same as Sheet name when saving.
Please refer to the attchment for the Picture. I save seperate IDW for seperate part and assembly...
Really Appreciate your help....
Best regards,
Pavan
A couple of questions.
What error message are you getting?
You want to rename the file. Is this an existing file or a new file? If it's an existing file you can't rename the file while it is open. But you can do a saveas on the file to save it as the new name.
One thought I have is if this is a new file that hasn't been saved yet you can have a rule that is set to rename the sheet and then set the name of the file that runs before the file is saved.But be aware that you can run into the same issue I mentioned earlier in this thread in trying to name a while in the file saving event. Inventor will try and get a filename before it begins the save process. So it will prompt you for a name before you attempt to rename it if you want to use the standard save process starts. You have to have a special rule to save the file for that. We can put together a rule to accomplish that but I would like to know more of the workflow you're aiming for.
Hi RJay,
Thank you for the Propmt reply.
we save seperate IDW for each part drawing.
Inventor by default changes the File Name to base view name, in this case it is my part number.(R2-CUSTOMER-100-001_00).
With your code, i was able to rename the sheet from Sheet 1 to >>(R2-CUSTOMER-100-001_00 SPACER BLOCK).
When i press save for 1st time the file "save as"window prompt will only show R2-CUSTOMER-100-001_00 with out description.
I need to add this description to the file name while saving also.
With many drawings it is much easier to rember the part name like, Spaceblock, End support, vertical web than partnumber, and this description makes it easier to locate the file easily while browsing through IDWS.
At Present our company is not using any Iproperties and they key in all by Prompted entry. So i am trying to change and introduced i proporties enabled title block , but stuck at this request from them.
While trying i got all this message:
Error on line 1: proporty access must assign to the propoerty or use its value.
Thank you for the help..
Thanks and Best Regards,
Pavan
If i add a ilogic in my template for adding the name of the file as description in iproperty. but as soon as i use the template and give the name to the file and save it the description box just saves the names of the template rather saving the name of the file given.
Can anyone help me this ?
Hi @yatinp175. You will need to provide a lot more detailed information than that for us to be able to tell you with any accuracy why things are not working properly, or how to fix the problems. A good start would be including the code that you are currently using. Another good start would be describing the steps involved in the process in as much detail as possible, maybe even with a bulleted list. It sounds like you expect the 'Description' iProperty's value to change to match some portion (path, file name, file extension, all, some ?) of the file name of the newly created document, after you have performed a SaveAs operation. Does that sound accurate? Well then, we would need to know how the new document is being created. For instance, are you using the 'New' command, where it presents you with a dialog to choose a template to create the new document from, then generates a new document that is not saved yet? Or are you opening the actual template document itself, then doing a SaveAs operation, to directly create a new file on disk for the new document? Knowing the details of how these things are being done is usually important in these types of situations.
SaveAs scenarios are the most difficult to deal with, because, unlike regular Save operation and SaveCopyAs operation, where you are left with a reference to the document that just got saved...the SaveAs operation leaves us with the same reference to the original document, instead of the new document that just got created. The only way to get a reference to the new document that gets created by a SaveAs operation is to capture the 'FullFileName' (full file path, file name, and file extension) that was specified during the SaveAs operation, then use that to 'Open' that file, to get a reference to the document that gets loaded from that file. The iLogic 'Event Triggers' dialog Event named "Before Save Document" will not help, because it has not been saved yet. The one named "After Save Document" will not help either, because it remains focused on the 'original' document (which is the Document that triggered the event). Not only that but, some events have a 'before' and 'after' timing aspect to them, and during the 'before' timing, the new file has not been created yet, so no information is available for new file name yet, then during the 'after', when that information is available, if you set the value of that iProperty, that will make the document 'dirty' again, so it would need to be saved yet again. If the document was closed after save, but the iProperty was changed after save, then when you open the document again, the iProperty will have its original value, because it did not get changed before save. And you do not want to insert instructions to save a document inside of a code that runs after save, because that can cause an endless cycle of trying to save the document.
The Inventor API events (outside of the iLogic 'Event Triggers') usually give us much more control than what the iLogic 'Event Triggers' can give you, but they can be complicated to use, and are generally best managed within an Inventor add-in, not just regular iLogic rules. One example is the ApplicationEvents.OnSaveDocument Event, which says that it is only for regular 'Save' and 'SaveCopyAs' scenarios, not for 'SaveAs' scenarios. But then there is no ApplicationEvents.OnSaveAsDocument Event. However, there is a FileUIEvents.OnFileSaveAsDialog Event, but it only gets triggered by the actual user interface dialog getting called to be shown, not by doing a SaveAs by code. Some of the Inventor API tools can likely get us a reference to the 'new' document object, or the full file name of the 'new' file, but that process may be more complicated than you initially had in mind, possibly requiring an Inventor add-in to manage it.
Wesley Crihfield
(Not an Autodesk Employee)
I have created my own template in the autodesk inventor. The concern for me is when i do use my template and save it as a new document the default setting shows the part number in the i property to be the file name after saving the document i.e it automatically fills the details of name of the file to the part number i just want that to be happen in the description iproperty.
I tried the code below in my template so that i could get what i want but instead after saving the document , it just fills the name of the template rather than saving the file name.
' Get the current document
doc = ThisDoc.Document
' Construct the new file name with the description
Filename_Description = iProperties.Value("Project", "Part Number") & "_" & iProperties.Value("Project", "Description")
' Check if the description iProperty has a value
If Trim(iProperties.Value("Project", "Description")) <> "" Then
' Set the display name to the new file name with description
doc.DisplayName = Filename_Description
Else
' Reset the display name if no description is provided
doc.DisplayName = ""
End If
Hi @yatinp175. Thank you for posting your code, but that is still not much information. You still did not answer all of my questions.
Below is an alternate iLogic rule that includes a lot more 'feedback' information about when something is encountered that you may not be expecting, but it requires that you have the tab for your iLogic Log window available (it does not need to be the 'active' tab). You must also have the iLogic Log level set to either 'Debug' or 'Trace', to see those levels of iLogic Log entries in the iLogic Log window. That can either be set in the iLogic Configuration settings (Tools tab / Options panel), or within the iLogic rule itself, at the bottom of the rule editor dialog. Then, after the rule runs, click on that iLogic Log tab to review any notes that this rule may have written to it, for a better idea of what it may have encountered.
However, even with all those checks included, there is still no guarantee that it will work the way you want, because like I said before, the SaveAs scenario is complicated to work with.
Dim oDoc As Document = ThisDoc.Document
If oDoc.FileSaveCounter = 0 Then
Logger.Debug("Document is not saved yet, so no path or file name exist for it yet!")
Return 'exit rule
End If
Dim sFileNameWithoutExtension As String = ThisDoc.FileName(False)
If sFileNameWithoutExtension = "" Then
Logger.Debug("FileName was empty!")
Return 'exit rule
End If
'get value of Part Number iProperty
Dim sPartNumber As String = oDoc.PropertySets.Item(3).Item(2).Value
If sPartNumber = "" Then
Logger.Debug("Part Number is empty!")
Return 'exit rule
ElseIf sPartNumber <> sFileNameWithoutExtension Then
Logger.Debug("Part Number does not match file name, without extension!")
Return 'exit rule
End If
'get value of Description iProperty
Dim sDescription As String = oDoc.PropertySets.Item(3).Item(14).Value
If sDescription = "" Then
Logger.Debug("Description is empty!")
Return 'exit rule
End If
Dim sNewDisplayName As String = sFileNameWithoutExtension & "_" & sDescription
'set new value to Document.DisplayName
oDoc.DisplayName = sNewDisplayName
oDoc.Update2(True)
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.