Jump to content

Autolisp to draw elbow 45


Tharwat

Recommended Posts

Hello Mr.Buzzard,

 

I have wrote tow different Autolisp files that are dealing with our main issue

which is (polar function) and here they are attached - downstairs :D- within this Message.

 

So which one of them is the perfect Autolisp file that dealing with polar although, both of them are giving the same result withno mistakes.

 

May I know your opinion about them please?

 

with all my respects.

Tharwat

Hi Tharwat,

 

I assume that both programs were to draw the same type bracket if supplied the same length information for A and B. It would seem to me one of them is a bit mixed up. My guess is that bracket2 is making the bracket correctly while bracket1 seem to make the bracket sort of twisted. You should recheck the calculations in bracket1.lsp (See image below.)

 

One thing for certain is you are starting to get an understanding using for the polar calculations using the degree to radian function very good.

 

One additional thing I noticed is the command call using language compatibility needs some adjustment.

 

You have this in bracket2:

(command "._pline" pt1 [color="Red"]"w"[/color] 0 "" pt2 pt3 pt4 pt5 pt6 [color="red"]"c"[/color])

 

It should look like this:

(command "._pline" pt1 [color="red"]"_w"[/color] 0 "" pt2 pt3 pt4 pt5 pt6 [color="red"]"_c"[/color])

 

You need to use an underscore for the sub-commands as well.

 

For a small routine you are getting idea. Keep up the good work.

 

I was wondering if using the degree to radian was any easier for you.

Document1.jpg

Link to comment
Share on other sites

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    30

  • Tharwat

    15

  • Lee Mac

    7

  • Tankman

    3

Top Posters In This Topic

Posted Images

Ok,

 

I looked over both codes more thoroughly and here is what I found to be the problem. The length variables in bracket1 seem to be mixed up or in the wrong place and does not match bracket2.

 

You had this in the calculations for bracket1:

(setq P2 (polar P1 0 A))
(setq P3 (polar P2 (/ pi 2) B))
(setq P4 (polar P3 pi C))
(setq P5 (polar P4 (/ pi 2) C))
(setq P6 (polar P5 pi B))

 

You had this in the calculations for bracket2:

  (setq pt2 (polar pt1 (dtr 0) a))
 (setq pt3 (polar pt2 (dtr 90) c))
 (setq pt4 (polar pt3 (dtr 180) b))
 (setq pt5 (polar pt4 (dtr 90) b))
 (setq pt6 (polar pt5 (dtr 180) c))

 

So bracket1 should look like this:

(setq P2 (polar P1 0 A))
(setq P3 (polar P2 (/ pi 2) C))
(setq P4 (polar P3 pi B))
(setq P5 (polar P4 (/ pi 2) B))
(setq P6 (polar P5 pi C))

Link to comment
Share on other sites

One final thing,

 

 

In bracket2 you have the degrees to radian function within the middle of your main function. The DTR is a function in its own right so keep it separate. It makes it less confusing.

 

Finally to answer your original question as to which method is better, I can only say its a matter of preference so you should know the answer to that. (Which method did you prefer?)

 

 

You had this:

(defun c:bracket2 (/ pt1 oldsnap oldortho newsnap newortho a b c pt2 pt3 pt4 pt5 pt6)
 (setq pt1 (getpoint"\n Specify lower corner point of Bracket: "))
 (setq oldsnap (getvar "osmode"))
 (setq oldortho (getvar "orthomode"))
 (setq newsnap (setvar "osmode" 0))
 (setq newortho (setvar "orthomode" 0))
[color="Red"]  (defun DTR (ang)(* pi (/ ang 180.0)))[/color]
 (setq a (getdist"\nLength of A: "))
 (setq b (getdist"\nLength of B:"))
 (setq c (- a b))
 (setq pt2 (polar pt1 (dtr 0) a))
 (setq pt3 (polar pt2 (dtr 90) c))
 (setq pt4 (polar pt3 (dtr 180) b))
 (setq pt5 (polar pt4 (dtr 90) b))
 (setq pt6 (polar pt5 (dtr 180) c))
 (command "._pline" pt1 "_w" 0 "" pt2 pt3 pt4 pt5 pt6 "_c")
 (setvar "osmode" oldsnap)
 (setvar "orthomode" oldortho)
 (princ "Made by Tharwat")
 (princ)
 )

 

Make it like this:

(defun c:bracket2 (/ pt1 oldsnap oldortho newsnap newortho a b c pt2 pt3 pt4 pt5 pt6)
 (setq pt1 (getpoint"\n Specify lower corner point of Bracket: "))
 (setq oldsnap (getvar "osmode"))
 (setq oldortho (getvar "orthomode"))
 (setq newsnap (setvar "osmode" 0))
 (setq newortho (setvar "orthomode" 0))
 (setq a (getdist"\nLength of A: "))
 (setq b (getdist"\nLength of B:"))
 (setq c (- a b))
 (setq pt2 (polar pt1 (dtr 0) a))
 (setq pt3 (polar pt2 (dtr 90) c))
 (setq pt4 (polar pt3 (dtr 180) b))
 (setq pt5 (polar pt4 (dtr 90) b))
 (setq pt6 (polar pt5 (dtr 180) c))
 (command "._pline" pt1 "_w" 0 "" pt2 pt3 pt4 pt5 pt6 "_c")
 (setvar "osmode" oldsnap)
 (setvar "orthomode" oldortho)
 (princ "Made by Tharwat")
 (princ)
 )
 
[color="Red"](defun DTR (ang)(* pi (/ ang 180.0)))[/color]

Link to comment
Share on other sites

Hi Mr.Buzzard.

 

I do appreciate your hard work on my modest Lisps, and that was more than enough to get the perfect idea of them.

 

So by working and using different ways of sole functions, definitely that would show its hidden abilities clearer and welder which made me realize that using the (defun DTR (ang)(* pi (/ ang 180.0))) is really much easier and less confusion, due to direct input of the actual angle degree.

 

And the way that you have changed codes in Bracket1 is really fascinating and smart, because it will never give the chance to Autocad to make that small tow boxes or going somewhere else if we entered A:less than B:. .... thats more than great.

 

Many Thanks.

Tharwat

Link to comment
Share on other sites

Hi Mr.Buzzard.

 

I do appreciate your hard work on my modest Lisps, and that was more than enough to get the perfect idea of them.

 

So by working and using different ways of sole functions, definitely that would show its hidden abilities clearer and welder which made me realize that using the (defun DTR (ang)(* pi (/ ang 180.0))) is really much easier and less confusion, due to direct input of the actual angle degree.

 

And the way that you have changed codes in Bracket1 is really fascinating and smart, because it will never give the chance to Autocad to make that small tow boxes or going somewhere else if we entered A:less than B:. .... thats more than great.

 

Many Thanks.

Tharwat

Glad I could help, But I think you can see the value in it for yourself. Go with the method that you feel comfortable with.

Link to comment
Share on other sites

Hi Mr Buzzard,

I have noticed in your Lisp files that you are using (getkword) instead of (getdist) although that you are asking for measurements or distances as following;

(setq D::SYS$ (cond ((getkword (strcat"\nSpecify air system type. [<E>xhaust, <D>ust, <S>upply or <R>eturn] <"D::SYS$">: ")))(T D::SYS$)))

This way will prevent users to enter real numbers, things like 0.5 0.75 ...etc.

would you please indicate to me the function that saves user inputs for the second use of the command.

 

Last question, we can use (getvar "orthomode") to change the mode, So what is the use of polarmode ? and I tried "polarmode" but that was wrong.

 

Your sincerely

Tharwat

Link to comment
Share on other sites

That part of the code is asking for a System Type and requires the first letter of one of the four systems supplied in the code. It is not asking for a distance.

 

With HVAC System you have Supply and Return and then there is also Exhaust and Dust systems. Depending on with you select with control the Insulation tile which will not allow you to select insulation if Exhaust or Dust System is selected. This prevents the user from making an error since those two systems are not insulated.

 

With regard to the second part of you question concerning system variables below is from the ACAD Help Section:

 

POLARMODE

Controls settings for polar and object snap tracking. The value is the sum of four bitcodes:

Polar angle measurements

0 Measure polar angles based on current UCS (absolute)

1 Measure polar angles from selected objects (relative)

 

Object snap tracking

0 Track orthogonally only

2 Use polar tracking settings in object snap tracking

 

Use additional polar tracking angles

0 No

4 Yes

 

Acquire object snap tracking points

0 Acquire automatically

8 Press SHIFT to acquire

 

Orthomode

Constrains cursor movement to the perpendicular. When ORTHOMODE is turned on, the cursor can move only horizontally or vertically relative to the UCS and the current grid rotation angle.

0 Turns off Ortho mode

1 Turns on Ortho mode

Link to comment
Share on other sites

Sorry for choosing the wrong code;

