- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am trying to use some code that I found to add an occurrence to an assembly. I've placed this code in an iLogic rule. When the code runs I get this error "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
I've verified that the file name and path way is correct so I do not think that is the problem. Below is the code and it fails on the line "Call oOccs.Add(sFilePath, oMatrix)"
Any help would really be appreciated.
Public Sub Place_Part(sFilePath As String)
Dim oApp As Application
oApp = ThisApplication
' if active document isn't an assembly then exit
If Not TypeOf oApp.ActiveDocument Is AssemblyDocument Then Exit Sub
Dim oDoc As AssemblyDocument
oDoc = oApp.ActiveDocument
' define filepath
Dim oOccs As ComponentOccurrences
oOccs = oDoc.ComponentDefinition.Occurrences
' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = oApp.TransientGeometry
' Create a matrix. A new matrix is initialized with an identity matrix.
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix
' check if file already exists in assembly
If CompExist(oDoc, sFilePath) Then
ans = MsgBox("Component already exists within assembly. Place component anyway?", vbYesNo)
If ans = vbYes Then
Call oOccs.Add(sFilePath, oMatrix)
Else
Exit Sub
End If
Else
Trace.WriteLine("iLogic: sFilePath: " & sFilePath)
Call oOccs.Add(sFilePath, oMatrix)
MsgBox ("Hello")
End If
End Sub
Function CompExist(ByRef oAssy As Inventor.AssemblyDocument, sFilePath As String) As Boolean
Dim oOcc As ComponentOccurrence
Dim oCompDef As AssemblyComponentDefinition
oCompDef = oAssy.ComponentDefinition
' Iterate through all of the occurrence in this collection. This
' represents the occurrences at the top level of an assembly.
For Each oOcc In oCompDef.Occurrences
' get filepath of occurrence
sOccFilePath = oOcc.Definition.Document.FullFileName
If sOccFilePath = sFilePath Then
CompExist = True
Exit Function
End If
Next oOcc
End Function
Master Drafter/ CAD Programmer
Using Inventor 2018
Solved! Go to Solution.