Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP & Osnaps

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
282 Views, 4 Replies

LISP & Osnaps

I wrote a program to make a duct transition from rectangular to round (in 2D). The user is prompted to select the two endpoints of the rectangular duct and then the two endpoints of the round duct. Then it should draw the required lines based on the four points. I didn't do anything with the OSMODE because I wanted to use my regular snaps to select the endpoint of the line. When I run the program the result is different depending on the characteristics of the lines that I take the endpoints of. For example, if I have two lines representing each end of the transition and pick the two endpoints of the one line and then the two endpoints of the other line it draws the transition incorrectly. However, if I draw four lines representing each side of the ends of the two ducts with the transition in the same place I get the correct result. I'm guessing it has something to do with the OSMODE stuff. Any suggestions? Here is the code. I am also attaching a clip of the two different issues.

(defun *error* (msg)
(princ msg)
(princ)
)

;;This program creates a rectangular to round transition
(defun c:rect2rnd4 ()
;;Define the points for the rectangular end of the transition
(setq ptl1 (getpoint "\nSelect first rectangular point"))
(setq ptl2 (getpoint "\nSelect second rectangular point"))
;;Define the points for the round end of the transition
(setq ptl3 (getpoint "\nSelect the first round point"))
(setq ptl4 (getpoint "\nSelect the second round point"))
;;Define the angle of the ductwork
(setq theta1 (angle ptl2 ptl1))
(setq theta2 (angle ptl4 ptl3))
;;Determine the round duct diameter
(setq rounddia (distance ptl3 ptl4))
(setq rectwidth (distance ptl1 ptl2))

(If (>= theta1 pi)
(progn
(setq theta1 (- theta1 pi))
(setq pttemp ptl1)
(setq ptl1 ptl2)
(setq ptl2 pttemp)
)
)
(If (>= theta2 pi)
(progn
(setq theta2 (- theta2 pi))
(setq pttemp ptl3)
(setq ptl3 ptl4)
(setq ptl4 pttemp)
)
)

;;Create the transition
(command "_pline"
(polar ptl4 theta2 (* rounddia 0.75))
"_w" 0 0
ptl1
(polar ptl4 theta2 (* rounddia 0.5))
ptl2
(polar ptl4 theta2 (* rounddia 0.25))
""
)
(princ)
)
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

In the command function, use "_Non" before any input for points.

(command "._pline" "_non"
(polar ptl4 theta2 (* rounddia 0.75))
"_w" 0 0
"_non" ptl1


--
R. Robert Bell


wrote in message news:5374369@discussion.autodesk.com...
I wrote a program to make a duct transition from rectangular to round (in
2D). The user is prompted to select the two endpoints of the rectangular
duct and then the two endpoints of the round duct. Then it should draw the
required lines based on the four points. I didn't do anything with the
OSMODE because I wanted to use my regular snaps to select the endpoint of
the line. When I run the program the result is different depending on the
characteristics of the lines that I take the en
dpoints of. For example, if I have two lines representing each end of the
transition and pick the two endpoints of the one line and then the two
endpoints of the other line it draws the transition incorrectly. However,
if I draw four lines representing each side of the ends of the two ducts
with the transition in the same place I get the correct result. I'm
guessing it has something to do with the OSMODE stuff. Any suggestions?
Here is the code. I am also attaching a clip of the
two different issues.

(defun *error* (msg)
(princ msg)
(princ)
)

;;This program creates a rectangular to round transition
(defun c:rect2rnd4 ()
;;Define the points for the rectangular end of the transition
(setq ptl1 (getpoint "\nSelect first rectangular point"))
(setq ptl2 (getpoint "\nSelect second rectangular point"))
;;Define the points for the round end of the transition
(setq ptl3 (getpoint "\nSelect the first round point"))
(setq ptl4 (getpoint "\nSelect the second round point"))

;;Define the angle of the ductwork
(setq theta1 (angle ptl2 ptl1))
(setq theta2 (angle ptl4 ptl3))
;;Determine the round duct diameter
(setq rounddia (distance ptl3 ptl4))
(setq rectwidth (distance ptl1 ptl2))

(If (>= theta1 pi)
(progn
(setq theta1 (- theta1 pi))
(setq pttemp ptl1)
(setq ptl1 ptl2)
(setq ptl2 pttemp)
)
)
(If (>= theta2 pi)
(progn
(setq theta2 (- theta2 pi))
(setq pttemp ptl3)
(setq ptl3 ptl4)
(setq ptl4 pttemp)
)
)

;;Create
the transition
(command "_pline"
(polar ptl4 theta2 (* rounddia 0.75))
"_w" 0 0
ptl1
(polar ptl4 theta2 (* rounddia 0.5))
ptl2
(polar ptl4 theta2 (* rounddia 0.25))
""
)
(princ)
)
Message 3 of 5
Anonymous
in reply to: Anonymous

Yes, it probably does, and what it would do wrong would depend on which
Osnap modes you have running. In the left drawing, the points it calculates
at intermediate places along the width of the circular end are going to
osnap to the end or mid (or whatever you have on) of the pre-existing line
you selected the endpoints of. But in the right example, there's no line
there, so there's nothing to osnap to (unless there's something else in the
neighborhood when you do this in an actual drawing). Osnap modes won't
affect the routine's calculation of the various points, only the result of
osnap applied to them in the process of its drawing something.

In addition to Bob's suggestion, another easy thing is to turn off running
Osnap anywhere after the four points are selected and before the Pline
command function. The simplest way to do that would be something like:

(setvar "osmode" 0)

But if you want to restore them afterwards, you should precede that with
something like:

(setq osmodes (getvar "osmode"))

to save whatever the setting is before you turn it off, and after the
transition is drawn, restore it with something like:

(setvar "osmode" osmodes)

There are other ways to do it, too (look into the lisp 'osnap' function with
'non' applied through it, or look at the 16384 bitcode in the Osmode System
Variable, which you can add to the current value instead of setting it to
zero), but this is pretty common (you'll find similar code in lots of
examples on the Newsgroup).
--
Kent Cooper


wrote...
I wrote a program to make a duct transition from rectangular to round (in
2D). The user is prompted to select the two endpoints of the rectangular
duct and then the two endpoints of the round duct. Then it should draw the
required lines based on the four points. I didn't do anything with the
OSMODE because I wanted to use my regular snaps to select the endpoint of
the line. When I run the program the result is different depending on the
characteristics of the lines that I take the en
dpoints of. For example, if I have two lines representing each end of the
transition and pick the two endpoints of the one line and then the two
endpoints of the other line it draws the transition incorrectly. However,
if I draw four lines representing each side of the ends of the two ducts
with the transition in the same place I get the correct result. I'm
guessing it has something to do with the OSMODE stuff. Any suggestions?
Here is the code. I am also attaching a clip of the
two different issues.

(defun *error* (msg)
(princ msg)
(princ)
)

;;This program creates a rectangular to round transition
(defun c:rect2rnd4 ()
;;Define the points for the rectangular end of the transition
(setq ptl1 (getpoint "\nSelect first rectangular point"))
(setq ptl2 (getpoint "\nSelect second rectangular point"))
;;Define the points for the round end of the transition
(setq ptl3 (getpoint "\nSelect the first round point"))
(setq ptl4 (getpoint "\nSelect the second round point"))

;;Define the angle of the ductwork
(setq theta1 (angle ptl2 ptl1))
(setq theta2 (angle ptl4 ptl3))
;;Determine the round duct diameter
(setq rounddia (distance ptl3 ptl4))
(setq rectwidth (distance ptl1 ptl2))

(If (>= theta1 pi)
(progn
(setq theta1 (- theta1 pi))
(setq pttemp ptl1)
(setq ptl1 ptl2)
(setq ptl2 pttemp)
)
)
(If (>= theta2 pi)
(progn
(setq theta2 (- theta2 pi))
(setq pttemp ptl3)
(setq ptl3 ptl4)
(setq ptl4 pttemp)
)
)

;;Create
the transition
(command "_pline"
(polar ptl4 theta2 (* rounddia 0.75))
"_w" 0 0
ptl1
(polar ptl4 theta2 (* rounddia 0.5))
ptl2
(polar ptl4 theta2 (* rounddia 0.25))
""
)
(princ)
)
Message 4 of 5
Anonymous
in reply to: Anonymous

Thanks! I tried setting the osmode to 0 after I selected the points and before I executed the line command and it works great now. That seemed a little quicker and easier to add things to the program in the future than adding "_non". I appreciate both of your feedback though. Thanks!
Message 5 of 5
Anonymous
in reply to: Anonymous

I do sometimes find the insertion of "none" into a routine at point
selection to be the best way, but usually only for single points. If you
know you're going to want it off for a series of point selections, turning
Osnap off altogether (even if only temporarily) seems easier.
--
Kent Cooper


wrote...
Thanks! I tried setting the osmode to 0 after I selected the points and
before I executed the line command and it works great now. That seemed a
little quicker and easier to add things to the program in the future than
adding "_non". I appreciate both of your feedback though. Thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost