Method add of object ComponentOccurrences failed

Method add of object ComponentOccurrences failed

Anonymous
Not applicable
1,267 Views
3 Replies
Message 1 of 4

Method add of object ComponentOccurrences failed

Anonymous
Not applicable

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

 

0 Likes
1,268 Views
3 Replies
Replies (3)
Message 2 of 4

MegaJerk
Collaborator
Collaborator

Can you post a portion of your code that you're having problems with? 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 3 of 4

dano0310
Advocate
Advocate
Hi
I had a quick skim and can't seem to find where "my_path" is defined.
Dan
0 Likes
Message 4 of 4

adam.nagy
Autodesk Support
Autodesk Support

Happy New Year.

 

Is this question still waiting for an answer?

According to its logged date under the title "01-15-2012" it's a year old now  :-s - is that correct?

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes