PDA

View Full Version : Deferred Tangent


.T.
2006-02-17, 10:07 PM
Hi all,

I'm having a slight problem trying to, basically, draw a line tan-tan between two arcs with lisp.

It seems that, even with osmode set to 256, tan will not defer while picking the first point. Has anyone else had this problem?:banghead:

Here is the basic code that replicates what I am trying to do:

(defun c:dev1 (/ pt1 pt2)
(setvar "osmode" 256)
(setq pt1 (getpoint "nFirst Point: ")
pt2 (getpoint pt1 "nSecond Point: ")
)
(command "line" pt1 pt2)
(setvar "osmode" 0)
)


I've also tried:


(defun c:dev2 (/ pt1 pt2)
(setq pt1 (osnap (getpoint "nFirst Point: ") "tan")
pt2 (osnap (getpoint pt1 "nSecond Point: ") "tan")
)
(command "line" pt1 pt2)
(setvar "osmode" 0)
)

Just draw two circles and try using the routines to draw a line between them.

TIA,

Tim Creary

rad.77676
2006-02-17, 10:30 PM
Tim,
I don't see the problem here, the first routine works fine.
Second does not snap tangent because you didn't set osmode to 256
Maybe I missed the point?
Rob


(defun c:dev1 (/ pt1 pt2)
(setvar "osmode" 256)
(setq pt1 (getpoint "nFirst Point: ")
pt2 (getpoint pt1 "nSecond Point: ")
)
(new-line1)
(setvar "osmode" 0)
(princ)
)

(defun new-line1 ()
(entmake (list (cons 0 "LINE")
(cons 8 "newline")
(cons 62 30)
(cons 10 (list (car pt1) (cadr pt1)))
(cons 11 (list (car pt2) (cadr pt2)))
)
)
)

.T.
2006-02-18, 01:07 AM
Thanks for looking at it Rob.

For some reason, when I draw with the routine, it is definitely getting confused upon the second execution. The first execution works most of the time. Please see the attached drawing. It makes no sense to me.:confused:

Is there a flag I need to reset somewhere? I've declared pt1 and pt2, and verified that they are nil upon competion. Is tan hooking into "Lastpoint" or something?

The second one was trying the "OSnap" function, which is supposed to work regardless of OSMode (I'm pretty sure). It isn't really the correct tool for the job, and doesn't really do what I want anyway (lack of user intuitivity [if that's a word]; it doesn't show the little snap tool tip).

Argh, This should be soooo simple! ~ok, i'm finished venting now; It IS Friday, right?

Thanks,

Tim Creary

rad.77676
2006-02-18, 02:30 AM
I don't believe it matters but I reset OSMODE before the entmake.
Try this:

(defun c:dev1 (/ pt1 pt2)
(setvar "osmode" 256)
(setq pt1 (getpoint "nFirst Point: ")
pt2 (getpoint pt1 "nSecond Point: ")
)
(setvar "osmode" 0)
(new-line1)
(princ)
)

(defun new-line1 ()
(entmake (list (cons 0 "LINE")
(cons 8 "newline")
(cons 62 30)
(cons 10 (list (car pt1) (cadr pt1)))
(cons 11 (list (car pt2) (cadr pt2)))
)
)
)

.T.
2006-02-18, 02:41 AM
It still works for you?


Thanks,

Tim Creary

rad.77676
2006-02-18, 02:43 AM
Tim,
I don't seem to have any problem with this, I can take a closer look at it tomorrow, or monday.
After looking at that drawing a little closer, I realized you aren't using the code I posted, try it!
Rob

.T.
2006-02-18, 03:02 AM
Thanks, Rob.

Yes, I did try your code, and I got the same result. My ego isn't big enough to keep me from using someone else's code if mine isn't working.:) Especially if it's better than mine. ;) I must be running with some system variable out of whack or something. I'm going to try it on another machine.

I have a fresh install on a new computer, so there shouldn't be any question there (I hope).

Have a great weekend, and thanks for your help!
Tim Creary

.T.
2006-02-18, 03:29 AM
Hey Rob,

Uh oh. Looking at the drawing in your post, I see you ARE getting basically the same result as I am.

Yes, it does the second tan just fine (most of the time, I've had a couple that choked), but it is the first pick that I'm having problems with. Sorry, maybe I wasn't clear.

Basically I'm trying to draw a line tangent to the first circle AND tangent to the second circle. This is very doable just using the line command and having osnap set to tan, or using tan as a snap directly (typing tan before picking each point). I'm just at a loss as to how to get there from here in lisp seeing that the code doesn't do this as written.

I have attached another drawing showing the desired result...

Thanks,

Tim Creary

kennet.sjoberg
2006-02-18, 05:24 PM
Hi Tim !

I do not think this will work at all with _tan and getpoint.
When you use getpoint to take a single point it is locked to a specific point before you use getpoint again
and the second getpoint should give the first getpoint a direction and location.

Here is my attempt to save pt1 and pt2 but I failed
pt2 is trapped OK, but not pt1, I do not know what kind of calculated point that is.

But the command do work and you can try to find pt1 in any way if you like.

(defun c:dev3 (/ pt1 pt2 )
(command "line" )
(while
(cond
((and (= 1 (logand (getvar "CMDACTIVE" ) 1 )) (not pt1 )) (command "_tan" PAUSE ) (setq pt1 (getvar "LASTPOINT" )) )
((and (= 1 (logand (getvar "CMDACTIVE" ) 1 )) (not pt2 )) (command "_tan" PAUSE ) (setq pt2 (getvar "LASTPOINT" )) )
((and pt1 pt2 ) (command "" ) )
(t nil)
)
)
(princ)
)


: ) Happy Computing !

