Change Mate Offset through API - How?

Change Mate Offset through API - How?

Anonymous
Not applicable
670 Views
1 Reply
Message 1 of 2

Change Mate Offset through API - How?

Anonymous
Not applicable
How does one change the offset value of a named mate constraint through the
API. Seems like there should be a Value property for the MateConstraint.
The only way I could figure out how to do it was to delete the existing
contraint and add a new one. Couldn't get that to work either.

Here's my code. Any ideas? Isn't there an easier way?

This code errors out at the line "Set oMate = ..." with a run-time error
445, "Object doesn't support this action."

Thanks,

--Randy

===========================================
Public Sub SetInsideFrameWidth(Width As Double)

Dim oInventor As Inventor.Application
Set oInventor = GetObject(, "Inventor.Application")

Dim oDoc As AssemblyDocument
Set oDoc = oInventor.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = oDoc.ComponentDefinition

Dim oAssyConstraints As AssemblyConstraints
Dim oAssyConstraint As AssemblyConstraint
Dim oGeom1 As Object
Dim oGeom2 As Object


Set oAssyConstraints = oDoc.ComponentDefinition.Constraints

For Each oAssyConstraint In oAssyConstraints
Debug.Print oAssyConstraint.Name
If oAssyConstraint.Name = "InsideFrameWidth" Then
Set oGeom1 = oAssyConstraint.GeometryOne
Set oGeom2 = oAssyConstraint.GeometryTwo
oAssyConstraint.Delete
Dim oMate As MateConstraint
Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oGeom1,
oGeom2, CStr(Width) & " in")
oMate.Name = "InsideFrameWidth"
Exit Sub
End If
Next
End Sub
0 Likes
671 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
To change the mate offset you're actually editing the parameter associated
with the mate. The MateConstraint object's Offset property returns the
associated parameter. The code below illustrates this.

Dim oMate As MateConstraint
' Get a reference to an existing mate.

' Edit the parameter associated with the mate.
oMate.Offset.Value = 4.5

' You could also do this.
Dim oParam As Parameter
Set oParam = oMate.Offset
oParam.Value = 3.5

Remember that after editing the parameter you need to use the
AssemblyDocument.Update method to update the assembly to reflect the change.

-Brian

"Randall A. Maxey" wrote in message
news:[email protected]...
> How does one change the offset value of a named mate constraint through
the
> API. Seems like there should be a Value property for the MateConstraint.
> The only way I could figure out how to do it was to delete the existing
> contraint and add a new one. Couldn't get that to work either.
>
> Here's my code. Any ideas? Isn't there an easier way?
>
> This code errors out at the line "Set oMate = ..." with a run-time error
> 445, "Object doesn't support this action."
>
> Thanks,
>
> --Randy
>
> ===========================================
> Public Sub SetInsideFrameWidth(Width As Double)
>
> Dim oInventor As Inventor.Application
> Set oInventor = GetObject(, "Inventor.Application")
>
> Dim oDoc As AssemblyDocument
> Set oDoc = oInventor.ActiveDocument
>
> Dim oAsmCompDef As AssemblyComponentDefinition
> Set oAsmCompDef = oDoc.ComponentDefinition
>
> Dim oAssyConstraints As AssemblyConstraints
> Dim oAssyConstraint As AssemblyConstraint
> Dim oGeom1 As Object
> Dim oGeom2 As Object
>
>
> Set oAssyConstraints = oDoc.ComponentDefinition.Constraints
>
> For Each oAssyConstraint In oAssyConstraints
> Debug.Print oAssyConstraint.Name
> If oAssyConstraint.Name = "InsideFrameWidth" Then
> Set oGeom1 = oAssyConstraint.GeometryOne
> Set oGeom2 = oAssyConstraint.GeometryTwo
> oAssyConstraint.Delete
> Dim oMate As MateConstraint
> Set oMate = oAsmCompDef.Constraints.AddMateConstraint(oGeom1,
> oGeom2, CStr(Width) & " in")
> oMate.Name = "InsideFrameWidth"
> Exit Sub
> End If
> Next
> End Sub
>
>
>