Author Topic: Intermediate Challenge - Building Outline  (Read 7143 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Intermediate Challenge - Building Outline
« on: April 28, 2008, 04:33:25 PM »
The challenge is to write a lisp that would create a building outline from user input of the keyboard only.
The idea is to limit the keystrokes needed.
Here is some pseudo code I dreamed up, your may vary.
Extra credit if there is an UNDO key.

Code: [Select]
1 - Option for lines or plines
2 - Get start point
3 - Get direction, numeric keypad or arrow keys
       numbers 1 7 9 3 = 45 degree lines
       else if ENTER then quit.
4 - Get distance, Feet then if dot key get decimal feet
      else if space bar or zero or minus key then get inches
      else if ENTER end of distance
5 - Repeat 3 and 4

The thread that spawned the idea.
http://www.theswamp.org/index.php?topic=22794.0
« Last Edit: April 28, 2008, 05:00:10 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Intermediate Challenge - Building Outline
« Reply #1 on: April 28, 2008, 04:42:15 PM »
do you think you should link the thread where this all started so everyone can have a little something to work with?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Intermediate Challenge - Building Outline
« Reply #2 on: April 28, 2008, 06:33:00 PM »
Here you go.  Could be better, but it is cool for now.   :lol:

Code: [Select]
(defun c:Challenge (/ Pt PtList Ang Dist EntryStr Pos GrVecList PlObj)
   
    (if
        (and
            (setq Pt (getpoint "\n Select starting point: "))
            (setq PtList
                (cons
                    (cadr Pt)
                    (cons
                        (car Pt)
                        PtList
                    )
                )
            )
            (setq GrVecList (list Pt 1))
        )
        (while (/= (setq EntryStr (getstring "\n Enter direction and distance [ie. 825 = 90 degrees at 25 feet]: ")) "")
            (setq Ang (substr EntryStr 1 1))
            (setq Dist (substr EntryStr 2))
            (setq Ang
                (cond
                    ((= Ang "1")
                        (+ pi (* pi 0.25))
                    )
                    ((= Ang "2")
                        (+ pi (* pi 0.5))
                    )
                    ((= Ang "3")
                        (+ pi (* pi 0.75))
                    )
                    ((= Ang "4")
                        pi
                    )
                    ((= Ang "6")
                        0.0
                    )
                    ((= Ang "7")
                        (* pi 0.75)
                    )
                    ((= Ang "8")
                        (* pi 0.5)
                    )
                    ((= Ang "9")
                        (* pi 0.25)
                    )
                )
            )
            (setq Dist
                (cond
                    ((setq Pos (vl-string-search "." Dist))
                        (+
                            (* 12 (distof (substr Dist 1 Pos)))
                            (* (distof (substr Dist (1+ Pos))) 12)
                        )
                    )
                    ((setq Pos (vl-string-search "-" Dist))
                        (+
                            (* 12 (distof (substr Dist 1 Pos)))
                            (distof (substr Dist (+ 2 Pos)))
                        )
                    )
                    (t (* 12 (distof Dist)))
                )
            )
            (setq GrVecList
                (cons
                    (setq Pt (polar Pt Ang Dist))
                    (cons
                        1
                        (cons
                            Pt
                            GrVecList
                        )
                    )
                )
            )
            (setq PtList
                (cons
                    (cadr Pt)
                    (cons
                        (car Pt)
                        PtList
                    )
                )
            )
            (grvecs (reverse (cddr GrVecList)))
        )
    )
    (if (> (length PtList) 2)
        (setq PlObj
            (vlax-invoke
                (vlax-get
                    (vla-get-ActiveDocument (vlax-get-Acad-Object))
                    (if (equal (getvar 'CVPort) 1)
                        'PaperSpace
                        'ModelSpace
                    )
                )
                'AddLightWeightPolyline
                (reverse PtList)
            )
        )
    )
    (if
        (=
            (progn
                (initget "Line Polyline")
                (getkword "\n New object should be [Line/Polyline] <Polyline>: ")
            )
            "Line"
        )
        (progn
            (vlax-invoke PlObj 'Explode)
            (vla-Delete PlObj)
        )
    )
    (redraw)
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Intermediate Challenge - Building Outline
« Reply #3 on: April 28, 2008, 07:16:12 PM »
Tim, Nicely done and works well.
Only comment is if you pan or zoom the vectors are lost.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Intermediate Challenge - Building Outline
« Reply #4 on: April 28, 2008, 07:32:52 PM »
that's awesome tim!
i can't believe how this is turning out.

i did notice that if you type in an invalid string (ie: 2) then it just ends and you don't get anything.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Intermediate Challenge - Building Outline
« Reply #5 on: April 28, 2008, 07:45:41 PM »
Tim, Nicely done and works well.
Only comment is if you pan or zoom the vectors are lost.

Thanks Alan.  Yea I know about the changing the view thingy, but will let someone else solve that.  :evil: But it should redraw with each new element entered.

that's awesome tim!
i can't believe how this is turning out.

i did notice that if you type in an invalid string (ie: 2) then it just ends and you don't get anything.
Thanks.  Yea there is no error checking, but this is a proof of idea.  This is open for others to build upon, and I think I wrote it in a fashion that people could add to it simply.  Well I hope I did.  :-)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Dinosaur

  • Guest
Re: Intermediate Challenge - Building Outline
« Reply #6 on: April 28, 2008, 08:07:30 PM »
What would have to be done to this to make it work in foot units to two decimal places ie. 24.68'?  One of our more tedious tasks is to take an architectural foundation plan and draw a footprint in decimal feet for a site plan.  We waste a large chunk of time converting units, offsetting and filleting.  I am sure something like this would make it much less error prone and tedious.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Intermediate Challenge - Building Outline
« Reply #7 on: April 28, 2008, 08:16:26 PM »
Not a big deal, my routine addresses that.
As Tim said his routine addresses the basic requirements and others may build upon it.

I can't post mine as it isn't complete yet but here is where i am headed.
Code: [Select]
    ;;  decode distance entry, where nn is a number key
    ;;  Although UNITS are set to Inches in the Drawing the User
    ;;   Input is primarily in Feet and Inches but the following
    ;;   numeric input is allowable.
    ;;
    ;;  nn[ENTER] Feet
    ;;  nn.nn[ENTER] Feet & decimal feet
    ;;  nn-nn[ENTER] Feet & inches
    ;;  nn-nn.nn[ENTER] Feet & inches plus decimal inches
    ;;  nn-nn n/n[ENTER] Feet & inches plus fractional inches
    ;;  * and dir = 1 3 7 9 -> Triangle Mode, distance if of
    ;;     the right angle leg
    ;;  nn+ Inches
    ;;  nn.nn+ Inches & decimal inches
    ;;  nn n/n+ Inches & fractional inches
    ;;  C c Close polyline
« Last Edit: April 28, 2008, 08:21:08 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Intermediate Challenge - Building Outline
« Reply #8 on: April 28, 2008, 09:15:42 PM »
i know keith had a big part in this one, but here it is anyway:

Code: [Select]
(defun line_info(/ bear bldg_direction bldg_dist)
(princ "\n       7        8        9")
(princ "\n    (45°NW)    (UP)   (45°NE)")
(princ "\n       4                 6")
(princ "\n     (LEFT)           (RIGHT)")
(princ "\n       1        2        3")
(princ "\n    (45°SW)   (DOWN)  (45°SE)")
  (initget "1 2 3 4 6 7 8 9 Quit")
(setq bldg_direction (getkword "\nDirection (8=Up, 6=Right, 2=Down, 4=Left), <Quit>: "))
  (cond
  ((= bldg_direction "Quit")(setq bldg_direction nil))
  ((= bldg_direction "")(setq bldg_direction nil))
  ((= bldg_direction "6")(setq bldg_direction "0"))
  ((= bldg_direction "9")(setq bldg_direction "45"))
  ((= bldg_direction "8")(setq bldg_direction "90"))
  ((= bldg_direction "7")(setq bldg_direction "135"))
  ((= bldg_direction "4")(setq bldg_direction "180"))
  ((= bldg_direction "1")(setq bldg_direction "225"))
  ((= bldg_direction "2")(setq bldg_direction "270"))
  ((= bldg_direction "3")(setq bldg_direction "315"))
)
  (if (/= bldg_direction nil)
  (progn
     (setq bldg_dist (getdist "\nLengh of wall: "))
     (setq bear (strcat "@" (rtos bldg_dist) "<" bldg_direction))
  )
  (setq bear nil)
)
 
)

(defun c:bldg-draw( / begin_point bear)
(setq begin_point (getpoint "\nBeginning point for building: "))
(setq bear (line_info))
(command "line" begin_point bear)
  (while (setq bear (line_info))
  (command bear)
)
  (command)
(princ)
);defun
« Last Edit: April 29, 2008, 12:50:08 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Intermediate Challenge - Building Outline
« Reply #9 on: April 29, 2008, 12:15:01 AM »
Good job Alan, you skills are improving.
I have some alternative code methods to show you but it will have to wait until tomorrow.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Intermediate Challenge - Building Outline
« Reply #10 on: April 29, 2008, 12:42:50 PM »
Here is another version that has more options, kind of like what Alan was suggesting.

Code: [Select]
(defun c:Challenge (/ Pt PtList Ang Dist EntryStr Pos- Pos. 2Pos- GrVecList PlObj StPt flag)
   
    (if
        (and
            (setq Pt (getpoint "\n Select starting point: "))
            (setq StPt Pt)
            (setq PtList
                (cons
                    (cadr Pt)
                    (cons
                        (car Pt)
                        PtList
                    )
                )
            )
            (setq GrVecList (list Pt 1))
        )
        (while
            (and
                (not flag)
                (not (initget 128 "Close Entry"))
                (setq EntryStr (getkword "\n Enter direction and distance [Close/Entry format]: "))
            )
            (cond
                ((= EntryStr "Close")
                    (setq PtList
                        (cons
                            (cadr StPt)
                            (cons
                                (car StPt)
                                PtList
                            )
                        )
                    )
                    (setq flag T)
                )
                ((= EntryStr "Entry")
                    (prompt
                        (strcat
                            "\nHow to correctly entry data."
                            "\nThe first number is the angle, based on the number pad:"
                            "\n 1 = 225"
                            "\n 2 = 270"
                            "\n 3 = 315"
                            "\n 4 = 180"
                            "\n 5 = Enter angle or pick angle on screen"
                            "\n 6 = 0"
                            "\n 7 = 135"
                            "\n 8 = 90"
                            "\n 9 = 45"
                            "\n"
                            "\nThe next numbers are the distance, and should be entered like:"
                            "\n nn = feet"
                            "\n nn.nn = feet plus decimal feet"
                            "\n nn-nn = feet plus inches"
                            "\n nn-nn.nn = feet plus inches plus decimal inches"
                            "\n nn-nn-n/n = feet plus inches plus a fraction of an inch"
                            "\n"
                            "\nSo a number entered 825-6 equals a line the length of 25'-6\" at 90 degrees from the last point."
                        )
                    )
                    (textscr)
                )
                ((> (strlen EntryStr) 1)
                    (setq Ang (substr EntryStr 1 1))
                    (setq Dist (substr EntryStr 2))
                    (setq Ang
                        (cond
                            ((= Ang "1")
                                (+ pi (* pi 0.25))
                            )
                            ((= Ang "2")
                                (+ pi (* pi 0.5))
                            )
                            ((= Ang "3")
                                (+ pi (* pi 0.75))
                            )
                            ((= Ang "4")
                                pi
                            )
                            ((= Ang "5")
                                (getangle "\n Enter desired angle: ")
                            )
                            ((= Ang "6")
                                0.0
                            )
                            ((= Ang "7")
                                (* pi 0.75)
                            )
                            ((= Ang "8")
                                (* pi 0.5)
                            )
                            ((= Ang "9")
                                (* pi 0.25)
                            )
                            (t nil)
                        )
                    )
                    (setq Dist
                        (cond
                            (
                                (and
                                    (setq Pos- (vl-string-search "-" Dist))
                                    (setq Pos. (vl-string-search "." Dist Pos-))
                                )
                                (+
                                    (* 12 (distof (substr Dist 1 Pos-)))
                                    (distof (substr Dist (+ 2 Pos-) (1- (- Pos. Pos-))))
                                    (distof (substr Dist (1+ Pos.)))
                                )
                            )
                            (
                                (and
                                    (setq Pos- (vl-string-search "-" Dist))
                                    (setq 2Pos- (vl-string-search "-" Dist (1+ Pos-)))
                                    (vl-string-search "/" Dist 2Pos-)
                                )
                                (+
                                    (* 12 (distof (substr Dist 1 Pos-)))
                                    (distof (substr Dist (+ 2 Pos-) (1- (- 2Pos- Pos-))))
                                    (distof (substr Dist (+ 2 2Pos-)))
                                )
                            )
                            ((setq Pos. (vl-string-search "." Dist))
                                (+
                                    (* 12 (distof (substr Dist 1 Pos.)))
                                    (* (distof (substr Dist (1+ Pos.))) 12)
                                )
                            )
                            ((setq Pos- (vl-string-search "-" Dist))
                                (+
                                    (* 12 (distof (substr Dist 1 Pos-)))
                                    (distof (substr Dist (+ 2 Pos-)))
                                )
                            )
                            ((= Dist "")
                                nil
                            )
                            (t (* 12 (distof Dist)))
                        )
                    )
                    (if
                        (and
                            (= (type Ang) 'REAL)
                            (= (type Dist) 'REAL)
                        )
                        (progn
                            (setq GrVecList
                                (cons
                                    (setq Pt (polar Pt Ang Dist))
                                    (cons
                                        1
                                        (cons
                                            Pt
                                            GrVecList
                                        )
                                    )
                                )
                            )
                            (setq PtList
                                (cons
                                    (cadr Pt)
                                    (cons
                                        (car Pt)
                                        PtList
                                    )
                                )
                            )
                            (grvecs (reverse (cddr GrVecList)))
                        )
                    )
                )
            )
        )
    )
    (if (> (length PtList) 2)
        (setq PlObj
            (vlax-invoke
                (vlax-get
                    (vla-get-ActiveDocument (vlax-get-Acad-Object))
                    (if (equal (getvar 'CVPort) 1)
                        'PaperSpace
                        'ModelSpace
                    )
                )
                'AddLightWeightPolyline
                (reverse PtList)
            )
        )
    )
    (if
        (=
            (progn
                (initget "Line Polyline")
                (getkword "\n New object should be [Line/Polyline] <Polyline>: ")
            )
            "Line"
        )
        (progn
            (vlax-invoke PlObj 'Explode)
            (vla-Delete PlObj)
        )
    )
    (redraw)
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Intermediate Challenge - Building Outline
« Reply #11 on: April 29, 2008, 12:54:55 PM »
Code: [Select]
"\n 5 = Enter angle or pick angle on screen"
you completely read my mind, i was working on figuring that one out.

yours is beyond incredible!
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Intermediate Challenge - Building Outline
« Reply #12 on: April 29, 2008, 12:58:41 PM »
Code: [Select]
"\n 5 = Enter angle or pick angle on screen"
you completely read my mind, i was working on figuring that one out.
Thought that might be wanted.  I think I would use it.

yours is beyond incredible!
Thanks.  Years of practice, and still learning, but you are in the right spot to learn, and seems like you have the right attitude for it, so I'm guessing it won't take you long.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Intermediate Challenge - Building Outline
« Reply #13 on: April 29, 2008, 02:19:49 PM »
Similar...here is one to draw with bearing info. Just modify the code for direction in lieu of bearing.
Nice dialog box interface.

Cadalyst Get the Code! Browseby Joon Hong, p.68 LL.LSP and LL2.DCL help you quickly draw bearing lines. The list box in the dialog stores a list of the lines you've input for reuse. ...
new.cadalyst.com/code/browseyear.cfm?fullyear=2002 - 55k - Cached - Similar pages
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Intermediate Challenge - Building Outline
« Reply #14 on: April 29, 2008, 02:24:14 PM »
Code: [Select]
"\n 5 = Enter angle or pick angle on screen"
you completely read my mind, i was working on figuring that one out.
Thought that might be wanted.  I think I would use it.

yours is beyond incredible!
Thanks.  Years of practice, and still learning, but you are in the right spot to learn, and seems like you have the right attitude for it, so I'm guessing it won't take you long.

yeah, i only started learing lisp in my free time about 8-9 months ago.
most of mine are simple, but they are improving.

i can't believe how much i've learned since i came here.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox