Pick occurrence to be added instead of Item 2 selection

Pick occurrence to be added instead of Item 2 selection

k14348
Advocate Advocate
426 Views
1 Reply
Message 1 of 2

Pick occurrence to be added instead of Item 2 selection

k14348
Advocate
Advocate

Hi,

    I wanted to add pick occurrence in the assembly instead of item (2) selection. Also only once pick should be done for the whole code instead of 3 pick. Could you help me on this improvement.

 

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

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

Dim oOcc2 As ComponentOccurrence
Set oOcc2 = oAsmCompDef.Occurrences.Item(2)  'pick occurrence to be added instead of Item 2 selection'

' Get the XY plane 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 plane obtained is in the context of the part,
' not the assembly.
Dim oPartPlane1 As WorkPlane
Set oPartPlane1 = oOcc1.Definition.WorkPlanes.Item(3)

Dim oPartPlane2 As WorkPlane
Set oPartPlane2 = oOcc2.Definition.WorkPlanes.Item(3)

' Because we need the work plane in the context of the assembly
' we need to create proxies for the work planes. The proxies
' represent the work planes in the context of the assembly.
Dim oAsmPlane1 As WorkPlaneProxy
Call oOcc1.CreateGeometryProxy(oPartPlane1, oAsmPlane1)

Dim oAsmPlane2 As WorkPlaneProxy
Call oOcc2.CreateGeometryProxy(oPartPlane2, oAsmPlane2)

' Create the constraint using the work plane proxies.
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1, oAsmPlane2, 0)


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

Dim oOcc2A As ComponentOccurrence
Set oOcc2A = oAsmCompDef.Occurrences.Item(2)

' Get the XY plane 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 plane obtained is in the context of the part,
' not the assembly.
Dim oPartPlane1A As WorkPlane
Set oPartPlane1A = oOcc1.Definition.WorkPlanes.Item(2)

Dim oPartPlane2A As WorkPlane
Set oPartPlane2A = oOcc2.Definition.WorkPlanes.Item(2)

' Because we need the work plane in the context of the assembly
' we need to create proxies for the work planes. The proxies
' represent the work planes in the context of the assembly.
Dim oAsmPlane1A As WorkPlaneProxy
Call oOcc1A.CreateGeometryProxy(oPartPlane1A, oAsmPlane1A)

Dim oAsmPlane2A As WorkPlaneProxy
Call oOcc2A.CreateGeometryProxy(oPartPlane2A, oAsmPlane2A)

' Create the constraint using the work plane proxies.
Call oAsmCompDef.Constraints.AddMateConstraint(oAsmPlane1A, oAsmPlane2A, 0)


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

Dim oOcc2B As ComponentOccurrence
Set oOcc2B = oAsmCompDef.Occurrences.Item(2)

' Get the XY plane 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 plane obtained is in the context of the part,
' not the assembly.
Dim oPartPlane1B As WorkPlane
Set oPartPlane1B = oOcc1B.Definition.WorkPlanes.Item(1)

Dim oPartPlane2B As WorkPlane
Set oPartPlane2B = oOcc2B.Definition.WorkPlanes.Item(1)

' Because we need the work plane in the context of the assembly
' we need to create proxies for the work planes. The proxies
' represent the work planes in the context of the assembly.
Dim oAsmPlane1B As WorkPlaneProxy
Call oOcc1B.CreateGeometryProxy(oPartPlane1B, oAsmPlane1B)

Dim oAsmPlane2B As WorkPlaneProxy
Call oOcc2B.CreateGeometryProxy(oPartPlane2B, oAsmPlane2B)

' Create the constraint using the work plane proxies.
Call oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane1B, oAsmPlane2B, 0)


End Sub

 

Thanks,

karthikeyan M

 

0 Likes
Accepted solutions (1)
427 Views
1 Reply
Reply (1)
Message 2 of 2

dean.morrison
Advocate
Advocate
Accepted solution

Hi,

 

I think this will allow you to pick an assembly. Note you may need to change filter if its a part you want to pick.

 

Set oOcc2 = ThisApplication.CommandManager.Pick(kAssemblyOccurrenceFilter, "Select Assembly Occurence")

 

Hope that helps.

 

Dean.