Option Explicit
Private WithEvents oInteraction As InteractionEvents
Private WithEvents omouseEvent As MouseEvents
Private oTransform As Matrix
Private oAsmCompDef As AssemblyComponentDefinition
Private CompOccur As ComponentOccurrence
Private partPatch As String
Private Sub Class_Initialize()
partPatch = "D:\Part1.ipt"
Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Set oTransform = ThisApplication.TransientGeometry.CreateMatrix
Set CompOccur = oAsmCompDef.Occurrences.Add(partPatch, oTransform)
Set oInteraction = ThisApplication.CommandManager.CreateInteractionEvents
Set omouseEvent = oInteraction.MouseEvents
omouseEvent.MouseMoveEnabled = True
oInteraction.Start
End Sub
Private Sub Class_Terminate()
On Error Resume Next
If Not oInteraction Is Nothing Then
oInteraction.Stop
omouseEvent = Nothing
CompOccur = Nothing
myFlag = False
End If
End Sub
Private Sub omouseEvent_OnMouseClick(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, _
ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
If Not oInteraction Is Nothing Then
oInteraction.Stop
Set omouseEvent = Nothing
Set oInteraction = Nothing
Call oTransform.SetTranslation(ThisApplication.TransientGeometry.CreateVector(ModelPosition.x, _
ModelPosition.y, ModelPosition.Z))
Dim i As Integer
For i = 0 To 5
Set CompOccur = oAsmCompDef.Occurrences.Add(partPatch, oTransform)
Next
Set CompOccur = Nothing
myFlag = False
End If
End Sub
Private Sub omouseEvent_OnMouseMove(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, _
ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
Call oTransform.SetTranslation(ThisApplication.TransientGeometry.CreateVector(ModelPosition.x, _
ModelPosition.y, ModelPosition.Z))
CompOccur.Transformation = oTransform
View.Update
End Sub