error code

error code

johan.degreef
Advisor Advisor
3,263 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,264 Views
41 Replies
Replies (41)
Message 2 of 42

JhoelForshav
Mentor
Mentor

Hi @johan.degreef 

Usually when SaveAs fails for no apparent reason it's because inventor has a document with that file name in memory. You might have deleted the document in your file system but it's still kept in inventors memory.

 

Try this line:

ThisApplication.Documents.CloseAll(True)

And then run your code. It'll close all unreferenced documents in memory.

Message 3 of 42

bradeneuropeArthur
Mentor
Mentor

Hi @johan.degreef 

 

Put some messageboxes in the code an take a look till where the codes runs!

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 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

This did not help. Thanks anyway

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 5 of 42

JhoelForshav
Mentor
Mentor

Ok...
Since you're using ThisDoc.Path, have you saved the document in which you run the rule? Otherwise that will not return a valid path.

0 Likes
Message 6 of 42

johan.degreef
Advisor
Advisor

@bradeneuropeArthur 

 

thanks for the suggestion

After clicking OK on messagebox 6, the error appears. i do not see messagebox 7

 

 

 

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

MessageBox.Show("Message1", "Title")


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

MessageBox.Show("Message2", "Title")

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

MessageBox.Show("Message3", "Title")

'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)

MessageBox.Show("Message4", "Title")


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

MessageBox.Show("Message5", "Title")

oNewName = ShortName & "_" & iCounter

oPathandName = oActiveAssemblyfolder & oNewName & oExt

MessageBox.Show("Message6", "Title")

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

MessageBox.Show("Message7", "Title")

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

MessageBox.Show("Message8", "Title")

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

MessageBox.Show("Message9", "Title")


'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
Message 7 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 


@JhoelForshav wrote:

Ok...
Since you're using ThisDoc.Path, have you saved the document in which you run the rule? Otherwise that will not return a valid path.


Yes

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 8 of 42

JhoelForshav
Mentor
Mentor

Could you have a look at oPathAndName with a msgbox to make sure it returns a valid existing path and that the file doesn't already exist?

 

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

MessageBox.Show("Message1", "Title")


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

MessageBox.Show("Message2", "Title")

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

MessageBox.Show("Message3", "Title")

'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)

MessageBox.Show("Message4", "Title")


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

MessageBox.Show("Message5", "Title")

oNewName = ShortName & "_" & iCounter

oPathandName = oActiveAssemblyfolder & oNewName & oExt

MessageBox.Show("Message6", "Title")

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

MessageBox.Show("Message7", "Title")

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

MessageBox.Show("Message8", "Title")

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

MessageBox.Show("Message9", "Title")


'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 9 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

It returns:

 

Knipsel.JPG

 

If I check, that file DOES already exists, but why doesn't the search code DOESN'T finds it, after all these years of working flawlessly?

 

EDIT: After opening that part _025.ipt itself and resave it, it's get found. This part is there for days, it is not that i placed that just before.

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 10 of 42

bradeneuropeArthur
Mentor
Mentor

Have you enabled "Show extension for known filetypes" in Explorer

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 11 of 42

johan.degreef
Advisor
Advisor

Yes...

Don't tell me that this is the cause 🙂

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 12 of 42

JhoelForshav
Mentor
Mentor

Hi @johan.degreef 

I'd say maybe your loop to set the iCounter variable isn't that stable. It only counts how many files are in the path containing the six digits and then assumes the number should be that +1. So If there would be 5 files numbered 1,2,3,4,6 you'd get this error.

 

It looks like your files ends with "_XXXX.ipt/iam" where XXXX is the number. I'd suggest looking at these numbers and take the highest value + 1 to make sure it's unique.

 

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

MessageBox.Show("Message1", "Title")


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

MessageBox.Show("Message2", "Title")

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
		Dim oFileNameSplit As String() = System.IO.Path.GetFileNameWithoutExtension(oFilename).Split("_")
		If CInt(oFilename.Length - 1) > iCounter Then iCounter = CInt(oFilename.Length - 1)
	End If
Next



MessageBox.Show("Message3", "Title")

'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)

MessageBox.Show("Message4", "Title")


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

MessageBox.Show("Message5", "Title")

oNewName = ShortName & "_" & iCounter

oPathandName = oActiveAssemblyfolder & oNewName & oExt

MessageBox.Show("Message6", "Title")

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

MessageBox.Show("Message7", "Title")

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

MessageBox.Show("Message8", "Title")

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

MessageBox.Show("Message9", "Title")