kennet

.T.
2006-02-20, 07:11 PM
Thanks Kennet,

Actually, I can make your code do what I want to do. It just seems that it should be easier. It certainly helped to have a fresh pair of eyes!;) My forehead is sore! :banghead:

Do you think it would be a valid wish list item to have deferred tan (and deferred perp, probably, but I haven't tested it) work with getpoint? I wonder if it is even possible.

Thanks,

Tim Creary

kennet.sjoberg
2006-02-20, 07:26 PM
Thanks Kennet,

Actually, I can make your code do what I want to do. It just seems that it should be easier.My attempt is to trapp pt1 and pt2 in the fly, not to draw a simple line ;)

Do you think it would be a valid wish list item to have deferred tan . . . . work with getpoint?. . . The wish is free ;)

: ) Happy Computing !

kennet

.T.
2006-02-20, 07:44 PM
My attempt is to trapp pt1 and pt2 in the fly, not to draw a simple line ;)

BUT, you were able to give me that line, which I can extract the two points from, then entdel it!8)

I was banging my head against the wall with the idea of "This stupid thing should work" so hard that I failed to remember that, in lisp, as in life, there are generally several ways to produce the same result.


The wish is free ;)

But is it worthy?;)

Thanks,

Tim Creary

kennet.sjoberg
2006-02-20, 07:56 PM
BUT, you were able to give me that line, which I can extract the two points from, then entdel it!8)
ha, I was writing this

; Afterwards you can trap pt1 and pt2 from the new created line, and than delete it
(defun c:dev4 (/ LastEnt pt1 pt2 )
(setq LastEnt (entlast) )
(command "line" "_tan" PAUSE "_tan" PAUSE "" )
(if (not (eq LastEnt (entlast)) )
(progn
(setq pt1 (cdr (assoc 10 (entget (entlast)))) )
(setq pt2 (cdr (assoc 11 (entget (entlast)))) )
(command "._erase" (entlast) "" )
)
(princ "No new object created" )
)
(princ)
)

But is it worthy?;) Probably not.

: ) Happy Computing !

kennet

Opie
2006-02-20, 08:14 PM
BUT, you were able to give me that line, which I can extract the two points from, then entdel it!8)

I was banging my head against the wall with the idea of "This stupid thing should work" so hard that I failed to remember that, in lisp, as in life, there are generally several ways to produce the same result.


But is it worthy?;)

Thanks,

Tim Creary
Tim,

You can submit the wish (http://www.augi.com/autocad/submitwish.asp) and let the review team decide if it is worthy. ;)

.T.
2006-02-20, 08:57 PM
OK, done; Its' probably worth a few lines of code, we'll see what happens 8)

Tim Creary

Opie
2006-02-20, 09:58 PM
OK, done; Its' probably worth a few lines of code, we'll see what happens 8)

Tim Creary
I'll see what I can do to get it placed on the ballot (just not the current one (http://www.augi.com/autocad/ballot.asp))

CAB2k
2006-02-20, 11:45 PM
I had good luck with this but it may not suit your needs using NEAR.
(defun c:dev3 (/ pt1 pt2 osm)
(setq osm (getvar "osmode"))
(setvar "osmode" 512)
(setq pt1 (getpoint "nFirst Point: ")
pt2 (getpoint pt1 "nSecond Point: ")
)
(command "line" "tan" pt1 "tan" pt2 "")
(setvar "osmode" osm)
(princ)
)

.T.
2006-02-21, 12:06 AM
Thanks, CAB.

I'll have to experiment with it in the environment.8-)

You gave me an idea, also: maybe using the cdr of entsel...

Thanks,

Tim Creary

.T.
2006-02-21, 12:26 AM
Nope, the cdr of entsel isn't going to work :(

The point returned isn't on the entity; it's the point where the user clicks to select the entity.

Tim Creary

CAB2k
2006-02-21, 09:03 PM
(defun c:test (/ ent obj p1)
(and
(setq ent (entsel "\nSelect an object:"))
(setq obj (vlax-ename->vla-object (car ent))
p1 (vlax-curve-getclosestpointto obj (cadr ent) t)
)
)
p1
)

And from your example
(defun c:test (/ ent obj p1)
(and
(setq ent (entsel "\nSelect an object:"))
(setq p1 (osnap (cadr ent) "nea"))
)
p1
)