Author Topic: How many ways can you create a LINE  (Read 8601 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
How many ways can you create a LINE
« on: October 04, 2005, 12:33:35 PM »
Just for fun.

How many ways can you create a line [ (0 . "LINE") ] using Auto/Visual LISP?
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How many ways can you create a LINE
« Reply #1 on: October 04, 2005, 12:52:40 PM »
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: How many ways can you create a LINE
« Reply #2 on: October 04, 2005, 01:27:08 PM »
Here are three more ways.  :-)

Code: [Select]

(if (setq sp (getpoint "\nStarting Point: "))
  (if (setq ep (getpoint sp "\nEnding Point: "))
    (command "_.line" sp ep "")
    )
  )


(if (setq sp (getpoint "\nStarting Point: "))
  (if (setq ep (getpoint sp "\nEnding Point: "))
    (entmake
      (list
'(0 . "LINE")
'(100 . "AcDbLine")
(cons 10 sp)
(cons 11 ep)
      )
    )
  )
)


(vl-cmdf "_.line"
(setq sp (getpoint "\nStart Point: "))
(getpoint sp "\nEnd Point: ")
""
)
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How many ways can you create a LINE
« Reply #3 on: October 04, 2005, 01:42:15 PM »
In case anyone couldn't see how they should modify this to suit here's some code to chew on --

Code: [Select]
(defun RubeGoldberg ( points / *error* document space p1 p2 )

    ;;  a different way to handle bozo input

    (cond
        (
            (or
                (null (listp points))
                (< (length points) 2)
                (null
                    (vl-every
                       '(lambda (point)
                            (apply 'and
                                (mapcar
                                   'numberp
                                    point
                                )
                            )
                        )
                        points
                    )
                )
            )
            (defun *error* (x)
                (princ
                    (strcat
                        "Bozo alert: Must be a list "
                        "of at least 2 points.\n"
                    )   
                )
                (princ)
            )
            (exit)
        )
    )
   
    ;;  space, the final frontier             

    (setq space
        (if
            (zerop
                (vla-get-activespace
                    (setq document
                        (vla-get-activedocument
                            (vlax-get-acad-object)
                        )
                    )   
                )
            )
            (vla-get-paperspace document)
            (vla-get-modelspace document)
        )   
    )
   
    ;;  normalize the points (i.e. make sure they're
    ;;  all 3D)
   
    (setq points
        (mapcar
           '(lambda (point)
                (while (< (length point) 3)
                    (setq point
                        (append point
                          '(0)
                        )
                    )
                )
                point
            )
            points
        )               
    )
   
    ;;  let's make two arrays before entering the loop
    ;;  (instead of making them for each iterration)
    ;;
    ;;  [ coded specifically to annoy Se7en ]
   
    (mapcar
        '(lambda (x)
            (set x
                (vlax-make-safearray
                    vlax-vbdouble
                    (cons 0 2)
                )
            )   
        )
       '(p1 p2)
    )

    ;;  a more logical way to achieve
    ;;  the same would be --
    ;;
    ;;  (foreach x '(p1 p2)
    ;;      (set x
    ;;          (vlax-make-safearray
    ;;              vlax-vbdouble
    ;;              (cons 0 2)
    ;;          )
    ;;      )   
    ;;  )
    ;;
    ;;  in the event you're going, "what
    ;;  the .." is he talking about all the
    ;;  crud above does the same as --
    ;;
    ;;  (setq
    ;;      p1 (vlax-make-safearray vlax-vbdouble (cons 0 2))
    ;;      p2 (vlax-make-safearray vlax-vbdouble (cons 0 2))
    ;;  ) 
    ;;
    ;;  Why do I bother? Because it's fun
    ;;  and I don't have many toys.
   
    ;;  anyway, let's rock and roll --
   
    (while (< 1 (length points))   
        (vlax-invoke-method
            Space
           'AddLine
            (vlax-safearray-fill p1 (car points))       
            (vlax-safearray-fill p2 (cadr points))       
        )
        (setq points (cdr points))
    )

    (princ)

)
« Last Edit: October 04, 2005, 08:29:51 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Bob Wahr

  • Guest
Re: How many ways can you create a LINE
« Reply #4 on: October 04, 2005, 02:45:42 PM »
(defun c:makealine()(command ".line"))

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How many ways can you create a LINE
« Reply #5 on: October 04, 2005, 02:55:36 PM »
Here are two simple ways you see in routines.
Code: [Select]
(command "LINE" pause pause "")
Code: [Select]
(command "LINE")
(while (> (getvar "CMDACTIVE") 0)
  (command pause)
)
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.

Bob Wahr

  • Guest
Re: How many ways can you create a LINE
« Reply #6 on: October 04, 2005, 03:03:55 PM »
Code: [Select]
(command "LINE")
(while (> (getvar "CMDACTIVE") 0)
 (command pause)
)
correct me if I'm wrong but this would fail miserably wouldn't it?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How many ways can you create a LINE
« Reply #7 on: October 04, 2005, 03:15:20 PM »
I must correct you because you are wrong.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Bob Wahr

  • Guest
Re: How many ways can you create a LINE
« Reply #8 on: October 04, 2005, 03:17:59 PM »
You're right, doesn't work as desired though.  All of this
Code: [Select]
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
is wasted and it requires enter to be pressed to get rid of the extra
Code: [Select]
)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How many ways can you create a LINE
« Reply #9 on: October 04, 2005, 03:20:17 PM »
<clearing throat>

...

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

Bob Wahr

  • Guest
Re: How many ways can you create a LINE
« Reply #10 on: October 04, 2005, 03:23:55 PM »
Code: [Select]
(command "LINE")
(while (> (getvar "CMDACTIVE") 0)
(command pause)
)
pasted into the command line looks a lot like
Code: [Select]
Command: (command "LINE")
LINE Specify first point: nil
Specify first point: (while (> (getvar "CMDACTIVE") 0)
(_> (command pause)
(_> )

Specify next point or [Undo]:
Specify next point or [Undo]:
Specify next point or [Close/Undo]:
Specify next point or [Close/Undo]:
Command: nil
He's missing the beginning bits like a
Code: [Select]
(and maybe a
Code: [Select]
defun or so.

Bob Wahr

  • Guest
Re: How many ways can you create a LINE
« Reply #11 on: October 04, 2005, 03:24:16 PM »
if not, what am I missing?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How many ways can you create a LINE
« Reply #12 on: October 04, 2005, 03:34:57 PM »
I didn't say it's elegant, just that is doesn't fail miserably.

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

Bob Wahr

  • Guest
Re: How many ways can you create a LINE
« Reply #13 on: October 04, 2005, 03:37:55 PM »
I agreed with that.  My last post was in response to "Eh?"

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: How many ways can you create a LINE
« Reply #14 on: October 04, 2005, 03:39:52 PM »
Sorry. It could benefit from a wrapper, agreed. Since we all know CAB is capable of a lot more than that I choose to believe he was just showing the bare minimum of what is frequently done.

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