TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jbuzbee on September 29, 2010, 11:59:11 AM

Title: Which is more beautiful . . .
Post by: jbuzbee 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)
  )
Title: Re: Which is more beautiful . . .
Post by: T.Willey on September 29, 2010, 12:11:22 PM
B
Title: Re: Which is more beautiful . . .
Post by: JohnK on September 29, 2010, 12:13:26 PM
In this case/application/need: A
Title: Re: Which is more beautiful . . .
Post by: pkohut on September 29, 2010, 12:16:42 PM
A
Title: Re: Which is more beautiful . . .
Post by: Hangman 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:
Title: Re: Which is more beautiful . . .
Post by: LE3 on September 29, 2010, 12:29:13 PM
A
Title: Re: Which is more beautiful . . .
Post by: ronjonp 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)
Title: Re: Which is more beautiful . . .
Post by: pkohut 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.
Title: Re: Which is more beautiful . . .
Post by: Aerdvark on September 29, 2010, 01:52:10 PM
C for shure.
Title: Re: Which is more beautiful . . .
Post by: dgorsman 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
Title: Re: Which is more beautiful . . .
Post by: Chris on September 29, 2010, 03:00:53 PM
for Simplicity A
overall C
Title: Re: Which is more beautiful . . .
Post by: alanjt 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)
)
Title: Re: Which is more beautiful . . .
Post by: MP 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)

)
Title: Re: Which is more beautiful . . .
Post by: alanjt 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.
Title: Re: Which is more beautiful . . .
Post by: MP on September 29, 2010, 03:39:47 PM
true / sorry / that's what I get for posting quick and dirty (http://www.theswamp.org/screens/mp/facepalm.gif)
Title: Re: Which is more beautiful . . .
Post by: Mark 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.
Title: Re: Which is more beautiful . . .
Post by: LE3 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
Title: Re: Which is more beautiful . . .
Post by: Kerry 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 ??
Title: Re: Which is more beautiful . . .
Post by: JohnK 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*
Title: Re: Which is more beautiful . . .
Post by: jbuzbee 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
Title: Re: Which is more beautiful . . .
Post by: Kerry 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 !!
Title: Re: Which is more beautiful . . .
Post by: Daniel J. Ellis 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
Title: Re: Which is more beautiful . . .
Post by: MP on September 30, 2010, 07:42:00 AM
what the hell is that ?

/guess
Title: Re: Which is more beautiful . . .
Post by: jbuzbee 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 . . ..
Title: Re: Which is more beautiful . . .
Post by: ronjonp 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  :-)
Title: Re: Which is more beautiful . . .
Post by: HasanCAD 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)
  )
Title: Re: Which is more beautiful . . .
Post by: pkohut 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.
Title: Re: Which is more beautiful . . .
Post by: ronjonp 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!!")
)
Title: Re: Which is more beautiful . . .
Post by: Lee Mac on September 30, 2010, 02:56:37 PM
C with a litle change

You broke it.

 :-D
Title: Re: Which is more beautiful . . .
Post by: Matt__W 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:
Title: Re: Which is more beautiful . . .
Post by: jbuzbee on September 30, 2010, 03:33:39 PM
Quote
Alright... my turn!!

Exactly!


Thankyou.


 :wink:
Title: Re: Which is more beautiful . . .
Post by: Kerry on September 30, 2010, 04:32:44 PM

and then there is option P
Title: Re: Which is more beautiful . . .
Post by: dgorsman 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: