Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create some delete some

1 REPLY 1
Reply
Message 1 of 2
Anonymous
398 Views, 1 Reply

Create some delete some

In need of some programming help...

So I have this code:

 

Sub Main()

    Dim oAsmCompDef As AssemblyComponentDefinition
    oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition


    ' Get references to the two occurrences to constrain.
    ' This arbitrarily gets the first and second occurrence.
    Dim oOcc1 As ComponentOccurrence
    oOcc1 = oAsmCompDef.Occurrences.Item(Cars)

    Dim oOcc2 As ComponentOccurrence
    oOcc2 = oAsmCompDef.Occurrences.Item(Bumper)


    ' Get the work points from each occurrence.  This goes to the
    ' component definition of the part to get this information.
    ' This is the same as accessing the part document directly.
    ' The work point obtained is in the context of the part,
    ' not the assembly.
    Dim oPartPoint1 As WorkPoint
     oPartPoint1 = oOcc1.Definition.WorkPoints.Item(1)

    Dim oPartPoint2 As WorkPoint
    oPartPoint2 = oOcc2.Definition.WorkPoints.Item(1)

    Dim oPartPlaneXY As WorkPlane
    oPartPlaneXY = oOcc1.Definition.WorkPlanes(3)
    
    Dim oPart2PlaneXY As WorkPlane
    oPart2PlaneXY = oOcc2.Definition.WorkPlanes(3)

    
    ' Because we need the work point in the context of the assembly
    ' we need to create proxies for the work points.  The proxies
    ' represent the work points in the context of the assembly.
    Dim oAsmPoint1 As WorkPointProxy
    Call oOcc1.CreateGeometryProxy(oPartPoint1, oAsmPoint1)

    Dim oAsmPoint2 As WorkPointProxy
    Call oOcc2.CreateGeometryProxy(oPartPoint2, oAsmPoint2)
    
    Dim oPartPlane1 As WorkPlaneProxy 
    Call oOcc1.CreateGeometryProxy(oPartPlaneXY, oPartPlane1)
    
    Dim oPart2Plane1 As WorkPlaneProxy
    Call oOcc2.CreateGeometryProxy(oPart2PlaneXY, oPart2Plane1)

    
    ' Create the constraint using the work point proxies.
    Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPoint1, oAsmPoint2, 0)
    Call oAsmCompDef.Constraints.AddMateConstraint(oPartPlane1, oPart2Plane1, 0)
 
End Sub

 

There is an excel sheet thats linked to inventor and inventor pulls values from this sheet and uses them as parameters. This code was created in iLogic which uses some of these parameters. The parameters 'Cars' and 'Bumper' give the occurance of the two components that I want to mate. As you can see from the code, it's choosing two components, a workplane and workpoint from each component and create a mate constraint. My problem now is deleting the constraints that were created. I am running this program over and over and it creates more constraints but what I am aiming for is the bumper to follow the end of the car wherever it happens to be in inventor.

1 REPLY 1
Message 2 of 2
Curtis_Waguespack
in reply to: Anonymous

Hi dtowngurl51,

Here is a modification of the code you provided. This example simply names the new constraints as they are created, then you could use the code at this link to delete the constraints by name.

 

 

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
    
    ' Get references to the two occurrences to constrain.
    ' This arbitrarily gets the first and second occurrence.
Dim oOcc1 As ComponentOccurrence
oOcc1 = oAsmCompDef.Occurrences.Item(1)
Dim oOcc2 As ComponentOccurrence
oOcc2 = oAsmCompDef.Occurrences.Item(2)

    ' Get the work points from each occurrence.  This goes to the
    ' component definition of the part to get this information.
    ' This is the same as accessing the part document directly.
    ' The work point obtained is in the context of the part,
    ' not the assembly.
Dim oPartPoint1 As WorkPoint
oPartPoint1 = oOcc1.Definition.WorkPoints.Item(1)

Dim oPartPoint2 As WorkPoint
oPartPoint2 = oOcc2.Definition.WorkPoints.Item(1)

Dim oPartPlaneXY As WorkPlane
oPartPlaneXY = oOcc1.Definition.WorkPlanes(3)
    
Dim oPart2PlaneXY As WorkPlane
oPart2PlaneXY = oOcc2.Definition.WorkPlanes(3)
    
    ' Because we need the work point in the context of the assembly
    ' we need to create proxies for the work points.  The proxies
    ' represent the work points in the context of the assembly.
Dim oAsmPoint1 As WorkPointProxy
Call oOcc1.CreateGeometryProxy(oPartPoint1, oAsmPoint1)

Dim oAsmPoint2 As WorkPointProxy
Call oOcc2.CreateGeometryProxy(oPartPoint2, oAsmPoint2)
    
Dim oPartPlane1 As WorkPlaneProxy 
Call oOcc1.CreateGeometryProxy(oPartPlaneXY, oPartPlane1)
    
Dim oPart2Plane1 As WorkPlaneProxy
Call oOcc2.CreateGeometryProxy(oPart2PlaneXY, oPart2Plane1)
    
'Create the constraint using the work point proxies.
Dim oConstraint As MateConstraint
oConstraint  = oAsmCompDef.Constraints.AddMateConstraint(oAsmPoint1, oAsmPoint2, 0.5)
'name the constraint
oConstraint.Name = "MyConstraint1"
oConstraint  = oAsmCompDef.Constraints.AddMateConstraint(oPartPlane1, oPart2Plane1, 0.5)
'name the constraint
oConstraint.Name = "MyConstraint2"
    

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report