PDA

View Full Version : Calling all Gurus: Here is an easy one


jack.frahm
2004-12-18, 01:09 AM
Command: L
LINE Specify first point: _from Base point: <Offset>: .06

Specify next point or [Undo]: _from Base point: <Offset>: .06


How would I make the above series of commands one easy LISP routine? I would like to create a LISP routine that would allow the drawing of a line that starts offset at .xx from user input.

Thanks in advance,
Jack

paulmcz
2004-12-18, 01:22 AM
... offset 0.06, OK, but at what angle from the base point?

Command: L
LINE Specify first point: _from Base point: <Offset>: .06

Specify next point or [Undo]: _from Base point: <Offset>: .06


How would I make the above series of commands one easy LISP routine? I would like to create a LISP routine that would allow the drawing of a line that starts offset at .xx from user input.

Thanks in advance,
Jack

rkmcswain
2004-12-18, 03:10 AM
Command: L
LINE Specify first point: _from Base point: <Offset>: .06

Specify next point or [Undo]: _from Base point: <Offset>: .06


How would I make the above series of commands one easy LISP routine? I would like to create a LISP routine that would allow the drawing of a line that starts offset at .xx from user input.

Thanks in advance,
Jack

Something like this?

(defun c:myline (/ p1)
(command "._line"
(polar (setq p1 (getpoint "\nSpecify first point: "))
(* 0.5 pi)
0.06
)
(polar (getpoint p1 "\nSpecify next point: ")
(* 0.5 pi)
0.06
)
""
)
(princ)
)


You will have to modify the angle to suit your needs. Currently it's 90°

CAB2k
2004-12-18, 06:35 PM
Here are some more options:
(defun c:myline (/ p1)
(if (and (setq p1 (getpoint "\nSpecify first point: "))
(setq p2 (getpoint p1 "\nSpecify next point: ")))
(command "._line"
(polar p1 (* 0.5 pi) 0.06)
(polar p2 (* 0.5 pi) 0.06)
""
)
)
(princ)
)

(defun c:myline (/ p1)
(if (and (setq p1 (getpoint "\nSpecify first point: "))
(setq p2 (getpoint p1 "\nSpecify next point: ")))
(command "._line" p1 p2 ""
"_.move" "L" "" p1 (polar p1 (* 0.5 pi) 0.06) ""
)
)
(princ)
)

kennet.sjoberg
2004-12-18, 11:53 PM
Hi Jack, have fun

(defun c:parl ( / Pkt1 ) ;; *Offset*

(defun parl_err (msg / ask )
(princ "\nUser [Esc]. " )
(if (not *Offset* ) (setq *Offset* 0 ) ( ) )
(setq *error* OldErr )
(setq ask (getreal (strcat "New Offset <" (rtos *Offset* 2 2 )"> or Enter ? : " )) )
(if ask (setq *Offset* ask ) (setq *Offset* *Offset* ) )
(drawl)
)

(defun drawl ( / OldErr Pkt2 )
(setq OldErr *error* *error* parl_err )
(initget 65 )
(if (not *Offset* ) (while (not (setq *Offset* (getdist "Digitize the distance or enter a real : " )))) ( ) )
(princ (strcat "\nPresent Offset is " (rtos *Offset* 2 2 ) ", use [Esc] to change.\n" ) )
(if (not Pkt1 ) (while (not (setq Pkt1 (getpoint "Start point: ")))) )
(while (not (setq Pkt2 (getpoint "End point: "))) )
(command "._line"
(polar Pkt1 (+ (angle Pkt1 Pkt2 ) (/ PI 2 )) *Offset* )
(polar Pkt2 (+ (angle Pkt1 Pkt2 ) (/ PI 2 )) *Offset* )
""
)
(setq *error* OldErr )
)

(drawl)
(princ)
)

paulmcz, the line is parallel to the 2 points
rkmcswain, what happens when You draw a vertical line ?
ab2draft, what happens when You draw a vertical line ?
ab2draft, what happens again when You draw a vertical line ?

: ) Happy Computing !

kennet

CAB2k
2004-12-19, 02:19 AM
kennet,
sorry I did not test the code, just offering options for limited error checking.

How about one that repeats until enter is pressed and you may change the offset as in your code, sort of like your code :-).

(defun c:myline (/ p1 p2 ang)
;; remembers changed offset
;; press ENTER to quit
;; press O to change offset
;; to offset to the opposit direction pick points in reverse order
;; or enter a negative offset
(setq off|set (cond (off|set) (0.06)); default
p1 t
)
(while
(and
(not
(while (and p1 (/= (type p1) 'list))
(initget "Offset")
(setq p1 (getpoint
(strcat "\nPick first point or [Offset] to change: "
(rtos off|set))))
(if (= p1 "Offset")
(while (not (setq off|set (getdist "\nEnter new offset distance: ")))))
)
)
(and p1
(setq p2 (getpoint p1 "\nSpecify next point: "))
(setq ang (- (angle p1 p2) (* 0.5 pi))
p1 (polar p1 ang off|set)
p2 (polar p2 ang off|set)
)
(not (command "._line" p1 p2 ""))
(setq p1 T)
)
)
)
(princ)
)

rkmcswain
2004-12-19, 04:38 AM
rkmcswain, what happens when You draw a vertical line ?
kennet
Same thing it does when you draw a line at any other angle. Both line endpoints are 0.06 units away, at 90°, from the two picked points, just what the code tells it to do, unless I'm missing something.

kennet.sjoberg
2004-12-19, 12:37 PM
Same thing it does when you draw a line at any other angle . . unless I'm missing something.

Yes rkmcswain, my routine always draw the line offset and parallel,
Your routine draws the line parallel 0 dislocated when vertical.

: ) Happy Computing !

kennet

rkmcswain
2004-12-19, 03:07 PM
Yes rkmcswain, my routine always draw the line offset and parallel,
Your routine draws the line parallel 0 dislocated when vertical.
kennet
That's great, but the original post never specified an angle from which the offset points should be offset.

...allow the drawing of a line that starts offset at .xx from user input
My last comment on the first post indicated to the OP that the angle might have to be modified by the OP, possibly at run time.

kennet.sjoberg
2004-12-19, 04:56 PM
mmm..rkmcswain, In Your opinion You are totally right,
That's great, but the original post never specified an angle from which the offset points should be offset.
But for me is an offset distance always perpendicular to a line or curve,
or in AutoCAD terms "Offsetting creates a new object whose shape parallels the shape of a selected object."
and in our case an fictitious line through two points.

: ) Happy Computing !

