- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It's not clear what exactly you're workflow is but here are a couple of things that will hopefully help.
When you select something in an assembly you're getting the proxy for that object so the entities you're getting back from the Pick method can immediately be used to create a constraint because they're already a proxy in the context of the top-level assembly.
However, there are cases where you do need to create a proxy. This is when you have a reference to an entity in the context of the part or subassembly but then need a reference with respect to the top-level assembly. For example, in your program it would probably more convenient to ask the user to select the cylinder part and then select the rod part, instead of having to select specific work planes. In this case you have the occurrence but need to go into the part to get the correct plane (this assumes they've been named) and then create proxies of the planes to be able to use them in the context of the assembly. Here's some VBA code that demonstrates the entire process.
Public Sub ConnectParts()
' Select the cylinder and rod occurrences.
Dim cylPart As ComponentOccurrence
Set cylPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select the cylinder part.")
Dim rodPart As ComponentOccurrence
Set rodPart = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select the rod part.")
' Find the origin work plane in the cylinder part.
' This leaves the context of the assembly because the
' component definitition returned is the same as if you
' opened the part by itself.
Dim partDef As PartComponentDefinition
Set partDef = cylPart.Definition
Dim cylinderPlane As WorkPlane
Set cylinderPlane = partDef.WorkPlanes.Item("OriginPlane")
' Find the origin plane in the rod part.
Set partDef = rodPart.Definition
Dim rodPlane As WorkPlane
Set rodPlane = partDef.WorkPlanes.Item("OriginPlane")
' Create proxies for the two work planes.
Dim cylPlaneProxy As WorkPlaneProxy
Call cylPart.CreateGeometryProxy(cylinderPlane, cylPlaneProxy)
Dim rodPlaneProxy As WorkPlaneProxy
Call rodPart.CreateGeometryProxy(rodPlane, rodPlaneProxy)
' Create a mate constraint in the assembly.
Dim asmDef As AssemblyComponentDefinition
Set asmDef = ThisApplication.ActiveDocument.ComponentDefinition
Call asmDef.Constraints.AddMateConstraint(cylPlaneProxy, rodPlaneProxy, 0)
End Sub
