Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

File Name/iLogic

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
JamieSENG
10415 Views, 13 Replies

File Name/iLogic

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.

13 REPLIES 13
Message 2 of 14
JamieSENG
in reply to: JamieSENG

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
Message 3 of 14
rjay75
in reply to: JamieSENG

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

 

 

Message 4 of 14
JamieSENG
in reply to: rjay75

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.

Message 5 of 14
rjay75
in reply to: JamieSENG

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
Message 6 of 14
JamieSENG
in reply to: rjay75

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?

Message 7 of 14
rjay75
in reply to: JamieSENG

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. 

Message 8 of 14
JamieSENG
in reply to: rjay75

I did what you suggested rjay, Did i miss something?

 

Capture.JPG

Message 9 of 14
rjay75
in reply to: JamieSENG

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
Message 10 of 14
JamieSENG
in reply to: rjay75

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.

Message 11 of 14
Anonymous
in reply to: rjay75

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

Message 12 of 14
rjay75
in reply to: Anonymous

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.

Message 13 of 14
Anonymous
in reply to: rjay75

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

Message 14 of 14
aronmatheus
in reply to: rjay75

@rjay75  Is there any way to rename the part without losing the parameter link to the name of the part using ilogic?

aronmatheus_0-1624449549649.png

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report