kennet

paulmcz
2004-12-19, 05:51 PM
In the orig. post, Jack is clearly showing that he engaged osnap's "from" option and that he wants to start and finish the line using that option. Offset distance in "offset" command is always perpendicular to the line in question. When you want to start the line using "from" option of the osnap menu, the offset distance is only one of two parameters, you have to specify. The other is an angle.
Line could be parallel to 2 points, but not necessarily. In both, start and finish you could specify different angle and in that case the line will not be parallel to 2 points, from which the offset distance remains constant.

kennet.sjoberg
2004-12-19, 11:54 PM
OK paulmcz, You have two points, both points have a fictitious circle with radius .06
from both circle origin You can walk the distance .06 in a free direction as You wish,
and glue a line in the two new points, that line can act as a push pole on a old fashion steam-train and tilt in many different ways.
I can not see a reason for a command like that and I do not think Jack mentioned that either.
Maybe Jack can clarify.


: ) Happy Computing !

kennet

paulmcz
2004-12-20, 02:17 AM
Hi Kennet,

I was hoping that Jack would clarify right at the start of this thread.
If Jack meant to use the same angle in "from" osnap option for both points, he could simply draw the line containing these 2 points and then move it 0.06 units in that angle. That, I think, would be the shortest way and very simple lisp routine. But that only Jack knows.

As you say:
Maybe Jack can clarify.

Paul.

kennet.sjoberg
2004-12-20, 10:27 AM
Yes paulmcz, that was exactly what ab2draft did in his second function in his first post,
but there he did not take fully care of the angle in the moving direction,
here is a modified one of that version.

(defun c:myline (/ p1 p2 )
(if (and (setq p1 (getpoint "nSpecify first point: ")) (setq p2 (getpoint p1 "nSpecify next point: ")) )
(command "._line" p1 p2 ""
"_.move" "L" "" p1 (polar p1 (+ (angle p1 P2) (/ PI 2)) 0.06) "" ) )
(princ)
)

When running the original and the modified code, it is especially easy to see the difference when creating vertical lines.

: ) Happy Computing !

kennet

kennet.sjoberg
2004-12-20, 12:47 PM
Simple and really fun..
Draws continues lines with preset offset and fillet values.
no errorhandler.. no flashing options.. just a few lines of simple code.. feel free to modify..

(defun c:pl ( / Pkt1 Pkt2 I PktE E1 E2 SelSet )
(if (minusp (getvar "OFFSETDIST" ))(setvar "OFFSETDIST" 1.0e-020 )( ))
(princ (strcat "\nCommand: Using preset FILLETRAD of " (rtos (getvar "FILLETRAD" ))) )
(princ (strcat "\nCommand: Using preset OFFSETDIST of " (rtos (getvar "OFFSETDIST" ))) )
(princ (strcat "\nCommand: Using preset PLINEWID of " (rtos (getvar "PLINEWID" ))) )
(setq Pkt1 (getpoint "\nStart point: " ) )
(setq Pkt2 (getpoint "Next point: " ) )
(setq I 1 )
(while Pkt2
(setq I (* I -1 ))
(if Pkt1 (command "._line" Pkt1 Pkt2 "" ) (command "._line" "" Pkt2 "" ) )
(if Pkt1 (setq PktE Pkt1 ) (setq PktE Pkt2 ) )
(command "._select" (entlast) "" )
(command "._offset" (getvar "OFFSETDIST" ) (entlast) (polar Pkt2 (+ (angle PktE Pkt2 ) (/ PI 2 )) (getvar "OFFSETDIST" ) ) "" )
(command "._erase" "p" "" )
(if (not SelSet ) (setq SelSet (ssadd)) ( ) )
(ssadd (entlast) SelSet )
(if (minusp I ) (setq E1 (cdr (assoc -1 (entget (entlast)))) ) (setq E2 (cdr (assoc -1 (entget (entlast)))) ) )
(if E2 (progn (command "._fillet" E1 E2 )(ssadd (entlast) SelSet )) ( ) )
(setq Pkt1 nil )
(setq Pkt2 (getpoint " Next point: " ) )
)
(command "pedit" "M" SelSet "" "Y" "J" "" "W" (getvar "PLINEWID" ) "" )
(princ "\nCommand:" )
(princ "\nChange offset distance with Command: Offset NN ..or (setvar \42OFFSETDIST\42 N.n )" )
(princ "\nChange fillet radius with Command: Fillet R ..or (setvar \42FILLETRAD\42 R.r )" )
(princ "\nChange Pline Width with Command: Pline pick W ..or (setvar \42PLINEWID\42 W.w )" )
(princ)
)


: ) Happy Computing and Christmas !

kennet

ps.
If You set (setvar "OFFSETDIST" -1 ) it will not be any offset
ds.