Message 1 of 4
Method add of object ComponentOccurrences failed
Not applicable
01-14-2012
04:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Everyone,
I have an excell spreadshhet and a modified copy of the add occurence sample from the help file. I tried to test the code by changing the parameters in the excell spreadsheet and the code runs OK first (maybe second time), but fails afterwards with the following error -2147467259 (80004005): Method add of object ComponentOccurrences failed.
Can anybody tell me what it is wrong with it? Thanks.:
Public Sub AddFixedIdler()
Dim oOcc As ComponentOccurrence
Dim myobject As Inventor.AssemblyDocument
Dim FileName As String
Dim Directory As String
'Set a reference to the existing open document
Set myobject = ThisApplication.ActiveDocument
'update and save the assembly
'suppress apllication notifications
ThisApplication.SilentOperation = True
myobject.Update
myobject.Save
'unsuppress apllication notifications
ThisApplication.SilentOperation = False
File_Name = myobject.FullFileName
Directory = Left(File_Name, InStrRev(File_Name, "\") - 1)
' Set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
' Obtain the Parameters collection
Dim oParams As Parameters
Set oParams = myobject.ComponentDefinition.Parameters
INo = oParams.Item("INo").Value
FINo = oParams.Item("FINo").Value
Idis = oParams.Item("IS").Value
ImRTtSdis = oParams.Item("ImRTtSdis").Value
Shim = oParams.Item("Shim").Value
FIdlerType = oParams.Item("FIdlerType").Value
'select idler (Ind STD or CST STD)
Dim Idler As String
If FIdlerType = 0 Then
Idler = Directory + "\30006.iam"
Else
Idler = Directory + "\30027.iam"
End If
'Delete existing fix idlers
For Each oOcc1 In myobject.ComponentDefinition.Occurrences
If (InStr(oOcc1.Name, "30006") <> 0) Or (InStr(oOcc1.Name, "30027") <> 0) Then
oOcc1.Delete
End If
Next
' Set a reference to the transient geometry object.
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
' Create a matrix. A new matrix is initialized with an identity matrix.
Dim oMatrix As Matrix
Set oMatrix = oTG.CreateMatrix
' Set the rotation of the matrix for a 90 degree rotation about the Y axis.
Call oMatrix.SetToRotation(3.14159265358979 / 2, _
oTG.CreateVector(0, 1, 0), oTG.CreatePoint(0, 0, 0))
' Set the translation portion of the matrix so the part will be repositioned
Dim yLocation As Single
yLocation = ImRTtSdis + Shim
Dim xLocation As Single
For i = 0 To INo - 1
xLocation = (2 * i - INo + 1) * Idis / 2
Call oMatrix.SetTranslation(oTG.CreateVector(xLocation, yLocation, 0))
' Add the occurrence.
Set oOcc = oAsmCompDef.Occurrences.Add(Idler, oMatrix)
'set occurence LOD to Custom
oOcc.SetLevelOfDetailRepresentation ("Custom")
Next i
'update and save the assembly
'suppress apllication notifications
ThisApplication.SilentOperation = True
myobject.Update
myobject.Save
'unsuppress apllication notifications
ThisApplication.SilentOperation = False
End Sub

