error code

error code

johan.degreef
Advisor Advisor
3,314 Views
41 Replies
Message 1 of 42

error code

johan.degreef
Advisor
Advisor

I get a lot of these error codes lately, with this code. Does anyone sees where it comes from?

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Document.SaveAs(String FileName, Boolean SaveCopyAs)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

 

Imports System.IO
GetInput :

Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 000000)

If Six_Digit = "" Then
	Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
GoTo GetInput

End If


Dim oDoc As Document
Dim sFilename As String

'hard code path
oLibrary_Folder = "C:\PTN_Part_Library\"


Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories)

For Each oFilename As String In oFilenames
	If oFilename.Contains(Six_Digit) Then
		Dim oOptions As Inventor.NameValueMap
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
		sFilename = oFilename
		Exit For
	End If
Next

If sFilename = "" Then
	MessageBox.Show("No matching libary file found.", "iLogic")
	Return
End If

iCounter = 0

'path from current file
oActiveAssemblyfolder = ThisDoc.Path & "\"

'path from current project file ( *.ipj)
oProjectfolder = _
ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath & "\"

Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories)

'count existing project files					  
For Each oFilename As String In oProject_Filenames
	If oFilename.Contains(Six_Digit) Then
		iCounter = iCounter + 1
	End If
Next

'increment counter
iCounter = iCounter + 1


'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", - 1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)


If iCounter < 10 Then
	iCounter = "00" + CStr(iCounter)
ElseIf iCounter < 100 Then
	iCounter = "0" + CStr(iCounter)
Else
	iCounter = CStr(iCounter)
End If

oNewName = ShortName & "_" & iCounter

oPathandName = oActiveAssemblyfolder & oNewName & oExt

'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close

'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)


'insert new occurence
'Dim oOcc As ComponentOccurrence
'oOcc = oAsmCompDef.Occurrences.Add( _
'oPathandName, oMatrix)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent,oPathandName) 
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute


'oOcc.Grounded = False
'ThisDoc.Document.SelectSet.Select(oOcc)

']

'MessageBox.Show("New file created: " & vbLf & oPathandName, "iLogic")

 

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Accepted solutions (1)
3,315 Views
41 Replies
Replies (41)
Message 41 of 42

JhoelForshav
Mentor
Mentor

Ok... Using System.DateTime seems to work better:

 

GetInput :

Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 000000)

If Six_Digit = "" Then
	Return
Else If Len(Six_Digit) <> "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
GoTo GetInput

End If



Dim oDoc As Document
Dim sFilename As String

'hard code path
oLibrary_Folder = "C:\PTN_Part_Library\"


Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories)

For Each oFilename As String In oFilenames
	Dim oFileNameNoExt As String = System.IO.Path.GetFileNameWithoutExtension(oFilename)
	If oFileNameNoExt.Contains(Six_Digit) AndAlso oFileNameNoExt.Length = 11 Then
		Dim oOptions As Inventor.NameValueMap
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
		sFilename = oFilename
		Exit For
	End If
Next

If sFilename = "" Then
	MessageBox.Show("No matching libary file found.", "iLogic")
	Return
End If

'path from current file
Dim oActiveAssemblyfolder As String = ThisDoc.Path & "\"




'find the postion of the last backslash in the path
Dim FNamePos As Integer = InStrRev(sFilename, "\", -1)
'get the file name with the file extension
Dim oName As String = Right(sFilename, Len(sFilename) -FNamePos)
'get the file name (without extension)
Dim ShortName As String = Left(oName, Len(oName) -4)
'get extension
Dim oExt As String = Right(oName, 4)


Dim oNewName As String = ShortName & "_" & System.DateTime.Now.ToString("yyyyMdHHmmss")

Dim oPathandName As String = oActiveAssemblyfolder & oNewName & oExt

oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = ShortName
'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close

'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition



' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)



'insert new occurence
'Dim oOcc As ComponentOccurrence
'oOcc = oAsmCompDef.Occurrences.Add( _
'oPathandName, oMatrix)

ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPathandName)
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute


'oOcc.Grounded = False
'ThisDoc.Document.SelectSet.Select(oOcc)

']

'MessageBox.Show("New file created: " & vbLf & oPathandName, "iLogic")
Message 42 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

Wow man, You have been extremely helpfull! Many Thanks

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025