- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Error in iLogic
All of the sudden this iLogic code gives an error. What i did: I did install Vsual studio to try to learn to code, and therefore I needed to install .net framework 4.8. That is what I have changed. I work on Inventor 2021. I guess it is since then then error pops up.
Imports System.IO
GetInput :
Dim Filename As String = "C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx"
Dim ExcelApp As Object
Dim opened As Boolean
Dim wb As Object
Dim Six_Digit As String
ExcelApp = GetObject(, "Excel.Application")
opened = False
For Each wb In ExcelApp.workbooks
If UCase(wb.fullname) = UCase(Filename) Then
opened = True
Exit For
End If
Next
If Not opened Then
GoExcel.Open("C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx")
'GoExcel.Open("C:\Users\ef\Desktop\New_PTN_Part_Library.xlsx")
End If
Six_Digit = ExcelApp.ActiveCell.Value
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:\Autodesk en Templates\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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try to uninstall 4.8! Think that you don't need that for testing your code!
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I think i deleted all 4.8 stuff, but still not working. Now there is 5.0 too and some ASP.NET stuff.
Can that be safely deleted too?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Create a restore point first.
Normally you can uninstall that without issues.
If not restore your machine to the restore point.
Regards
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
The GetObject method gives correct an error if Excel is simply not running and the PathName argument is omitted. Simply add an empty string and GetObject creates a new Excel.Application instance.
ExcelApp = GetObject("", "Excel.Application")
This way is not possible if you want to use a running instance. You can use a try-catch statement
Try
ExcelApp = GetObject(, "Excel.Application")
For Each wb In ExcelApp.workbooks
If UCase(wb.fullname) = UCase(Filename) Then
Exit For
End If
Next
Catch
GoExcel.Open("C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx")
'GoExcel.Open("C:\Users\ef\Desktop\New_PTN_Part_Library.xlsx")
End Try
or an On Error Resume next.
On Error Resume Next
ExcelApp = GetObject(, "Excel.Application")
opened = False
For Each wb In ExcelApp.workbooks
If UCase(wb.fullname) = UCase(Filename) Then
opened = True
Exit For
End If
Next
If Not opened Then
GoExcel.Open("C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx")
'GoExcel.Open("C:\Users\ef\Desktop\New_PTN_Part_Library.xlsx")
End If
On Error GoTo 0
R. Krieg
RKW Solutions
www.rkw-solutions.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thx, but I tried both option, giving other errors.
This code was working fine.
There is always an instance open of excel (the sheet where I pick my number)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i have reinstalled excel, reinstalled inventor 2021. Nothing seems to bring this helpfull tool back to life. Don't know where to look further...
On my collegues PC it runs without any issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Do you have show fileextensions on?
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@bradeneuropeArthur wrote:Do you have show fileextensions on?
@bradeneuropeArthur wrote:Do you have show fileextensions on?
no
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It must have something to do with user rights, because if I run inventor as adminsitrator, it works. But I cannot do that all the time, because of access rights to sharded network drives.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Try it with fileextensions on!
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Can you share the complete code.
Including the add references!
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Changed:
Imports System.IO
GetInput :
Dim Filename As String = "C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx"
Dim ExcelApp As Object
Dim opened As Boolean
Dim wb As Object
Dim Six_Digit As String
ExcelApp = GetObject("", "Excel.Application")
opened = False
For Each wb In ExcelApp.workbooks
If UCase(wb.fullname) = UCase(Filename) Then
opened = True
Exit For
End If
Next
If Not opened Then
GoExcel.Open("C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx")
'GoExcel.Open("C:\Users\ef\Desktop\New_PTN_Part_Library.xlsx")
End If
Six_Digit = ExcelApp.ActiveCell.Value
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:\Autodesk en Templates\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
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Did that help?
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@bradeneuropeArthur wrote:
Did that help?
No
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Test dit eens:
Welke messages krijg je:
Imports System.IO
GetInput :
Dim Filename As String = "C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx"
Dim ExcelApp As Object
Dim opened As Boolean
Dim wb As Object
Dim Six_Digit As String
Msgbox ("A")
ExcelApp = GetObject("", "Excel.Application")
opened = False
Msgbox ("B")
For Each wb In ExcelApp.workbooks
If UCase(wb.fullname) = UCase(Filename) Then
opened = True
Msgbox ("C")
Exit For
End If
Next
If Not opened Then
GoExcel.Open("C:\Autodesk en Templates\PTN_Part_Library\New_PTN_Part_Library.xlsx")
'GoExcel.Open("C:\Users\ef\Desktop\New_PTN_Part_Library.xlsx")
Msgbox ("D")
Six_Digit = ExcelApp.ActiveCell.Value
Msgbox ("Excel six Digit " & Six_Digit)
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:\Autodesk en Templates\PTN_Part_Library\"
Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories)
Msgbox ("E ")
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 & "\"
Msgbox ("F ")
'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)
Msgbox ("G ")
Dim oNewName As String = ShortName & "_" & System.DateTime.Now.ToString("yyyyMdHHmmss")
Dim oPathandName As String = oActiveAssemblyfolder & oNewName & oExt
Msgbox ("H ")
oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = ShortName
'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close
Msgbox ("I")
'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Msgbox ("J ")
' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)
Msgbox ("K ")
'insert new occurence
'Dim oOcc As ComponentOccurrence
'oOcc = oAsmCompDef.Occurrences.Add( _
'oPathandName, oMatrix)
Msgbox ("L ")
ThisApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, oPathandName)
ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyPlaceComponentCmd").Execute
Msgbox ("M ")
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
"A", and then it crashes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
first start excel.
than run the code.
What messages do you get now?
Regards,
Arthur Knoors
Autodesk Affiliations:
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: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 !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@bradeneuropeArthur @Ralf_Krieg I always start excel first. The intention of the ilogic code is to select an excel cell with a 6 digit number in, so the result is an "A"
I don't think the problem lies in the code. It has to do with user rights or installation of excel/inventor. But I can't find what.