Class Not Registered Error

Class Not Registered Error

JKunHN5NJ
Explorer Explorer
277 Views
2 Replies
Message 1 of 3

Class Not Registered Error

JKunHN5NJ
Explorer
Explorer

I keep receiving a "Class Not Registered" error every time I try to run this code. I have searched around the forums, but have not been able to find any solutions.

 

' Initialize Inventor application
Dim inventorApp As Inventor.Application
inventorApp = ThisApplication

' Check if an assembly document is active
If inventorApp.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
    MsgBox("Please open an assembly document first.")
    Exit Sub
End If

' Get the active assembly document
Dim originalAssembly As AssemblyDocument
originalAssembly = inventorApp.ActiveDocument

' Prompt the user for a new file name for the copied assembly
Dim newFileName As String
newFileName = InputBox("Enter a new file name for the copied assembly:", "Copy Assembly")

' Check if the user canceled the input
If newFileName = "" Then
    Exit Sub
End If

' List of components to be reused (replace with your own file names)
Dim componentsToReuse As New List(Of String)
componentsToReuse.Add("UHDL13.50CollarPhantom.iam")
componentsToReuse.Add("907926.ipt")

' Save a copy of the assembly with the new file name
originalAssembly.SaveAs(newFileName, True)

' Close the original assembly
originalAssembly.Close(True)

' Open the copied assembly
Dim copiedAssembly As AssemblyDocument
copiedAssembly = inventorApp.Documents.Open(newFileName)

' Iterate through the components in the copied assembly and remove suppressed components
For Each component As ComponentOccurrence In copiedAssembly.ComponentDefinition.Occurrences
    If Component.Suppressed Then
        Component.Delete2(True) ' Delete the suppressed component
    End If
Next

' Iterate through the components in the copied assembly
For Each component As ComponentOccurrence In copiedAssembly.ComponentDefinition.Occurrences
    Dim componentName As String
    componentName = Component.Name

    ' Check if the component should be reused or copied
    If componentsToReuse.Contains(componentName) Then
        ' Component should be reused
        ' You can add code here to update the position or configuration if needed
    Else
        ' Component should be copied
        ' You can add code here to copy the component or replace it with a new version
        ' For example, you can replace it with a different IPT file using the File.Copy function.
    End If
Next

' Inform the user
MsgBox("Assembly copied successfully with a new file name: " & newFileName)

 in line 30 

0 Likes
278 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

I have rewritten the rule a bit and it should work now. At least it works on my system. 

I'm not sure if you noticed but the last part of the script does nothing and could be left out. I left it in because I dont know if you have plans with it.

' Check if an assembly document is active
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
    MsgBox("Please open an assembly document first.")
    Exit Sub
End If

' Get the active assembly document
Dim originalAssembly As AssemblyDocument = ThisDoc.Document

' Prompt the user for a new file name for the copied assembly
Dim oFileDlg As Inventor.FileDialog
Call ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Drawing Files (*.iam)| *.iam"
oFileDlg.FilterIndex = 1
oFileDlg.DialogTitle = "Select drawing template"
'oFileDlg.InitialDirectory = "c:\"
oFileDlg.MultiSelectEnabled = False
oFileDlg.CancelError = False
oFileDlg.ShowSave()
Dim newFileName As String = oFileDlg.FileName

' Check if the user canceled the input
If newFileName = "" Then
    Exit Sub
End If

' Save a copy of the assembly with the new file name
originalAssembly.SaveAs(newFileName, True)

' Close the original assembly
originalAssembly.Close(True)

' Open the copied assembly
Dim copiedAssembly As AssemblyDocument = ThisApplication.Documents.Open(newFileName)

' Iterate through the components in the copied assembly and remove suppressed components
For Each component As ComponentOccurrence In copiedAssembly.ComponentDefinition.Occurrences
    If component.Suppressed Then
        component.Delete2(True) ' Delete the suppressed component
    End If
Next

' Code below this line does nothing!

' List of components to be reused (replace with your own file names)
Dim componentsToReuse As New List(Of String)
componentsToReuse.Add("UHDL13.50CollarPhantom.iam")
componentsToReuse.Add("907926.ipt")
' Iterate through the components in the copied assembly
For Each component As ComponentOccurrence In copiedAssembly.ComponentDefinition.Occurrences
    Dim componentName As String
    componentName = component.Name

    ' Check if the component should be reused or copied
    If componentsToReuse.Contains(componentName) Then
        ' Component should be reused
        ' You can add code here to update the position or configuration if needed
    Else
        ' Component should be copied
        ' You can add code here to copy the component or replace it with a new version
        ' For example, you can replace it with a different IPT file using the File.Copy function.
    End If
Next

' Inform the user
MsgBox("Assembly copied successfully with a new file name: " & newFileName)

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

petr.meduna
Advocate
Advocate

Hi, looks like you used wrong format of filename written into SaveAs function. It must be the full file name, including directory name, file name and extension, not just name of new assembly. I would recommend using Inventor.FileDialog to avoid such mistakes.

Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.CancelError = False
oFileDlg.MultiSelectEnabled = False
oFileDlg.Filter = "IAM file (*.iam)|*.iam"
oFileDlg.DialogTitle = "Save assembly as"
oFileDlg.InitialDirectory = IO.Path.GetDirectoryName(ThisApplication.ActiveDocument.FullFileName)
oFileDlg.ShowSave()
If oFileDlg.FileName <> "" Then
	newFileName = oFileDlg.FileName
Else
	Exit Sub
End If

Dim originalAssembly As AssemblyDocument
originalAssembly = ThisApplication.ActiveDocument
originalAssembly.SaveAs(newFileName, True)
0 Likes