Occurrences.Add does not work?

Occurrences.Add does not work?

Anonymous
Not applicable
695 Views
2 Replies
Message 1 of 3

Occurrences.Add does not work?

Anonymous
Not applicable

Hi all,

 

i am getting this issue when running this code on other people inventor but it works on mine 

 

i was wondering if it is the location of the files with in the C:/ drive so i put the files on a shared drive and it is still the same.

 

it crashes out because it does not place any parts.

 

Background i am passing in Builder_Options As ArrayList and  SystemArea As String

 

 

can anyone help me with this i cant get my head round why it works on my pc but not others ?

 

Kind Regards 

 

 

CODE_____________________

 

'start new inventor assembly

Dim ThisApplication As Inventor.Application
ThisApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
ThisApplication.SilentOperation = True

Dim StartDoc As AssemblyDocument
StartDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kAssemblyDocumentObject)
'StartDoc = ThisApplication.ActiveDocument

 

Dim oAsmCompDef As AssemblyComponentDefinition
'oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
oAsmCompDef = StartDoc.ComponentDefinition

'Create a new matrix object. It will be initialized to an identity matrix.
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
' add all options to assembly
Dim SectionSelection As String
For Each SectionSelection In Builder_Options

oAsmCompDef.Occurrences.Add("C:\VaultWorkspace\Vault\" & SystemArea & "\" & SectionSelection & ".iam", oMatrix)
Next

 

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

JelteDeJong
Mentor
Mentor

hi, i didn't see any direct problems with your code. but i alterd the loop a bit maby it will help you to figure out the problem. i did the following:

  • Combining the strings to a path can be better left to a function that is made for that. When you use IO.Path.Combine() you dont need to wory any more about adding slashes.
  • i added a check to see if the create full file name realy exists.
  • i added a try/catch block. If 1 file fails to add it will show a messagebox but will continue.

 

Dim SectionSelection As String
For Each SectionSelection In Builder_Options
    Dim fullFilename As String = IO.Path.Combine("C:\VaultWorkspace\Vault\", SystemArea, SectionSelection & ".iam")
    If (IO.File.Exists(fullFilename)) Then
        Try
            oAsmCompDef.Occurrences.Add(fullFilename, oMatrix)
        Catch ex As Exception
            MsgBox("Error while placing part: " & fullFilename & " Inventor Error message: " & ex.Message)
        End Try
    Else
        MsgBox("Error while placing part. Following file does not Exists: " & fullFilename)
    End If
Next

 

 

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

Anonymous
Not applicable

Hi,

 

thank you for having a look at my code I have changed it with your bits but it still does not work I now get an error come up.

 

it says it can not find the file ( but I have checked the file is 100% there and it runs fine on my pc)

ERROR:

the parameter is incorrect. (Exception from HTRDULT: 0x80070057 (E_INVALIDARG) 

 

the line if fails on is 

 

oAsmCompDef.Occurrences.Add(fullFilename, oMatrix)

 

I have had a little google with no luck. 

 

any advice or help would be fantastic 

 

Kind Regards 

 

 

0 Likes