How to programmatically constrain two axis?

How to programmatically constrain two axis?

Anonymous
Not applicable
524 Views
2 Replies
Message 1 of 3

How to programmatically constrain two axis?

Anonymous
Not applicable
I would like to constrain the X axis of a part to the X axis of the World.
I would really appreciate a short bit of code on how to do this, (assuming
that it should be short). Thanks!

Ed
0 Likes
525 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Try this:

Public Sub ConstrainAxes()
' Get a reference to the assembly document.
Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

' Place the part into the assembly.
Dim oPartOcc As ComponentOccurrence
Set oPartOcc = oAsmDoc.ComponentDefinition.Occurrences.Add( _
"C:\Temp\Part1.ipt", _
ThisApplication.TransientGeometry.CreateMatrix)

' Get the X-axis work axis in the assembly.
Dim oAsmXAxis As WorkAxis
Set oAsmXAxis = oAsmDoc.ComponentDefinition.WorkAxes.Item(1)

' Get the X-axis work axis from the occurrent.
Dim oPartAxis As WorkAxis
Set oPartAxis = oPartOcc.Definition.WorkAxes.Item(1)

' The part work axis was obtained from the PartComponentDefinition
' associated with the part, so it is in the context of the part.
' We need it in the context of the assembly. This next step
' creates a WorkAxisProxy that represents that work axis in the
' context of the assembly.
Dim oPartAxisInAsm As WorkAxisProxy
Call oPartOcc.CreateGeometryProxy(oPartAxis, oPartAxisInAsm)

' Create a mate constraint between the axes.
Call oAsmDoc.ComponentDefinition.Constraints.AddMateConstraint( _
oAsmXAxis, oPartAxisInAsm, 0)
End Sub

-Brian

"Ed Thompson" wrote in message
news:0A89D27F4862226A274F7303105BB5A4@in.WebX.maYIadrTaRb...
> I would like to constrain the X axis of a part to the X axis of the World.
> I would really appreciate a short bit of code on how to do this, (assuming
> that it should be short). Thanks!
>
> Ed
>
>
0 Likes
Message 3 of 3

Anonymous
Not applicable
Brian,

I need to provide a component from a previously defined selection set. I'm
having trouble substituting my part for how the example defines the part
below. Hopefully, this only needs a couple of lines..

Thanks,

Ed

"Brian Ekins (Autodesk)" wrote in message
news:2C52EDB0E08D2C730936B873216A77FE@in.WebX.maYIadrTaRb...
> Try this:
>
> Public Sub ConstrainAxes()
> ' Get a reference to the assembly document.
> Dim oAsmDoc As AssemblyDocument
> Set oAsmDoc = ThisApplication.ActiveDocument
>
> ' Place the part into the assembly.
> Dim oPartOcc As ComponentOccurrence
> Set oPartOcc = oAsmDoc.ComponentDefinition.Occurrences.Add( _
> "C:\Temp\Part1.ipt", _
> ThisApplication.TransientGeometry.CreateMatrix)
>
> ' Get the X-axis work axis in the assembly.
> Dim oAsmXAxis As WorkAxis
> Set oAsmXAxis = oAsmDoc.ComponentDefinition.WorkAxes.Item(1)
>
> ' Get the X-axis work axis from the occurrent.
> Dim oPartAxis As WorkAxis
> Set oPartAxis = oPartOcc.Definition.WorkAxes.Item(1)
>
> ' The part work axis was obtained from the PartComponentDefinition
> ' associated with the part, so it is in the context of the part.
> ' We need it in the context of the assembly. This next step
> ' creates a WorkAxisProxy that represents that work axis in the
> ' context of the assembly.
> Dim oPartAxisInAsm As WorkAxisProxy
> Call oPartOcc.CreateGeometryProxy(oPartAxis, oPartAxisInAsm)
>
> ' Create a mate constraint between the axes.
> Call oAsmDoc.ComponentDefinition.Constraints.AddMateConstraint( _
> oAsmXAxis, oPartAxisInAsm, 0)
> End Sub
>
> -Brian
>
> "Ed Thompson" wrote in message
> news:0A89D27F4862226A274F7303105BB5A4@in.WebX.maYIadrTaRb...
> > I would like to constrain the X axis of a part to the X axis of the
World.
> > I would really appreciate a short bit of code on how to do this,
(assuming
> > that it should be short). Thanks!
> >
> > Ed
> >
> >
>
>
0 Likes