(initget (+ 2 4))
 (setq D::WID1# (cond ((getint (strcat "\nSpecify elbow width. <"(itoa D::WID1#)">: ")))(T D::WID1#)))

 

This is the one (getint) instead of (getdist)

 

Tharwat

Link to comment
Share on other sites

Sorry for choosing the wrong code;

(initget (+ 2 4))
 (setq D::WID1# (cond ((getint (strcat "\nSpecify elbow width. <"(itoa D::WID1#)">: ")))(T D::WID1#)))

 

This is the one (getint) instead of (getdist)

 

Tharwat

On that one it is better to use an Integer value then a Real value. I did not want the user to enter odd type sizes.

 

 

getint

Pauses for user input of an integer, and returns that integer 

(getint [msg]) 

Values passed to getint can range from –32,768 to +32,767. If the user enters something other than an integer, getint displays the message, "Requires an integer value," and allows the user to try again. The user cannot enter another AutoLISP expression as the response to a getint request. 

Arguments 

msg 

A string to be displayed to prompt the user; if omitted, no message is displayed. 

Return Values 

The integer specified by the user; otherwise nil, if the user presses ENTER without entering an integer. 

Examples 

Command: (setq num (getint)) 

15 

15 

Command: (setq num (getint "Enter a number:")) 

Enter a number: 25 

25 

Command: (setq num (getint)) 

15.0 

Requires an integer value. 

15 

15 

 

 

getdist

Pauses for user input of a distance 

(getdist [pt] [msg]) 

The user can specify the distance by selecting two points, or by specifying just the second point, if a base point is provided. The user can also specify a distance by entering a number in the AutoCAD current distance units format. Although the current distance units format might be in feet and inches (architectural), the getdist function always returns the distance as a real. 

The getdist function draws a rubber-band line from the first point to the current crosshairs position to help the user visualize the distance. 

The user cannot enter another AutoLISP expression in response to a getdist request. 

Arguments 

pt 

A 2D or 3D point to be used as the base point in the current UCS. If pt is provided, the user is prompted for the second point. 

msg 

A string to be displayed to prompt the user. If no string is supplied, AutoCAD does not display a message. 

Return Values 

A real number. If a 3D point is provided, the returned value is a 3D distance. However, setting the 64 bit of the initget function instructs getdist to ignore the Z component of 3D points and to return a 2D distance. 

Examples 

(setq dist (getdist)) 
(setq dist (getdist '(1.0 3.5))) 
(setq dist (getdist "How far ")) 
(setq dist (getdist '(1.0 3.5) "How far? "))

Link to comment
Share on other sites

Hi Mr Buzzard,

I have noticed in your Lisp files that you are using (getkword) instead of (getdist) although that you are asking for measurements or distances as following;

(setq D::SYS$ (cond ((getkword (strcat"\nSpecify air system type. [<E>xhaust, <D>ust, <S>upply or <R>eturn] <"D::SYS$">: ")))(T D::SYS$)))

This way will prevent users to enter real numbers, things like 0.5 0.75 ...etc.

would you please indicate to me the function that saves user inputs for the second use of the command.

 

Last question, we can use (getvar "orthomode") to change the mode, So what is the use of polarmode ? and I tried "polarmode" but that was wrong.

 

Your sincerely

Tharwat

Tharwat,

 

It dawned on me you might be referring to OSMODE and not POLARMODE. Again from acad help section.

 

OSMODE

 

Type: Integer

Saved in: Registry

Initial value: 4133

 

Sets running Object Snap modes using the following bitcodes:

 

0 NONe

1 ENDpoint

2 MIDpoint

4 CENter

8 NODe

16 QUAdrant

32 INTersection

64 INSertion

128 PERpendicular

256 TANgent

512 NEArest

1024 QUIck

2048 APParent Intersection

4096 EXTension

8192 PARallel

 

To specify more than one object snap, enter the sum of their values. For example, entering 3 specifies the Endpoint (bitcode 1) and Midpoint (bitcode 2) object snaps. Entering 16383 specifies all object snaps.

 

When object snaps are switched off using the Osnap button on the status bar, a bitcode of 16384 (0x4000) is returned, in addition to the normal value of OSMODE. With this additional value, developers can write applications for AutoCAD, and distinguish this mode from Object Snap modes that have been turned off from within the Drafting Settings dialog box. Setting this bit toggles running object snaps off. Setting OSMODE to a value with this bit off toggles running object snaps on.

 

If you saved your Object Snaps at the beginning of your code, You can also do something like this to turn them on anywhere in your code:

(setvar "osmode" oldosmode)

This will turn on your saved Object Snap settings.

 

To turn them off, just do this:

(setvar "osmode" 0)

Link to comment
Share on other sites

Hi mr,Buzzard.

 

thats a very kind of you to follow up my question, thank you so much.

 

with reference to the polar mode question, I would like to inform you that your program (elbow 45.lsp) is turning polar mode off after invoking or drafting an elbow, so if I wanted to draw a simple line after drafting an elbow (by your Lisp Program), I should press button (F10) to turn on polar tracking.

 

That's why I wanted to know the Autolisp function that controlling polar tracking on and off.

 

I searched for that Lisp function and I found it as follows;

AUTOSNAP
Type: Integer 
Saved in: Registry 
Initial value: 63 

Controls the display of the AutoSnap marker, tooltip, and magnet. Also turns on polar and object snap tracking, and controls the display of polar tracking, object snap tracking, and Ortho mode tooltips. The setting is stored as a bitcode using the sum of the following values:

0 Turns off the AutoSnap marker, tooltips, and magnet. Also turns off polar tracking, object snap tracking, and tooltips for polar tracking, object snap tracking, and Ortho mode

1 Turns on the AutoSnap marker

2 Turns on the AutoSnap tooltips

4 Turns on the AutoSnap magnet

8 Turns on polar tracking

16 Turns on object snap tracking

32 Turns on tooltips for polar tracking, object snap tracking, and Ortho mode 

 

So this is the one that I wanted, although this function is really dangerous for unexpernieced people, due to the changes that might occur to the crosshair if Lisps Files used and not completely done properly.

 

your reply will be highly appreciated.

 

Tharwat

Link to comment
Share on other sites

Hi mr,Buzzard.

 

thats a very kind of you to follow up my question, thank you so much.

 

with reference to the polar mode question, I would like to inform you that your program (elbow 45.lsp) is turning polar mode off after invoking or drafting an elbow, so if I wanted to draw a simple line after drafting an elbow (by your Lisp Program), I should press button (F10) to turn on polar tracking.

 

That's why I wanted to know the Autolisp function that controlling polar tracking on and off.

 

I searched for that Lisp function and I found it as follows;

AUTOSNAP
Type: Integer 
Saved in: Registry 
Initial value: 63 

Controls the display of the AutoSnap marker, tooltip, and magnet. Also turns on polar and object snap tracking, and controls the display of polar tracking, object snap tracking, and Ortho mode tooltips. The setting is stored as a bitcode using the sum of the following values:

0 Turns off the AutoSnap marker, tooltips, and magnet. Also turns off polar tracking, object snap tracking, and tooltips for polar tracking, object snap tracking, and Ortho mode

1 Turns on the AutoSnap marker

2 Turns on the AutoSnap tooltips

4 Turns on the AutoSnap magnet

8 Turns on polar tracking

16 Turns on object snap tracking

32 Turns on tooltips for polar tracking, object snap tracking, and Ortho mode 

 

So this is the one that I wanted, although this function is really dangerous for unexpernieced people, due to the changes that might occur to the crosshair if Lisps Files used and not completely done properly.

 

your reply will be highly appreciated.

 

Tharwat

Tharwat,

 

The program is not turn off Polarmode. It not calling polarmode to start with.

There is no polarmode in the program. Please be clear about what you mean.

Link to comment
Share on other sites

Hi mr,Buzzard.

 

thats a very kind of you to follow up my question, thank you so much.

 

with reference to the polar mode question, I would like to inform you that your program (elbow 45.lsp) is turning polar mode off after invoking or drafting an elbow, so if I wanted to draw a simple line after drafting an elbow (by your Lisp Program), I should press button (F10) to turn on polar tracking.

 

That's why I wanted to know the Autolisp function that controlling polar tracking on and off.

 

I searched for that Lisp function and I found it as follows;

AUTOSNAP
Type: Integer 
Saved in: Registry 
Initial value: 63 

Controls the display of the AutoSnap marker, tooltip, and magnet. Also turns on polar and object snap tracking, and controls the display of polar tracking, object snap tracking, and Ortho mode tooltips. The setting is stored as a bitcode using the sum of the following values:

0 Turns off the AutoSnap marker, tooltips, and magnet. Also turns off polar tracking, object snap tracking, and tooltips for polar tracking, object snap tracking, and Ortho mode

1 Turns on the AutoSnap marker

2 Turns on the AutoSnap tooltips

4 Turns on the AutoSnap magnet

8 Turns on polar tracking

16 Turns on object snap tracking

32 Turns on tooltips for polar tracking, object snap tracking, and Ortho mode 

 

So this is the one that I wanted, although this function is really dangerous for unexpernieced people, due to the changes that might occur to the crosshair if Lisps Files used and not completely done properly.

 

your reply will be highly appreciated.

 

Tharwat

Tharwat,

 

The program has nothing to do with polarmode. Its not saving, setting or changing polarmode. Please be clear as to what you mean.

 

 

The following is what I have it doing:

Saving

  (setq SUS_LIST '("cmdecho" "orthomode" "osmode" "blipmode" "angbase" "angdir" "clayer") 

 

Changing

  (setq CPS (list 0 1 0 0 0 0))
 (mapcar (function setvar)(list "cmdecho" "orthomode" "osmode" "blipmode" "angbase" "angdir") CPS) 

 

Before the insertion point:

(setvar "osmode" (nth 2 SUS))

 

Before the pline command call:

(setvar "osmode" (nth 2 CPS))

 

Restoring

(defun RUS ()
 (setq *error* TERR)
 (if SUS (mapcar 'setvar SUS_LIST SUS))
 (princ "\nProgram has restored the user settings.")
 (princ)) 

 

No polarmode there.

 

If you added anything else after I posted, Then check what you are doing.

Link to comment
Share on other sites

The only program I found has a quirk with Object Snap is ELB45.lsp

It is turning off the snaps but they were never saved at the start.

 

Attached is the fix for that program.

 

I hope thats what you mean. Again none of these programs are doing anything to polarmode.

 

I run all these programs and polar tracking works in every one of them after running each program.

ELB45.zip

Link to comment
Share on other sites

Mr.Buzzard,

 

I did not know that my point will make you angry.

 

What I meant is that not the polar mode it self either. I meant when we invoke the Elbow command that normally will turn the Orthomode on and off .So that will automatically turn off polar tracking, And as you know returning othromode on will not turn on polar tracking back again unless we make it manually. So that is not a big issue but that gave the oppertunity to look for polar tracking function as well.

 

Discussing matters deeply does not mean commenting to me.

 

With all my respects.

Tharwat

Link to comment
Share on other sites

Mr.Buzzard,

 

I did not know that my point will make you angry.

 

What I meant is that not the polar mode it self either. I meant when we invoke the Elbow command that normally will turn the Orthomode on and off .So that will automatically turn off polar tracking, And as you know returning othromode on will not turn on polar tracking back again unless we make it manually. So that is not a big issue but that gave the oppertunity to look for polar tracking function as well.

 

Discussing matters deeply does not mean commenting to me.

 

With all my respects.

Tharwat

I am not annoyed, But you are blaming the program for something you are doing manually.

 

I am only ensuring that Orthomode is on. I am not turning off orthomode. Anything that is being changed in the the program is being restored. I do not understand the problem here.

If you are manually shutting off things, Why are you blaming the program. If you do not want orthomode on, Then remove it.

 

So far you have brought up polarmode, orthomode, and autosnap referring to all of these.

I am having a hard time trying to understand what you mean.

Link to comment
Share on other sites

The attached is adjusting polarmode. Try it out.

 

The setting in red is what you should adjust. I do not know what setting you prefer. You will have to decide.

 

  (setq CPS (list 0 1 0 0 0 0 [color="Red"]2[/color]))
 (mapcar (function setvar)(list "cmdecho" "orthomode" "osmode" "blipmode" "angbase" "angdir" "polarmode") CPS)  

 

POLARMODE

Type: Integer

Saved in: Registry

Initial value: 0

 

Controls settings for polar and object snap tracking. The value is the sum of four bitcodes:

 

Polar angle measurements

0 Measure polar angles based on current UCS (absolute)

1 Measure polar angles from selected objects (relative)

 

Object snap tracking

0 Track orthogonally only

2 Use polar tracking settings in object snap tracking

 

Use additional polar tracking angles

0 No

4 Yes

 

Acquire object snap tracking points

0 Acquire automatically

8 Press SHIFT to acquire

 

If this is not what you mean, Then turn off orthomode. Set this number in red to 0.

(setq CPS (list 0 [color="Red"]0[/color] 0 0 0 0 2))
 (mapcar (function setvar)(list "cmdecho" "orthomode" "osmode" "blipmode" "angbase" "angdir" "polarmode") CPS)

 

See attached code below.

ELB.lsp

Link to comment
Share on other sites

  • 6 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...