TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: danny on November 19, 2004, 07:36:36 PM

Title: polyline w/ multiplied factor
Post by: danny on November 19, 2004, 07:36:36 PM
I'm looking for a polyline routine that when asked for a point (x,y), and (x)is inputted, it will multiply (x) by a given number to get (y). Basically something like this
Code: [Select]
Command: pl PLINE
Specify start point: (user to pick point)
Current line-width is 0'-0"
Specify x length: (x= user input or pick from point to point)
("x" multiplied by "s" (s=a given factor)=y)
next point = x,y
repeat
Specify x length: (x= user input or pick from point to point)
("x" multiplied by "s" (s=a given factor)=y)
next point = x,y
repeat


I searched this site to find a similar routine to get me started, but.....maybe someone can point me in the right direction.
Thanx..
Title: polyline w/ multiplied factor
Post by: MP on November 19, 2004, 11:26:50 PM
Is the real question "Can one write graphing functions in LISP that will calculate Y as a function of X, using polylines to display the result"?

I would hazard a guess of "Yes".

Of course, my post was a guess in of itself.

:)
Title: polyline w/ multiplied factor
Post by: CAB on November 20, 2004, 09:11:47 AM
danny,
I assume it's the syntax you don't understand. Lisp takes some getting
use to and a lot of practice. You can do almost anything with it, usually
limited by your experience and imagination. I'm sure if you have been reading
the posts here that you know Michael has lots of both.
I will get you started with the basics. If your formula gets complicated
we will defiantly need Michaels help.
Micheal, did I miss anything?

Code: [Select]
;;  start a function & declair local variables after /
(defun c:pl-cal (/ p1 x y)
  (setvar "plinewid" 0) ; set pline width
  (setq p1 (getpoint "\nPick starting point of Line."))
  (command "._pline" p1) ; start the pline
  ;;  loop until user presses Enter
  ;; if the user presses ESCAPE the pline command will not be completed
  ;; you will have to complete it by pressing enter, an *ERROR* handler
  ;; would be needed to catch this condition.
  (while ; loop until the next argument is false (nil)
    ;;  the distance function will allow picked or real number entry
    (setq x (getdist p1 "\nEnter next 'X' value.")) ;p1 gives a starting point
    (setq y (* x 1.5)) ; calc new y value
    (setq p1 (list x y)) ; make a point list, no z, reusing variable p1
    (command p1) ; send the point to the command line
  ) ; end while
  (command "") ; complete the pline by sending ENTER to the command line
  (princ) ; clear the command line & exit
) ; end of defun
Title: polyline w/ multiplied factor
Post by: danny on November 22, 2004, 01:09:16 PM
thanks CAB,
the comments in your lisp help me out in understanding what the function is doing.  If I may, can I ask how to get 'x' & 'y' to be the dist from the last point created.  As of now, 'x' & 'y' will always be the dist from 0,0.
I appreciate the help,
Title: polyline w/ multiplied factor
Post by: CAB on November 22, 2004, 01:17:24 PM
Quote
To enter an absolute X,Y coordinate, specify a point by entering its X and Y values in the format X,Y. Use absolute X,Y coordinates when you know the precise X and Y values of the location of the point.
For example, to draw a line beginning at an X value of –2 and a Y value of 1, make the following entries on the command line:

Command:  line
From point:  –2,1

To point:  3,4

AutoCAD locates the line as follows:

Use relative X,Y coordinates when you know the position of a point in relation to the previous point. For example, to locate a point relative to –2,1, precede the next coordinate with the @ symbol:

Command:  line
From point:  –2,1

To point:  @5,3

This is the equivalent of entering the absolute coordinate 3,4.
Title: polyline w/ multiplied factor
Post by: Anonymous on November 22, 2004, 01:36:28 PM
entering @ before the x value doesn't work when prompted
Code: [Select]
Enter next 'X' value
so would I put the symbol here?
Code: [Select]
(command @p1)
Title: polyline w/ multiplied factor
Post by: CAB on November 22, 2004, 01:57:20 PM
Try this:
Code: [Select]
;;  start a function & declair local variables after /
(defun c:pl-cal (/ p1 x y)
  (setvar "plinewid" 0) ; set pline width
  (setq p1 (getpoint "\nPick starting point of Line."))
  (command "._pline" p1) ; start the pline
  ;;  loop until user presses Enter
  ;; if the user presses ESCAPE the pline command will not be completed
  ;; you will have to complete it by pressing enter, an *ERROR* handler
  ;; would be needed to catch this condition.
  (while ; loop until the next argument is false (nil)
    ;;  the distance function will allow picked or real number entry
    (setq x (getdist p1 "\nEnter next 'X' value.")) ;p1 gives a starting point
    (setq y (* x 1.5)) ; calc new y value
    ;; make a point string, no z
    (setq p$ (strcat "@" (rtos x 2) "," (rtos y 2)))
    (command p$) ; send the point to the command line
    (setq p1 (getvar "lastpoint")) ; reset p1
  ) ; end while
  (command "") ; complete the pline by sending ENTER to the command line
  (princ) ; clear the command line & exit
) ; end of defun
Title: polyline w/ multiplied factor
Post by: danny on November 22, 2004, 02:25:47 PM
aagh..strcat..works great
Mahalo,
Title: polyline w/ multiplied factor
Post by: MP on November 22, 2004, 07:24:08 PM
Sorry CAB / Danny, didn't see the resulting conversation here. Looks like Charles did good by you. The only thing I'd do is keep things very modular; dividing the app into constituent parts, but that's just my habitual divide and conquer approach.

Cheers.