Author Topic: Which is more beautiful . . .  (Read 11017 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: 10633
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: 7528
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

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Which is more beautiful . . .
« Reply #15 on: September 29, 2010, 03:40:31 PM »
Code: [Select]
(if (eq 1 (getvar "cvport"))
                        'PaperSpace
                        'ModelSpace
                    )

So that's how you do that!! I have some ancient code to update now. LOL

thanks MP, always nice to see how your mind works.
TheSwamp.org  (serving the CAD community since 2003)

LE3

  • Guest
Re: Which is more beautiful . . .
« Reply #16 on: September 29, 2010, 04:10:21 PM »
If there are more options.... then will go with the alias:

Command: L

And forget about any complex customization -  :-P

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Which is more beautiful . . .
« Reply #17 on: September 29, 2010, 04:33:37 PM »
What Luis said ^^

Form follows function

so, for the quoted example  'L'  via the PGP file definitions.


Otherwise, in principle , C


or to keep John happy, A  :)

(added:kdub] we all realise that beauty is not necessarily related to functionality, yes ??
« Last Edit: September 29, 2010, 05:06:34 PM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10633
Re: Which is more beautiful . . .
« Reply #18 on: September 29, 2010, 04:59:11 PM »
*sigh* I choose method Q!


Someone asking question: What came first the Chicken or the Egg?
Some people here: The Camel because it can live longer in the desert.
*palm to face*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Which is more beautiful . . .
« Reply #19 on: September 29, 2010, 09:09:01 PM »
Thanks for playing!

As some of you know I'm no longer in the AutoCAD, AutoLISP, coding game.  This was a physiological profiling exercise.  Thanks for the feedback!

jb
« Last Edit: September 30, 2010, 07:07:03 AM by jbuzbee »
James Buzbee
Windows 8

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Which is more beautiful . . .
« Reply #20 on: September 30, 2010, 12:01:19 AM »

Quote
This was a physiological profiling excesses.

That's funny - I don't care who you are !!
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Re: Which is more beautiful . . .
« Reply #21 on: September 30, 2010, 03:27:51 AM »
C is so much better than the others. A, makes me cringe, and B provided a WTHIT moment.

I've not heard of a WITHIT moment before.

dJE
===
dJE

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Which is more beautiful . . .
« Reply #22 on: September 30, 2010, 07:42:00 AM »
what the hell is that ?

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

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Which is more beautiful . . .
« Reply #23 on: September 30, 2010, 10:17:58 AM »
Think about it:  I've noticed an intersting trend in message boards.  People are more free to respond due to the anonymity of the internet.  This site, which attracts very intelligent and technically advanced users, illustrates very different personality traits.  This thread alone clearly identifies conservatism, complexity, and creativity (option C!).

That's what makes this site and forum such a wonderful resource.  I hope it never changes . . ..
James Buzbee
Windows 8

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Which is more beautiful . . .
« Reply #24 on: September 30, 2010, 10:21:16 AM »
...
That's what makes this site and forum such a wonderful resource.  I hope it never changes . . ..

X2  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Which is more beautiful . . .
« Reply #25 on: September 30, 2010, 02:37:44 PM »
C with a litle change

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

pkohut

  • Bull Frog
  • Posts: 483
Re: Which is more beautiful . . .
« Reply #26 on: September 30, 2010, 02:44:46 PM »
C with a litle change

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

You broke it. Pick first point. Right click for second point. "entmakex" should not run, p2 is nil.
New tread (not retired) - public repo at https://github.com/pkohut

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Which is more beautiful . . .
« Reply #27 on: September 30, 2010, 02:54:03 PM »
C with a litle change

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

From a code perspective it would be good if the function returned something so you could do something with it after it's drawn  :-D:

(if (setq line (addline))
  (command "_move" line "" pause pause)
  (alert "oh noes!!")
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Which is more beautiful . . .
« Reply #29 on: September 30, 2010, 03:23:54 PM »
Alright... my turn!!

Code: [Select]
Option Explicit

Public Sub MainLine()
    Dim Point1 As Variant
    Dim Point2 As Variant
    Dim line As AcadLine
   
    If MyGetPoints(Point1, Point2) = 0 Then  'no CANCEL
        Set line = ThisDrawing.ModelSpace.AddLine(Point1, Point2)
    End If
End Sub


Private Function MyGetPoints(pt1 As Variant, pt2 As Variant) As Integer
    ' This sub returns two points, or an error flag if cancelled

    On Error Resume Next
   
    pt1 = ThisDrawing.Utility.getPoint(, "Specify first point:")
    If Err Then
        MyGetPoints = -1
        Exit Function
    End If
    pt2 = ThisDrawing.Utility.getPoint(pt1, "Specify second point:")
    If Err Then
        MyGetPoints = -1
        Exit Function
    End If
   
On Error GoTo 0
End Function

 :roll:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Which is more beautiful . . .
« Reply #30 on: September 30, 2010, 03:33:39 PM »
Quote
Alright... my turn!!

Exactly!


Thankyou.


 :wink:
James Buzbee
Windows 8

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Which is more beautiful . . .
« Reply #31 on: September 30, 2010, 04:32:44 PM »

and then there is option P
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Which is more beautiful . . .
« Reply #32 on: September 30, 2010, 07:38:53 PM »
And option S: draw a line from here to there.  No, not on that layer, the correct one.  What?  Line type is BYLAYER, just like everything else.  Is that color BYLAYER too?  Of course thats the way its supposed to be.   :realmad:
If you are going to fly by the seat of your pants, expect friction burns.

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