Author Topic: There has to be a better way to deal with subroutines  (Read 1624 times)

0 Members and 1 Guest are viewing this topic.

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
There has to be a better way to deal with subroutines
« on: December 10, 2008, 09:05:04 AM »
This is my current code:

Code: [Select]
(SETQ fpt (GETPOINT "\nSelect start point: "))
(POINT2D3D (fpt))
(SETQ
fpt cpt
cpt nil
)

cpt is the output of the POINT2D3D subroutine.

I'm repeating this process for a number of later points, hence wanting to use the subroutine.  Surely there has to be a more efficient way to move the sub's output back to the original variable and empty the sub's variable?

dJE
===
dJE

ronjonp

  • Needs a day job
  • Posts: 7531
Re: There has to be a better way to deal with subroutines
« Reply #1 on: December 10, 2008, 10:02:34 AM »
I'm not quite sure what you are asking  :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: There has to be a better way to deal with subroutines
« Reply #2 on: December 10, 2008, 10:08:58 AM »
Try this [Not tested]
Code: [Select]
;;  returns point list or nil
(defun MyGetPoint (msg / pt)
  (if (SETQ pt (GETPOINT (strcat "\n" msg)))
    (setq pt (POINT2D3D pt))
  )
)

(while (null (setq fpt (MyGetPoint "Select start point: ")))
  (prompt "Error, must pick a point, Try again.")
)
or this:
Code: [Select]
;;  returns point list
(defun MyGetPoint (msg / pt)
  (while (null (SETQ pt (GETPOINT (strcat "\n" msg))))
    (prompt "Error, must pick a point, Try again.")
  )
  (POINT2D3D pt)
)

(setq fpt (MyGetPoint "Select start point: "))
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.

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Re: There has to be a better way to deal with subroutines
« Reply #3 on: December 11, 2008, 03:54:02 AM »
Try this [Not tested]
Code: [Select]
;;      (setq pt (POINT2D3D pt))[/quote]

That looks like it should be the one, ta

dJE
===
dJE

JohnK

  • Administrator
  • Seagull
  • Posts: 10655
Re: There has to be a better way to deal with subroutines
« Reply #4 on: December 11, 2008, 08:23:03 AM »
> I'm repeating this process for a number of later points, hence wanting to use
> the subroutine.  Surely there has to be a more efficient way to move the sub's
> output back to the original variable and empty the sub's variable?

Have a look at my paper on this subject.

[ http://www.theswamp.org/index.php?topic=5203.0 ]
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org