iLogic - "save as" pop-up box

iLogic - "save as" pop-up box

ChristianAndersenIsmyname
Advocate Advocate
1,957 Views
12 Replies
Message 1 of 13

iLogic - "save as" pop-up box

ChristianAndersenIsmyname
Advocate
Advocate

Hey,

How can I force iLogic to force the save-as pop-up box (as if I'm pressing CTRL+S). Can I make it do something like

MessageBox.Show("Save now?",, MessageBoxButtons.YesNo)
If vbYes Then
CTRL+S
End If

 

I also have to make it wait until 'DONE' is pressed in Form box.

I've added a Screencast to show what I mean.

 

I've reduced the length of the code, as some parts are only logic to create part.

'------ CREATE PART ------
iLogicForm.Show("Dimensions")
Feature.IsActive("Revolution1") = True
Feature.IsActive("Chamfer1") = True
Feature.IsActive("Chamfer2") = True

(Code that I've removed here)

'------- SAVE PART -------
' Save box should only come up after we've clicked DONE in FORM dialog box
'MessageBox.Show("File must be saved before making a drawing." & vbNewLine & vbNewLine & "Save now?", "Save part", MessageBoxButtons.YesNo)

'If vbYes Then
'ThisDoc.Document.SaveAs(NewFileNameAndExtension , True)

'End If
0 Likes
Accepted solutions (2)
1,958 Views
12 Replies
Replies (12)
Message 2 of 13

WCrihfield
Mentor
Mentor

You could create a simple little iLogic rule, that only does the stuff after ---Save Part---, then drag that rule over into your form as a button.  Then you can eliminate the Done button, and only have the rule button.  Within the Form Editor, you can set the action to take when you click on that button.  You can set it to Apply then Run the rule.  That should do what you want.

You can use SendKeys to simulate pressing that keyboard keys combination too, instead of the ThisDoc.Document.SaveAs() method.

You could also execute the command behind the Control+S shortcut.

(AppFileSaveAsCmd)

(AppFileSaveCmd)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 13

bradeneuropeArthur
Mentor
Mentor

Hi,

 

With creating an add-in i.e. Vb.net you have a BeforeSave Or AfterSave Event.

But that is not what you need, correct?

 

Regards

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 13

ChristianAndersenIsmyname
Advocate
Advocate

That's a good idea that I didnt know about. Thanks.

ChristianAndersenIsmyname_0-1594898114186.png

 

But, what code am I gonna enter in this Rule?

It seems like a simple task if the file has already been saved before, but a bit more tricky when its a new part?

0 Likes
Message 5 of 13

WCrihfield
Mentor
Mentor

Try this:

Dim oSave As MsgBoxResult =  MsgBox("File must be saved before making a drawing." & vbCrLf & _
"Save now?", vbYesNo + vbQuestion, "SAVE?")

If oSave = vbYes Then
	ThisApplication.CommandManager.ControlDefinitions.Item(AppFileSaveAsCmd).Execute
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 13

ChristianAndersenIsmyname
Advocate
Advocate

Getting a error.

 

Error in rule: Save file, in document: Part23

Feil parameter. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))


System.ArgumentException: Feil parameter. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.ControlDefinitions.get_Item(Object Index)
   at ThisRule.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Side note: Since this is a new part, should be able to enter desired file name and save location (path).

So if I'm able to something like picture below, that would be awesome.

ChristianAndersenIsmyname_0-1594899216115.png

 

0 Likes
Message 7 of 13

I found a similar post: https://forums.autodesk.com/t5/inventor-customization/ilogic-save-as-rule/td-p/6421308

I want mostly the same as this, but I also want to be able to set save location (preferably in the same box as Forms).

 

I've therefore added two custom properties.

Custom Property: File Name

Custom Property: Save Location

I've added these two to Forms, so its easy to fill out, but how can I adjust this code to read those values?

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
Dim FName As String = oDoc.FullFileName
Dim FNP As Integer = InStrRev(FName, "\", -1)
Dim oPath As String = Left(FName, FNP)
Dim oNewName As String = InputBox("Enter New File Name", "Save as", "Name")

' If the user closes the input box, then stop the function
If oNewName = vbNullString Then Exit Sub

Dim oType As String
Select Case oDoc.DocumentType
Case kPartDocumentObject:     oType = ".ipt"
Case kAssemblyDocumentObject: oType = ".iam"
Case kDrawingDocumentObject:  oType = ".idw"
End Select

oDoc.SaveAs(oPath & oNewName & oType, True)
0 Likes
Message 8 of 13

WCrihfield
Mentor
Mentor

I forgot to enclose the name of the command in Quote marks.  It should be like this:

Dim oSave As MsgBoxResult =  MsgBox("File must be saved before making a drawing." & vbCrLf & _
"Save now?", vbYesNo + vbQuestion, "SAVE?")

If oSave = vbYes Then
	ThisApplication.CommandManager.ControlDefinitions.Item("AppFileSaveAsCmd").Execute
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 13

WCrihfield
Mentor
Mentor

Is this what you want?

 

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
Dim oCProps As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
Try
	Dim oFileName As String = oCProps.Item("File Name").Value
	Dim oPath As String = oCProps.Item("Save Location").Value
	Dim oType As String = ".ipt"
	oDoc.SaveAs(oPath & oFileName & oType, True)
Catch oEx As Exception
	MsgBox("The SaveAs Sub failed." & vbCrLf & _
	"The error message is as follows:" & vbCrLf & _
	oEx.Message, vbOKOnly + vbExclamation, "SaveAs Error")
End Try

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 13

ChristianAndersenIsmyname
Advocate
Advocate

I used your code now, and it's still not doing as it's supposed to.

 

Picture below is showing that I've entered File Name and Save Location in the Form box.

After everything is filled out, I press Save File (which runs the Rule from your previous post).

iProperties are saying the file is "Not Saved".

ChristianAndersenIsmyname_1-1594907906834.png

 

0 Likes
Message 11 of 13

Accepted solution

The path needs an additional "\"

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 13

WCrihfield
Mentor
Mentor
Accepted solution

You either need to include an "\" in the path you supply within the Form, or within the oPath variable in the code, for this to work.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 13 of 13

ChristianAndersenIsmyname
Advocate
Advocate

Thank you! This worked 😄