Safe the assembly file

Safe the assembly file

jarle_oudalstoelEN4BR
Enthusiast Enthusiast
137 Views
3 Replies
Message 1 of 4

Safe the assembly file

jarle_oudalstoelEN4BR
Enthusiast
Enthusiast

I am working on a rule that will save my file in a location I'm picking. The file name is generated by parameters. 

 

I am getting this security alert.

 

jarle_oudalstoelEN4BR_0-1788550897588.png

 

I do know if I save the file the rule will work but that defeats the purpose of the rule. 

 

Here is the rule I'm using. 

 

Dim oDoc As Document = ThisDoc.Document

' Get parameter values
Dim oIT As String = Parameter("ITEM_TEXT")
Dim oIN As String = Parameter("ITEM_NUMBER")
Dim oJobN As String = Parameter("JOB_NUMBER")
Dim oEDLIN As String = Parameter("EDLIN_NUMBER")

' Build filename
Dim NewFileName As String = oJobN & " - " & oEDLIN & " - " & oIT & oIN &".ipt"


' Select folder
Dim folderDlg As New System.Windows.Forms.FolderBrowserDialog
	folderDlg.Description = "Select folder to save file"
	If folderDlg.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
		Return
	End If

Dim TargetFolder As String = folderDlg.SelectedPath

' Build filename from parameter
Dim FileName As String = Parameter("PART_NUMBER")

' Full path
Dim NewFilePath As String = System.IO.Path.Combine(TargetFolder, NewFileName)

' Save As
ThisDoc.Document.SaveAs(NewFilePath, True)

MessageBox.Show("File saved to:" & vbCrLf & NewFilePath)

If anyone has ideas for how I can get this to work that would be greatly appreciated. 

 

Jarle

0 Likes
Accepted solutions (1)
138 Views
3 Replies
Replies (3)
Message 2 of 4

JhoelForshav
Mentor
Mentor

Hi @jarle_oudalstoelEN4BR 

 

Could you get around it by using Inventors native FileDialog? See example:

Dim oDoc As Document = ThisDoc.Document


Dim oIT As String = Parameter("ITEM_TEXT")
Dim oIN As String = Parameter("ITEM_NUMBER")
Dim oJobN As String = Parameter("JOB_NUMBER")
Dim oEDLIN As String = Parameter("EDLIN_NUMBER")


Dim NewFileName As String = _
oJobN & " - " & oEDLIN & " - " & oIT & oIN


Dim fileEnd As String
Dim fileFilter As String

Select Case oDoc.DocumentType

	Case DocumentTypeEnum.kPartDocumentObject
		fileEnd = ".ipt"
		fileFilter = "Inventor Part Files (*.ipt)|*.ipt"

	Case DocumentTypeEnum.kAssemblyDocumentObject
		fileEnd = ".iam"
		fileFilter = "Inventor Assembly Files (*.iam)|*.iam"

	Case DocumentTypeEnum.kDrawingDocumentObject
		fileEnd = ".idw"
		fileFilter = "Inventor Drawing Files (*.idw)|*.idw"

	Case DocumentTypeEnum.kPresentationDocumentObject
		fileEnd = ".ipn"
		fileFilter = "Inventor Presentation Files (*.ipn)|*.ipn"

	Case Else
		MessageBox.Show("Unsupported document type.")
		Return

End Select

Dim oFileDlg As Inventor.FileDialog = Nothing

ThisApplication.CreateFileDialog(oFileDlg)

oFileDlg.DialogTitle = "Save Part As"
oFileDlg.Filter = fileFilter
oFileDlg.FileName = NewFileName
oFileDlg.CancelError = True

Try

	oFileDlg.ShowSave()

Catch
	' User cancelled
	Return

End Try


Dim NewFilePath As String = oFileDlg.FileName

MsgBox(NewFilePath)
ThisDoc.Document.SaveAs(NewFilePath, False)

MessageBox.Show( _
"File saved to:" & vbCrLf & _
NewFilePath, _
"Save Complete")
0 Likes
Message 3 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

This message is displayed because iLogic checks the code for potentially harmful code.

You can disable this in configuration. Or you can configure rules, folder which will not be checked.

MichaelNavara_0-1788788537330.png

 

0 Likes
Message 4 of 4

josebaqueror
Advocate
Advocate
That security alert is iLogic's rule-security prompt. It fires when a rule does file operations (saving to a path, reading or writing external files) from a location Inventor doesn't trust. It isn't your code being wrong, it's the trust layer. Two ways to stop it: 1. Trust the location. In Tools, Options, iLogic (the security / Files settings), add the folder your rule writes to as a trusted path. Once the target and the rule's source are trusted, the prompt stops. 2. If it's the rule itself being flagged (an external rule running from a shared folder), add that rule folder to the trusted iLogic paths too. A rule run from an untrusted external location triggers the alert even when the save target is fine. Worth knowing: this is a deliberate safety gate, it stops a random rule from writing files without you noticing, so whitelisting the specific paths is the right fix rather than trying to suppress it in code. What does the alert actually say, and is your rule internal to the document or an external rule in a shared folder? If it's external, it's almost always the rule's own location that needs trusting, not just the save target.
Jose Luis Baquero Rivera
Mechanical Engineer
Open to projects, feel free to contact me
josebaqueror.com
https://www.linkedin.com/in/joseluisbaquerorivera/