'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")

 

 

0 Likes
Message 13 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

You might be right, because at the time of the error, there were +-24 parts of "PIPE_200213_xxx.ipt" present in the project. It seems that the numbers are not counted in a row 001, 002, 003, but rather 001, 006, 007, 009 etc. with gaps.

It might be the case that during the project files were deleted, because they were not needed anymore.

 

When you say " It only counts how many files are in the path with containing the sig digits and then assumes the number should be that +1". i hope he count the files in the whole projectfolder - that was the intention at least.

The parts are saved in the folder where the assembly resides, so that can be all over the project.

 

If I ever wanted to correct this bit of code, i need to rely on you guys, because I have too less programming skills for that.

Maybe I should wait to see if it happens again after disabling "Show extension for known filetypes" in Explorer.

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 14 of 42

JhoelForshav
Mentor
Mentor

@johan.degreef 

Yes... Sloppy written text by me. But you get the idea and I think we might have found the problem then.

Does the code I posted work? 🙂

0 Likes
Message 15 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

Your code works, but I'll check if it works when I get the error again with my old code.

 

You did change this bit, right? he does look in all folders in the project right?

 

'count existing project files					  
For Each oFilename As String In oProject_Filenames
	If oFilename.Contains(Six_Digit) Then
		Dim oFileNameSplit As String() = System.IO.Path.GetFileNameWithoutExtension(oFilename).Split("_")
		If CInt(oFilename.Length - 1) > iCounter Then iCounter = CInt(oFilename.Length - 1)
	End If
Next

 

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 16 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

Sorry JhoelForshav, but I had the error again. With my code, and with your modified code. Again he came up with a number that already existed in my project and therefore failed to save it and place it in my assembly

@bradeneuropeArthur 

The "file extention" setting was also disabled, but this not solve the problem

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 17 of 42

JhoelForshav
Mentor
Mentor

@johan.degreef 

Sorry! I really messed that one up for some reason! 😄

 

I meant to write it like this!

 

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

MessageBox.Show("Message1", "Title")


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

MessageBox.Show("Message2", "Title")

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
		Dim oFileNameSplit As String() = System.IO.Path.GetFileNameWithoutExtension(oFilename).Split("_")
		If CInt(oFileNameSplit(oFileNameSplit.Length - 1)) > iCounter Then iCounter = CInt(oFileNameSplit(oFileNameSplit.Length - 1)) + 1
	End If
Next




MessageBox.Show("Message3", "Title")

'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)

MessageBox.Show("Message4", "Title")


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

MessageBox.Show("Message5", "Title")

oNewName = ShortName & "_" & iCounter

oPathandName = oActiveAssemblyfolder & oNewName & oExt

MessageBox.Show("Message6", "Title")

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

MessageBox.Show("Message7", "Title")

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

MessageBox.Show("Message8", "Title")

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

MessageBox.Show("Message9", "Title")


'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")
0 Likes
Message 18 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

with this code he makes this out of it: PIPE_200213_850002.ipt

no counter of 3 digits anymore...?

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 19 of 42

JhoelForshav
Mentor
Mentor

@johan.degreef 

This must work?

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

MessageBox.Show("Message1", "Title")


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

MessageBox.Show("Message2", "Title")

Dim iCounter As Integer = 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
		Dim oFileNameSplit As String() = System.IO.Path.GetFileNameWithoutExtension(oFilename).Split("_")
		If CInt(oFileNameSplit(oFileNameSplit.Length - 1)) > iCounter Then iCounter = CInt(oFileNameSplit(oFileNameSplit.Length - 1))
	End If
Next

iCounter += 1


MessageBox.Show("Message3", "Title")

'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)

MessageBox.Show("Message4", "Title")



MessageBox.Show("Message5", "Title")

oNewName = ShortName & "_" & iCounter.ToString("0000")

oPathandName = oActiveAssemblyfolder & oNewName & oExt

MessageBox.Show("Message6", "Title")

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

MessageBox.Show("Message7", "Title")

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

MessageBox.Show("Message8", "Title")

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

MessageBox.Show("Message9", "Title")


'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")

Now I format iCounter to four digits with iCounter.ToString("0000")

0 Likes
Message 20 of 42

johan.degreef
Advisor
Advisor

@JhoelForshav 

No, it makes PIPE_200213_850003.ipt

Maybe we should replace the counter by a random generated code of +-20 digits? no duplicates then....

PIPE_200213_dK5p43Hes35rJ5Sxd63U.ipt

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