Author Topic: Which is more beautiful . . .  (Read 11027 times)

0 Members and 1 Guest are viewing this topic.

jbuzbee

  • Swamp Rat
  • Posts: 851
Which is more beautiful . . .
« on: September 29, 2010, 11:59:11 AM »
I've seen a number of challenges and "why I wrote this" type threads so I thought I try one out:

What initially drew me to AutoLISP was the ability to write quick and dirty routines, on the fly when needed, to cut drafting times in half!  Of course as I learned more my routines became more robust and thus much more complicated.  Did I get caught up in the "figuring out" of a complex process? (remember, I'm an architect, my knowledge of all things digital is very limited!) 

So my question is: Which one of the following routines is more beautiful to you?  Don't make the decision too complicated by arguing function, use, etc.  Just which one are you first drawn too?

A
Code: [Select]
(defun c:MyLine( / )
  (command "line" pause pause "")
  (princ)
  )

B
Code: [Select]
(defun c:MyLine (/ *Error* doc act space p1 p2 pt1 pt2)
  (defun *Error* (Msg)
    (cond ((or (not Msg)
       (member Msg '("console break" "Function cancelled" "quit / exit abort"))
       )
   )
  ((princ (strcat "\nError: " Msg)))
  )
    (princ)
    )
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-StartUndoMark doc)
  (setq act (vlax-get doc 'activespace))
  (cond ((= act 1)
(setq space (vlax-get doc 'modelspace))
)
((= act 0)
(setq space (vlax-get doc 'paperspace))
)
)
  (setq p1 (getpoint "\nSelect start point: "))
  (if p1
    (setq p2 (getpoint p1 "\nSelect end point: "))
    )
  (if (and p1 p2)
    (progn
    (setq pt1 (vlax-3d-point p1)
  pt2 (vlax-3d-point p2)
  )
    (vla-addline space pt1 pt2)
    )
    )
  (vla-EndUndoMark doc)
  (princ)
  )
James Buzbee
Windows 8

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Which is more beautiful . . .
« Reply #1 on: September 29, 2010, 12:11:22 PM »
B
Tim

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

Please think about donating if this post helped you.

JohnK

  • Administrator
  • Seagull
  • Posts: 10640
Re: Which is more beautiful . . .
« Reply #2 on: September 29, 2010, 12:13:26 PM »
In this case/application/need: A
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

pkohut

  • Bull Frog
  • Posts: 483
Re: Which is more beautiful . . .
« Reply #3 on: September 29, 2010, 12:16:42 PM »
A
New tread (not retired) - public repo at https://github.com/pkohut

Hangman

  • Swamp Rat
  • Posts: 566
Re: Which is more beautiful . . .
« Reply #4 on: September 29, 2010, 12:23:35 PM »
... the ability to write quick and dirty routines, on the fly when needed, to cut drafting times in half!

As Se7en mentioned, case/application/need:  I also say  A


Quote from: jbuzbee
... Did I get caught up in the "figuring out" of a complex process?

For this type of function, Yes.  Especially when your initial focus is "... quick and dirty routines, on the fly when needed, to cut drafting times in half!"

However, ... It's sooo much fun to create, build, modify, and watch your creation function and florish and improve your mundane drafting experience.  So, B.    :wink:
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LE3

  • Guest
Re: Which is more beautiful . . .
« Reply #5 on: September 29, 2010, 12:29:13 PM »
A

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Which is more beautiful . . .
« Reply #6 on: September 29, 2010, 12:45:22 PM »
C  :-P

Code: [Select]
(defun addline (/ e p1 p2)
  (and (setq p1 (getpoint "\nSpecify first point:"))
       (setq p2 (getpoint p1 "\nSpecify next point:"))
       (setq e (entmakex (list '(0 . "LINE") (cons 10 p1) (cons 11 p2))))
  )
  e
)
(addline)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

pkohut

  • Bull Frog
  • Posts: 483
Re: Which is more beautiful . . .
« Reply #7 on: September 29, 2010, 01:34:41 PM »
C is so much better than the others. A, makes me cringe, and B provided a WTHIT moment.
New tread (not retired) - public repo at https://github.com/pkohut

Aerdvark

  • Guest
Re: Which is more beautiful . . .
« Reply #8 on: September 29, 2010, 01:52:10 PM »
C for shure.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Which is more beautiful . . .
« Reply #9 on: September 29, 2010, 02:08:29 PM »
For the intention, A.  I would say B, but 1) no code comments 2) no prefix comments explaining what it does and what its for, and 3) OVERKILL is a command, not a way of life.   :-P
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Chris

  • Swamp Rat
  • Posts: 548
Re: Which is more beautiful . . .
« Reply #10 on: September 29, 2010, 03:00:53 PM »
for Simplicity A
overall C
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Which is more beautiful . . .
« Reply #11 on: September 29, 2010, 03:29:46 PM »
C, but if I were to use A, I'd take the following route:

Code: [Select]
(defun c:A2 (/ p1 p2)
  (if (and (setq p1 (getpoint "\nSpecify first point: "))
           (setq p2 (getpoint p1 "\nSpecify next point: "))
      )
    (command "_.line" "_non" p1 "_non" p2 "")
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Which is more beautiful . . .
« Reply #12 on: September 29, 2010, 03:35:41 PM »
If I had to go the (B) ActiveX route ...

Code: [Select]
(defun c:Quick_And_Dirty_Alternative_D ( / p1 p2 doc )

    [color=green];;  For this exercise a non wcs is not corrected for
    ;;  and thus will produce shit results just like the
    ;;  other examples. No hate, just sayin'.[/color]

    (if
        (and
            (setq p1 (getpoint "\nSelect start point: "))
            (setq p2 (getpoint p1 "\nSelect end point: "))
        )
        (progn
            (vla-StartUndoMark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
            (vla-addline
                (vlax-get doc
                    (if (eq 1 (getvar "cvport"))
                        'PaperSpace
                        'ModelSpace
                    )
                )
                (vlax-3d-point p1)
                (vlax-3d-point p2)
            )
            (vla-EndUndoMark doc)
        )
    )

    (princ)

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Which is more beautiful . . .
« Reply #13 on: September 29, 2010, 03:38:08 PM »
Code: [Select]
   [color=green];;  For this exercise a non wcs is not corrected for
    ;;  and thus will produce shit results just like the
    ;;  other examples. No hate, just sayin'.[/color]

Minus the command one.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Which is more beautiful . . .
« Reply #14 on: September 29, 2010, 03:39:47 PM »
true / sorry / that's what I get for posting quick and dirty
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst