TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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
(defun c:MyLine( / )
(command "line" pause pause "")
(princ)
)
B
(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)
)
-
B
-
In this case/application/need: A
-
A
-
... 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
... 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:
-
A
-
C :-P
(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)
-
C is so much better than the others. A, makes me cringe, and B provided a WTHIT moment.
-
C for shure.
-
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
-
for Simplicity A
overall C
-
C, but if I were to use A, I'd take the following route:
(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)
)
-
If I had to go the (B) ActiveX route ...
(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)
)
-
[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.
-
true / sorry / that's what I get for posting quick and dirty (http://www.theswamp.org/screens/mp/facepalm.gif)
-
(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.
-
If there are more options.... then will go with the alias:
Command: L
And forget about any complex customization - :-P
-
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 ??
-
*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*
-
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
-
This was a physiological profiling excesses.
That's funny - I don't care who you are !!
-
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
-
what the hell is that ?
/guess
-
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 . . ..
-
...
That's what makes this site and forum such a wonderful resource. I hope it never changes . . ..
X2 :-)
-
C with a litle change
(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)
)
-
C with a litle change
(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.
-
C with a litle change
(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!!")
)
-
C with a litle change
You broke it.
:-D
-
Alright... my turn!!
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:
-
Alright... my turn!!
Exactly!
Thankyou.
:wink:
-
and then there is option P
-
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: