Need help with ilogic File Save rule...

Need help with ilogic File Save rule...

JamesNordgren
Advocate Advocate
7,817 Views
8 Replies
Message 1 of 9

Need help with ilogic File Save rule...

JamesNordgren
Advocate
Advocate

Hello,  can someone point out why this code does not work?  Strange thing is, it seems to have worked and saved my file the first time I ran it, but then will not work again.  SaveAs file dialog opens, I hit OK to save, and nothing happens.  No error, just nothing.

Code pasted below: I copied from an included snippet, and modified it.

 

Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt|All Files (*.*)|*.*"
'oFileDlg.Filter = "XML Files (*.xml)|*.xml"
'
oFileDlg.Filter = "Excel Files (*.xls;*.xlsx)|*.xls;*.xlsx"
'
oFileDlg.Filter = "Text Files (*.txt;*.csv)|*.txt;*.csv"
'
oFileDlg.Filter = "SAT Files (*.sat)|*.sat"
'
oFileDlg.Filter = "IGES Files (*.igs)|*.igs"
'
oFileDlg.Filter = "Step Files (*.stp)|*.stp"
'
oFileDlg.DialogTitle = "Select a File"
'
oFileDlg.InitialDirectory = "C:\Vault Workspace\Projects\DSE Jobs\" 'ThisDoc.Path
oFileDlg.FileName = "C:\Vault Workspace\Projects\DSE Jobs\" & Left(sJobNumber,3) & "\" & sJobNumber & "EXTERNAL\ASSEMBLY\" & sJobNumber & "." & PartNumbers & ".ipt" 'ThisDoc.Path
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowSave()
'If Err.Number <> 0 Then
'
MessageBox.Show("File not SAVED.", "Dialog Cancellation")
'
ElseIf oFileDlg.FileName <> "" Then
'
selectedfile = oFileDlg.FileName
'
MessageBox.Show("File " & selectedfile & " was selected.", "Dialog Selection Made")
'
End If
0 Likes
Accepted solutions (1)
7,818 Views
8 Replies
Replies (8)
Message 2 of 9

Curtis_Waguespack
Consultant
Consultant

Hi JNORDGREN,

I think this line is generating an error:

oFileDlg.FileName = "C:\Vault Workspace\Projects\DSE Jobs\" & Left(sJobNumber,3) & "\" & sJobNumber & "EXTERNAL\ASSEMBLY\" & sJobNumber & "." & PartNumbers & ".ipt"  'ThisDoc.Path

And the On Error Resume Next is hiding it.

 

Comment out On Error Resume Next and I think you'll see it.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 3 of 9

JamesNordgren
Advocate
Advocate

Thank you Curtis,

 

However, it still doesnt work after commenting out the 'ON ERROR RESUME'.

 

I have attached the rule in a file... any other ideas why it creates the dialog but does not save the file?  

0 Likes
Message 4 of 9

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi JNORDGREN,

 

I'm not sure you need the dialog box for what you're doing.

 

If you are just trying to save the file as a new file you might not need to create a dialog box, instead you can use something like this:

 

sName = iProperties.Value("Project", "Part Number") & "_Test.ipt"
sPath = "C:\Temp\"

'Save File As
'True saves off a copy of this file as the new name
'False saves this file as the new name
ThisDoc.Document.SaveAs(sPath & sName , False)

 

If you want the dialog box so that the user can browse for the location, you can use something like the example at this link:

http://inventortrenches.blogspot.com/2012/10/ilogic-adding-save-as-dialog-box.html

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 5 of 9

JamesNordgren
Advocate
Advocate

Thanks!!  The link to your blog had exactly what I was missing.

0 Likes
Message 6 of 9

Anonymous
Not applicable

Hi Curtis,

 

Sorry to HiJack this link

 

I too am finding your code helpful, but is there a way to define the 'WorkSpacePath' ?

 

I would like to set it to a particualr folder within the workspace area.

 

Regards

 

Gareth

0 Likes
Message 7 of 9

Anonymous
Not applicable

The following code was written by me for the sole purpose saving an Inventor file so that the file Title begins the saved file name along with the Part Number something like:

 

Framus (123456).i?? where

Title = Framus and Part Number = 123456

 

The code is also attempting to see if either field is blank.  If either Title or Part Number are blank, the code needs to allow the user to fill in the missing information.  I wish to use this code with any of the Inventor file types a user could create.  The current code doesn't work at the moment.

 

 

 

'Collect information to complete file naming convention when saving files

'Define the active document
oDoc = ThisDoc.Document

'Look-up values for both the Title and Partnumber
oTitle = iProperties.Value("Summary", "Title")
oPartNumber = iProperties.Value("Project", "Part Number")

 

'Test the Title to see if it's blank
If oTitle = "" Then
i = MessageBox.Show("Title info must be filled out before saving file!", "Title Information is missing", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End If

 

If oPartNumber = "" Then
i = MessageBox.Show("Part Number must be filled out before saving file!", "Part Number is missing", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
End If


'Show Form to allow entry of Title and PartNumber Information

iLogicForm.Show("Title Information", FormMode.Modal)

 

'Set value of currrent file name

oNewFileName =  iProperties.Value("Summary", "Title") & " " & "(" & iProperties.Value("Project", "Part Number") & ")"

 

oDoc.SaveAs(oNewFileName, False) 'True = Save As Copy & False = Save As

 

It's my hope to write this rule as an External Rule so that it can be run at any time on any Inventor file.

 

Any help would be appreciated!

0 Likes
Message 8 of 9

Curtis_Waguespack
Consultant
Consultant

Hi  JimStrenk.

 

This should work for you:

 

'check for blank iProperty
If iProperties.Value("Summary", "Title") = "" Then
'prompt user for info if iProperty is blank
oTitle = InputBox("Title info must be filled out before saving file!", _
"iLogic - Title", iProperties.Value("Summary", "Title"))
    'check for empty input
    'in case the user cancels out of the input box
    If oTitle = "" Then
    Return 'end rule
    Else
    End if
'write user input to the iProperty
iProperties.Value("Summary", "Title") = oTitle
End If

'check for blank iProperty
If iProperties.Value("Project", "Part Number") = "" Then
'prompt user for info if iProperty is blank
oPartNumber = InputBox("Part Number must be filled out before saving file!", _
"iLogic - Part Number", iProperties.Value("Project", "Part Number"))
    'check for empty input
    'in caset he user cancels out of the input box
    If oPartNumber = "" Then
    Return 'end rule
    Else
    End if
'write user input to the iProperty
iProperties.Value("Project", "Part Number") = oPartNumber
End If

'Set value of currrent file name
oNewFileName =  iProperties.Value("Summary", "Title") _
& " " & "(" & iProperties.Value("Project", "Part Number") & ")"

oDoc = ThisDoc.Document
'Save the file
'True = Save As Copy
'False = Save As
oDoc.SaveAs(oNewFileName, False)

 I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 9 of 9

Anonymous
Not applicable

Curtis, close, very close.  The code is not working however.  Your code did allow me to input the Title and Part Number iProperties.  Once entered, the code fails.  These are the error messages that I get when running your code:

 

ERROR MESSAGE:

Error in rule: iLogic File Namer, in document: Part1

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

And ...

 

MORE INFO

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)

at LmiRuleScript.Main()

at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

My 'design intent' is to run this rule externally, be independent of Inventor file type, and also independent of whether Title and Part Number are filled or blank.  Code to work on currently opened file, and save the current file, if possible.

 

Here's the code as entered in the iLogic Editor:

 

'check for blank iProperty

 

If iProperties.Value("Summary", "Title") = "" Then

 

'prompt user for info if iProperty is blank

oTitle = InputBox("Title info must be filled out before saving file!", _
"iLogic - Title", iProperties.Value("Summary", "Title"))

 

'check for empty input
'in case the user cancels out of the Input box

 

If oTitle = "" Then
Return 'end rule

Else

 

End If

 

'write user input to the iProperty

iProperties.Value("Summary", "Title") = oTitle
End If

 

'check for blank iProperty

If iProperties.Value("Project", "Part Number") = "" Then

 

'prompt user for info if iProperty is blank

oPartNumber = InputBox("Part Number must be filled out before saving file!", _
"iLogic - Part Number", iProperties.Value("Project", "Part Number"))

'check for empty input

'in case the user cancels out of the input box

If oPartNumber = "" Then

Return 'end rule
Else

 

End If

 

'write user input to the iProperty
iProperties.Value("Project", "Part Number") = oPartNumber

End If

 

'Set value of currrent file name
oNewFileName =  iProperties.Value("Summary", "Title") _
& " " & "(" & iProperties.Value("Project", "Part Number") & ")"

 

oDoc = ThisDoc.Document

 

'Save the file 'True = Save As Copy 'False = Save As
oDoc.SaveAs(oNewFileName, False)

 

'End of iLogic File Namer.iLogicVB Code

 

System Specs.: Windows 7 Pro, PDSU 2014, Vault Basic 2014 Client, Vault Basic 2014Server

 

BTW, I've enjoyed purchasing and reading all of your Master Autodesk Inventor Series.  I'm sorry to report I was late in purchasing the 2014 Edition (July 2, 2013).  I enjoyed the reading more than the purchasing.  Tee hee!

 

How did you and the other major iLogic contributors learn this stuff?  While your books do a good job of discussing the basics if iLogic, are there other sources you or other might recommend regarding writing iLogic code?  If you had the time, I'd ask that you author "The iLogic Bible".

 

I highly recommend your web site for more information about using iLogic.

 

Again, thank you for your assistance in helping me with the iLogic code.  It is appreciated!  Smiley Very Happy 

0 Likes