@chandra.shekar.g
Sure, sorry I had just pulled up my chair at work. My statement is in regard to code unrelated to what you posted. It is posted below.
What I mean is that the code I have worked when I had only a single axis defined with the statement I wrote in my previous post. Once I created one line, however, the reference to that line remained, affecting what all lines afterwards saw as the reference for the statement (that's what I mean by it didn't unlatch).
Public Sub DrawSketchLine()
' Check to make sure a sketch is active.
If Not TypeOf ThisApplication.ActiveEditObject Is sketch Then
MsgBox "A sketch must be active."
Exit Sub
End If
Set oClass1 = New Class1
oClass1.Initialize
End Sub
Option Explicit
Private WithEvents oInteractionEvents As InteractionEvents
Private WithEvents oMouseEvents As MouseEvents
Private oIntGraphics As InteractionGraphics
Private oStartPoint As Point
Private oEndPoint As Point
Public Sub Initialize()
Set oStartPoint = Nothing
Set oEndPoint = Nothing
Set oInteractionEvents = ThisApplication.CommandManager.CreateInteractionEvents
Set oMouseEvents = oInteractionEvents.MouseEvents
oMouseEvents.MouseMoveEnabled = True
oMouseEvents.PointInferenceEnabled = True
Set oIntGraphics = oInteractionEvents.InteractionGraphics
oInteractionEvents.Start
End Sub
Private Sub oMouseEvents_OnMouseDown(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
If oStartPoint Is Nothing Then
Set oStartPoint = ModelPosition
Else
'\\\\\\ HERE! \\\\\\
If Abs(ModelPosition.X - oStartPoint.X) <= 10 Then
ModelPosition.X = oStartPoint.X
End If
ElseIf Abs(ModelPosition.Y - oStartPoint.Y) <= 10 Then
ModelPosition.Y = oStartPoint.Y
End If
ElseIf Abs(ModelPosition.Z - oStartPoint.Z) <= 10 Then
ModelPosition.Z = oStartPoint.Z
End If
Set oEndPoint = ModelPosition
Dim oSketchLine As SketchLine
Dim oStartPoint2d As Point2d
Dim oEndPoint2d As Point2d
If TypeOf ThisApplication.ActiveEditObject Is PlanarSketch Then
Dim oSketch2d As PlanarSketch
Set oSketch2d = ThisApplication.ActiveEditObject
Set oStartPoint2d = oSketch2d.ModelToSketchSpace(oStartPoint)
Set oEndPoint2d = oSketch2d.ModelToSketchSpace(oEndPoint)
Set oSketchLine = oSketch2d.SketchLines.AddByTwoPoints(oStartPoint2d, oEndPoint2d)
Dim offsetCol As ObjectCollection
Set offsetCol = ThisApplication.TransientObjects.CreateObjectCollection
offsetCol.Add oSketchLine
Call oSketch2d.OffsetSketchEntitiesUsingDistance(offsetCol, 2.54, True, False, True)
Call oSketch2d.OffsetSketchEntitiesUsingDistance(offsetCol, 2.54, False, False, True)
ElseIf TypeOf ThisApplication.ActiveEditObject Is DrawingSketch Then
Dim oDrawingSketch As DrawingSketch
Set oDrawingSketch = ThisApplication.ActiveEditObject
Set oStartPoint2d = oDrawingSketch.SheetToSketchSpace(ThisApplication.TransientGeometry.CreatePoint2d(oStartPoint.X, oStartPoint.Y))
Set oEndPoint2d = oDrawingSketch.SheetToSketchSpace(ThisApplication.TransientGeometry.CreatePoint2d(oEndPoint.X, oEndPoint.Y))
Set oSketchLine = oDrawingSketch.SketchLines.AddByTwoPoints(oStartPoint2d, oEndPoint2d)
End If
Set oStartPoint = Nothing
Set oEndPoint = Nothing
End If
End Sub
Private Sub oMouseEvents_OnMouseMove(ByVal Button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View)
If Not oStartPoint Is Nothing Then
' Set a reference to the transient geometry object for user later.
Dim oTransGeom As TransientGeometry
Set oTransGeom = ThisApplication.TransientGeometry
' Create a graphics data set object. This object contains all of the
' information used to define the graphics.
Dim oDataSets As GraphicsDataSets
Set oDataSets = oIntGraphics.GraphicsDataSets
If oDataSets.Count <> 0 Then
oDataSets.Item(1).Delete
End If
' Create a coordinate set.
Dim oCoordSet As GraphicsCoordinateSet
Set oCoordSet = oDataSets.CreateCoordinateSet(1)
' Create an array that contains coordinates
Dim oPointCoords(5) As Double
oPointCoords(0) = oStartPoint.X
oPointCoords(1) = oStartPoint.Y
oPointCoords(2) = oStartPoint.Z
oPointCoords(3) = ModelPosition.X
oPointCoords(4) = ModelPosition.Y
oPointCoords(5) = ModelPosition.Z
' Assign the points into the coordinate set.
Call oCoordSet.PutCoordinates(oPointCoords)
'Set preview color to red.
Dim oColorSet As GraphicsColorSet
Set oColorSet = oDataSets.CreateColorSet(1)
oColorSet.Add 1, 0, 255, 0
' Create the ClientGraphics object.
Dim oClientGraphics As ClientGraphics
Set oClientGraphics = oIntGraphics.PreviewClientGraphics
If oClientGraphics.Count <> 0 Then
oClientGraphics.Item(1).Delete
End If
' Create a new graphics node within the client graphics objects.
Dim oLineNode As GraphicsNode
Set oLineNode = oClientGraphics.AddNode(1)
' Create a LineGraphics object within the node.
Dim oLineSet As LineStripGraphics
Set oLineSet = oLineNode.AddLineStripGraphics
oLineSet.ColorSet = oColorSet
' Assign the coordinate set to the line graphics.
oLineSet.CoordinateSet = oCoordSet
ThisApplication.ActiveView.Update
End If
End Sub
Private Sub oInteractionEvents_OnTerminate()
ThisApplication.ActiveView.Update
End Sub