Results 1 to 7 of 7

Thread: Need simple cad program

Threaded View

  1. #7
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Need simple cad program

    Hon

    Sorry to hear about your deadline.

    Here is a mock-up of what I had in mind (see image below)
    It involves 2 things
    • a text file named Rooms.txt, and which contains room "dimensions"
    • a form with a CommandButton named cbRooms and a PictureBox named PB1

    Here is what the text file looks like
    Code:
    1,Room,1,0,0,12,8,-3,2,-9,-10
    2,Room,2,0,10,9,2,3,8,-12,-10
    3,Room,3,12,0,20,12,-10,8,-10,-8,-3,-4,3,-8
    4,Room,4,22,12,10,8,-10,-8
    5,HVAC,1,27,3,3,3,-3,-3
    The "fields" (comma separated) are as follows (origin shown in red for clarity)
    • 1 id number
    • 2 room type
    • 3 room number
    • 4 origin-x
    • 5 origin-y
    • 6+ dimension

    .. where origin is always the upper-left corner of the room, and

    .. where dimension is a length. You begin at the room's origin,
    and go clockwise around the room's perimeter, giving each dimension
    to get you back to the origin.
    • right and down are positive
    • left and up are negative


    Here is the code:

    Code:
    ' 1. form load
    Private Sub Form_Load()
        With Me
            .Top = 2000
            .Left = 1000
            .Height = 6000
            .Width = 7000
        End With
    End Sub
    ' 2. button that starts the app
    Private Sub cbRooms_Click()
        With cbRooms
            .Top = 300
            .Left = 300
        End With
        With PB1
            .Cls
            .Top = 800
            .Left = 500
            .Height = 4000
            .Width = 5000
            .Visible = True
            .AutoRedraw = True
        End With
        Dim aRMS(5, 15)    ' main array, fixed dimensions for simplicity
        ' read rooms file
        fn = "c:\VBForum Stuff\Rooms.txt"
        Open fn For Input As #1
        For ii = 1 To 5
            Line Input #1, xtr
            v1 = Split(xtr, ",")
            For jj = 1 To UBound(v1)
                aRMS(ii, jj - 1) = v1(jj)
            Next jj
            If EOF(1) Then
                Exit For
            End If
        Next ii
        Close #1
        ' plot rooms
        For ii = 1 To 5
            rtype = aRMS(ii, 0)
            rnum = aRMS(ii, 1)
            ' set line color
            If rtype = Empty Then
                Exit For
            ElseIf rtype = "Room" Then
                cc = vbBlack
            ElseIf rtype = "HVAC" Then
                cc = vbRed
            End If
            oo = 1000
            fac = 100
            ox = Val(aRMS(ii, 2)) * fac + oo
            oy = Val(aRMS(ii, 3)) * fac + oo
            For jj = 2 To 15
                ' id the origin
                If jj = 2 Then
                    ZDOT ox, oy, 6, cc
                    PB1.CurrentX = ox - 200
                    PB1.CurrentY = oy - 200
                    PB1.Print Trim(ii)
                End If
                ' plot a wall
                nxt = Val(aRMS(ii, jj + 2))
                resu = jj Mod 2
                If resu = 0 Then        ' left/right
                    xx1 = ox
                    xx2 = ox + nxt * fac
                    yy1 = oy
                    yy2 = oy
                    ZLINE xx1, xx2, yy1, yy2, 1, cc
                    ' reset orig
                    ox = xx2
                    oy = yy2
                ElseIf resu = 1 Then    ' up/down
                    xx1 = ox
                    xx2 = ox
                    yy1 = oy
                    yy2 = oy + nxt * fac
                    ZLINE xx1, xx2, yy1, yy2, 1, cc
                    ' reset orig
                    ox = xx2
                    oy = yy2
                End If
                ' exit
                If aRMS(ii, jj + 3) = Empty Then
                    Exit For
                End If
            Next jj
        Next ii
    End Sub
    ' 3. sub to draw a "dot"
    Sub ZDOT(nXX1, nYY1, nDW, nCC)
        With PB1
            .DrawWidth = nDW
            PB1.PSet (nXX1, nYY1), nCC
        End With
    End Sub
    ' 4. sub to draw a line
    Sub ZLINE(nXX1, nXX2, nYY1, nYY2, nDW, nCC)
        With PB1
            .DrawStyle = 0
            .DrawWidth = nDW
            PB1.Line (nXX1, nYY1)-(nXX2, nYY2), nCC
        End With
    End Sub
    The basic steps are
    • read the text file line by line, into v1 (temporary array, holds results of Split function)
    • assign to main array, aRMS()
    • loop through aRMS(), room-by-room, and plot its perimeter (and flag its origin)


    In the image below
    • rooms are shown in black
    • HVAC unit is shown in red

    This app is "crude", but is pretty simple.
    Hope this gives you some ideas.

    Spoo

    .
    Attached Images Attached Images  
    Last edited by Spoo; May 24th, 2010 at 12:32 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
  •  



Click Here to Expand Forum to Full Width