See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: TEST FOR HORIZONTAL OR VERTICAL LINE

  1. #1
    Member
    Join Date
    2018-08
    Posts
    11
    Login to Give a bone
    0

    Default TEST FOR HORIZONTAL OR VERTICAL LINE

    Hello,

    I have the following code to see if a selected line is horizontal or vertical but some lines that have the same StartY and EndY are still returning as angled. What am I missing? I even went so far as to restrain the line horizontal.

    Code:
    Public Shared Function HorizontalVerticle(Line As Line) As Tuple(Of String, Double, Double, Double, Double) 'Determin if line is horizontal or verticle
            If Line.StartPoint.Y = Line.EndPoint.Y And Line.StartPoint.X <> Line.EndPoint.X Then
                'MsgBox("Horizontal, " & Line.StartPoint.Y & vbCrLf & "Horizontal, " & Line.EndPoint.Y,, "HorizontalVerticle Function")
                Dim y = New Tuple(Of String, Double, Double, Double, Double)("Horizontal", Line.StartPoint.Y, Line.StartPoint.X, Line.EndPoint.Y, Line.EndPoint.X)
                Return y
            ElseIf Line.StartPoint.X = Line.EndPoint.X And Line.StartPoint.Y <> Line.EndPoint.Y Then
                'MsgBox("Verticle, " & Line.StartPoint.Y & vbCrLf & "Verticle, " & Line.EndPoint.Y,, "HorizontalVerticle Function")
                Dim y = New Tuple(Of String, Double, Double, Double, Double)("Verticle", Line.StartPoint.Y, Line.StartPoint.X, Line.EndPoint.Y, Line.EndPoint.X)
                Return y
            ElseIf Line.StartPoint.X <> Line.EndPoint.X And Line.StartPoint.Y <> Line.EndPoint.Y Then
                'MsgBox("Line is neither horizontal or verticle, " & Line.StartPoint.Y & vbCrLf & "Verticle, " & Line.EndPoint.Y,, "HorizontalVerticle Function")
                Dim y = New Tuple(Of String, Double, Double, Double, Double)("Angled", Line.StartPoint.Y, Line.StartPoint.X, Line.EndPoint.Y, Line.EndPoint.X)
                Return y
            End If
        End Function

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    0

    Default Re: TEST FOR HORIZONTAL OR VERTICAL LINE

    Did you use ORTHO when creating the line. It could look horizontal but have small variations in Y. You might not see it if you have your unit resolution set low. You could use the line's angle an specify a fuzz factor by comparing if its between two values.

    Also, in your function, you declared a variable Line As type Line. Its bad practice to name variables using language keywords. My naming convention is to use a 3-letter prefix with a meaningful name. e.g. linTest, strMessage.

    Also, the calling function passes in a Line object, so it already knows the start point and end point. Why return those same values?
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2018-08
    Posts
    11
    Login to Give a bone
    0

    Default Re: TEST FOR HORIZONTAL OR VERTICAL LINE

    I did use ortho mode and constrained the line to be horizontal.

  4. #4
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    Login to Give a bone
    1

    Default Re: TEST FOR HORIZONTAL OR VERTICAL LINE

    Here's my version. I tested it in a 2D dwg done in WCS.

    Code:
    Public Function PI() As Double
      PI = Atn(1) * 4
    End Function
    
    Public Sub CheckLines()
        
        Dim oEnt As AcadEntity
        Dim vPoint As Variant
        Dim HV As Boolean
        
    GetLine:
        ThisDrawing.Utility.getEntity oEnt, vPoint, "Select a Line. "
        If TypeOf oEnt Is AcadLine Then
            'check for horiz or vert
            HV = CkHoriz(oEnt)
            If HV = True Then
              ThisDrawing.Utility.Prompt "Selected line is Horizontal. "
            ElseIf HV = False Then
               HV = CkVert(oEnt)
               If HV = True Then
                 ThisDrawing.Utility.Prompt "Selected line is Vertical. "
               Else
                 ThisDrawing.Utility.Prompt "Selected line is not Horizontal or Vertical. "
               End If
            End If
            
        Else
            ThisDrawing.Utility.Prompt "You didn't select a Line. "
            GoTo GetLine
        End If
    End Sub
    
    Public Function CkHoriz(linTest As AcadLine) As Boolean
        CkHoriz = False
        If linTest.Angle = 0 Or linTest.Angle = PI() Then
            CkHoriz = True
        End If
    End Function
    
    Public Function CkVert(linTest As AcadLine) As Boolean
        CkVert = False
        If linTest.Angle = 0.5 * PI() Or linTest.Angle = 1.5 * PI() Then
            CkVert = True
        End If
    End Function
    C:> ED WORKING....

Similar Threads

  1. Replies: 9
    Last Post: 2006-04-14, 07:19 PM
  2. Detect lines that are not absolute horizontal or vertical
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 6
    Last Post: 2005-10-21, 12:15 PM
  3. Vertical Line on Horizontal Lap Siding
    By Rhythmick in forum Revit - Rendering
    Replies: 9
    Last Post: 2005-03-15, 04:51 AM
  4. horizontal sweeps and vertical parameters
    By woethesinner in forum Revit Architecture - Families
    Replies: 0
    Last Post: 2004-09-27, 07:52 PM
  5. Mask difference on vertical plane vs. horizontal plane.
    By SkiSouth in forum Revit - Rendering
    Replies: 0
    Last Post: 2004-04-24, 01:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •