HowTo : Howto get the nearest circle object from a specified point
Article | 41023926 |
Type | HowTo |
Product | Engine |
Version | 5.0.1.1036 |
Date Added | 4/13/2005 |
Submitted by | JongKyun |
Keywords | |
Subject
Howto get the nearest circle object from a specified point
Summary
Howto get the nearest circle object (the circle may be in an insert object) from a specified point.
Solution
Dim ent As vdFigure
Dim pt As Variant
Dim tmpdist As Double
Dim circ As vdCircle
Dim dist As Double
Dim handle As String
Dim EntInBlock As vdFigure
Dim ins As vdInsert
Dim matrix As vdmatrix
Dim circ2 As vdCircle
Dim IdMat As vdmatrix
Dim TransFormMatrix As vdmatrix
vdraw.Redraw
MsgBox "Pick a point to highlight the closest circle"
pt = vdraw.Utility.GetPoint
Set IdMat = vdraw.CreateInstance(OBJ_MATRIX)
dist = 0#
handle = ""
For Each ent In vdraw.ActiveDocument.ActiveLayOut.Entities 'Searching one by one all entities
If ent.Type = "VDINSERT" Then
Set ins = ent
Set matrix = ins.TransFormMatrix
For Each EntInBlock In vdraw.ActiveDocument.Blocks.FindName(ins.BlockName)
If EntInBlock.Type = "VDCIRCLE" Then
Set circ2 = EntInBlock.Copy
circ2.Transformby matrix
tmpdist = Abs(vdraw.Utility.geomDistance(pt, circ2.CenterPoint) - circ2.Radius)
If dist > 0 Then
If tmpdist < dist Then 'If it finds a circle closer to the point, it holds it's handle and it's distance from the point
dist = tmpdist
handle = EntInBlock.handle
Set TransFormMatrix = matrix
End If
Else 'If it is the first time that finds a circle then it holds it's handle and it's distance from the point
dist = tmpdist
handle = EntInBlock.handle
Set TransFormMatrix = matrix
End If
End If
Next
End If
If ent.Type = "VDCIRCLE" Then
Set circ = ent
tmpdist = Abs(vdraw.Utility.geomDistance(pt, circ.CenterPoint) - circ.Radius)
If dist > 0 Then
If tmpdist < dist Then 'If it finds a circle closer to the point, it holds it's handle and it's distance from the point
dist = tmpdist
handle = circ.handle
Set TransFormMatrix = IdMat
End If
Else 'If it is the first time that finds a circle then it holds it's handle and it's distance from the point
dist = tmpdist
handle = circ.handle
Set TransFormMatrix = IdMat
End If
End If
Next
Set ent = vdraw.ActiveDocument.GetFromHandle(handle)
If ent Is Nothing Then Exit Sub
If ent.Type <> "VDCIRCLE" Then Exit Sub
Set circ = ent.Copy
circ.Transformby TransFormMatrix
circ.HighLight = VdHightLightDot 'Highlight the closest circle
vdraw.DrawEntity circ, 0