AddMateConstraint

AddMateConstraint

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

AddMateConstraint

Anonymous
Not applicable
I am having problems with applying a mating constraint using VB

For Example,

In Assy A, I have placed two parts, Part A and Part B

In Part b, I have referenced a WorkPoint

In Part c, I have referenced a WorkPoint

How do I use the AddMateConstraint method to apply a point to point mate
between the two points? I can not get it to work.
0 Likes
1,059 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Chris,

You need one additional step in the process. Unfortunately, this isn't
explained in the current documentation. It is demonstrated in the AutoBolts
sample program though. The step missing is the creation of a WorkPointProxy
to use when creating the mate constraint. Although I plan I writing a
detailed description of proxies for the Inventor 6 API documentation, here's
a quick overview.

Proxies are supported for most objects that are accessable within an
assembly. A proxy is an object that represents some other object in the
context of an assembly. In reality, an assembly doesn't contain very much
data. All of the geometry is contained within parts. When a part is placed
into an assembly, the geometry isn't copied into the assembly, but is
referenced from the part. For each part instance in an assembly, the
assembly remembers what file the reference is to and the parts position
within the assembly.

Let's use your case as a specific example. In fact let's simplify it a bit
so we have a single part. In this sample we have Assy A and it contains two
instances of Part A. We want to create a mate constraint between these two
instances using a workpoint within Part A. To obtain the work point you
need to access the contents of the part. You can do this by using the
Definition property of the ComponentOccurrence in the assembly. The
Definition property will return a PartComponentDefinition object, since the
occurrence is referencing a part document. This PartComponentDefinition is
the same PartComponentDefinition object you would get if you opened that
part file directly. You've really jumped from the Assembly into that part.
You have fully access to the part just the same as if you had opened it
directly. Using the functionalty provided by the part you can obtain a
reference to the work point you're interested in.

Now that you have a reference to the work point you want to use it to create
a constraint. If you think about this case you should see we have a
problem. You want to create a mate constraint between two occurrences in an
assembly and you have a reference to the work point you want to use for the
constraint. This sample helps to make the problem obvious because these two
occurrences are referencing the same part. It's the same work point for
both occurrences. You obviously can't constrain a work point to itself.
This is where proxies come into play. When you look at the two occurrences
in the assembly you see two instances of the work point you want to use.
Even though in reality there is just one in the part file. The proxies
represent that work point in the assembly, so there is a unique
WorkPointProxy object for each instance of that part.

To create a proxy you first obtain the object in the context of the part and
then you can create a proxy relative to a specific occurrence in the
assembly. In this example, it's the occurrence that makes each proxy of the
work point unique. The work point proxy can then be used to create the Mate
constraint.

Here's some sample code that demonstrates the above example. To run it have
an assembly open that contains to occurrences of the same part. The part
needs to have a workpoint named "Fred".

Public Sub MateSample()
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Get the first occurrence in the assembly.
Dim oOcc1 As ComponentOccurrence
Set oOcc1 = oAsmCompDef.Occurrences.Item(1)

' Go into the part to get the work point.
Dim oWP As WorkPoint
Set oWP = oOcc1.Definition.WorkPoints.Item("Fred")

' Create a proxy for the work point for the first occurrence
Dim oWP1 As WorkPointProxy
Call oOcc1.CreateGeometryProxy(oWP, oWP1)

' Get the second occurrence in the assembly.
Dim oOcc2 As ComponentOccurrence
Set oOcc2 = oAsmCompDef.Occurrences.Item(2)

' Create a proxy for the work point for the second occurrence.
Dim oWP2 As WorkPointProxy
Call oOcc2.CreateGeometryProxy(oWP, oWP2)

' Create the mate constraint.
Call oAsmCompDef.Constraints.AddMateConstraint(oWP1, oWP2, 0)
End Sub

-Brian

"Chris Ludtke" wrote in message
news:[email protected]...
> I am having problems with applying a mating constraint using VB
>
> For Example,
>
> In Assy A, I have placed two parts, Part A and Part B
>
> In Part b, I have referenced a WorkPoint
>
> In Part c, I have referenced a WorkPoint
>
> How do I use the AddMateConstraint method to apply a point to point mate
> between the two points? I can not get it to work.
>
>
>
>
Message 3 of 4

Anonymous
Not applicable
Brian,
I have just read your reply to Chris and casually I was having the same problem. Now the problem is solved with the AddMateConstraint method, but it seems that the procedure does not work if you want to add an Angle constraint between two workaxes. I have just tried to do it using the CreateProxy method but I receive an error message:
runtime error 5
invalid procedure call or invalid argument.
Do I have to take care of something else when adding an angle constraint?

Leon
0 Likes
Message 4 of 4

Anonymous
Not applicable
There is a known API defect about adding
constraints using work geometry.  The good news is that this problem has
been fixed in 5.3 SP2 which will be available soon.

 

-Brian 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Brian,

I have just read your reply to Chris and casually I was having the same
problem. Now the problem is solved with the AddMateConstraint method, but it
seems that the procedure does not work if you want to add an Angle constraint
between two workaxes. I have just tried to do it using the CreateProxy method
but I receive an error message:
runtime error 5
invalid procedure call
or invalid argument.
Do I have to take care of something else when adding
an angle constraint?

Leon

0 Likes