create an imate based on a work point in the first sub assembly

create an imate based on a work point in the first sub assembly

Anonymous
Not applicable
428 Views
3 Replies
Message 1 of 4

create an imate based on a work point in the first sub assembly

Anonymous
Not applicable

Hi all,

 

i was wondering if someone would be able to help me, i am after a little bit of code to get the work points from the first sub-assembly and if a work point is called = "something" then in the top level add a mate iMate called "something" at that work point.

 

i have had a look around and found a few bits of code but i have not been able to figure this out.

 

Thanks in advance for any help 

Chris 

0 Likes
Accepted solutions (1)
429 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

this is what i have at the moment so.

 

i can get the work point i want in the sub-assembly (WP) and i can get its x,y,z points (WP.Point)

 

but i cant work out how to make an iMate in the top assembly on that WorkPoint? 

 

can anyone help ? 

 

 

 

Public Sub getpoint()
        'Define the Document
        Dim ThisApplication As Inventor.Application
        ThisApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Dim oDoc As AssemblyDocument
        oDoc = ThisApplication.ActiveDocument
        Dim tankAsmComp As AssemblyComponentDefinition
        tankAsmComp = oDoc.ComponentDefinition

        ' Get the referenced assembly.
        ' Dim tankAsm As AssemblyDocument = drawView.ReferencedDocumentDescriptor.ReferencedDocument
        'Dim tankAsmComp As AssemblyComponentDefinition = tankAsm.ComponentDefinition

        ' Get the occurrence of the tank in the assembly.
        Dim tankOcc As ComponentOccurrence = tankAsmComp.Occurrences.Item(1)

        ' Get the tank part.
        Dim tankPartComp As AssemblyComponentDefinition = tankOcc.Definition

        ' Get the work point named "TANKWP".
        Dim WP As WorkPoint
        For Each WP In tankPartComp.WorkPoints

            If WP.Name = "Center Point" Then
                'WP.Point

                Dim oMateiMateDefinition As MateiMateDefinition
                oMateiMateDefinition = tankAsmComp.iMateDefinitions.AddMateiMateDefinition(tankOcc, 0, InferredTypeEnum.kInferredPoint, WP.Point, "test")
                'oMateiMateDefinition = tankAsmComp.iMateDefinitions.AddMateiMateDefinition(WP, 0, InferredTypeEnum.kInferredPoint, WP.Point, "test")
            End If
        Next
    End Sub
0 Likes
Message 3 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

You need to create a WorkPointProxy and use that to create the iMate. Some thing like this.

'Define the Document
Dim ThisApplication As Inventor.Application
ThisApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim tankAsmComp As AssemblyComponentDefinition
tankAsmComp = oDoc.ComponentDefinition

' Get the referenced assembly.
' Dim tankAsm As AssemblyDocument = drawView.ReferencedDocumentDescriptor.ReferencedDocument
'Dim tankAsmComp As AssemblyComponentDefinition = tankAsm.ComponentDefinition

' Get the occurrence of the tank in the assembly.
Dim tankOcc As ComponentOccurrence = tankAsmComp.Occurrences.Item(1)

' Get the tank part.
Dim tankPartComp As AssemblyComponentDefinition = tankOcc.Definition

' Get the work point named "TANKWP".
Dim centerPoint As WorkPoint = Nothing
For Each WP As WorkPoint In tankPartComp.WorkPoints

    If WP.Name = "Center Point" Then
        centerPoint = WP
    End If
Next

' create WorkPointProxy 
Dim centerPointProxy As Inventor.WorkPointProxy = Nothing
tankOcc.CreateGeometryProxy(centerPoint, centerPointProxy)

' create iMate with the WorkPointProxy
Dim oMateiMateDefinition As MateiMateDefinition
oMateiMateDefinition = tankAsmComp.iMateDefinitions.AddMateiMateDefinition(centerPointProxy, 0, InferredTypeEnum.kInferredPoint, , "test")

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 4 of 4

Anonymous
Not applicable

hi JelteDeJong  

 

thank you, I have just been working it and have come to the same method of working.

 

I have marked your solution as accepted because it is a lot neater than what I have.

 

thank you for your help.

 

Kind Regards 

0 Likes