Author Topic: Calculation  (Read 2608 times)

0 Members and 1 Guest are viewing this topic.

Atwist

  • Guest
Calculation
« on: June 17, 2010, 02:11:59 AM »
Hello forummebers,

I would like a screen with input calculation items.
Then this insert as text item .
Example
Area  x pressure = max load

Is this possible?

Sorry for my bad english

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Calculation
« Reply #1 on: June 17, 2010, 03:12:29 AM »
try to use TABLE
see attached

Atwist

  • Guest
Re: Calculation
« Reply #2 on: June 17, 2010, 04:35:21 AM »
HasanCad,

Thanks for answer.

This is no option for my Il have the calculation white text insert the drawing

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Calculation
« Reply #3 on: June 17, 2010, 05:22:31 AM »
Please upload a sample file.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Calculation
« Reply #4 on: June 17, 2010, 09:18:02 AM »
A simple solution, No error checking!
Code: [Select]
(defun c:test (/ area pres force pt ent)
  (if
    (and
      (setq area (getint "\nEnter the Area: "))
      (setq pres (getint "\nEnter the Pressure: "))
      (setq force (* area pres))
      (setq pt (getpoint "\nSpecify the text location."))
      (setq ent (entmakex
                  (list '(0 . "TEXT")
                        (cons 10 pt)
                        ;(cons 40 1)
                        (cons 7 (getvar "TEXTSTYLE"))
                        (cons 1 (vl-princ-to-string force))
                  )
                )
      )
    )
  (princ "\nText Created")
  (princ "\n<!> No Text Specified <!>")
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

fixo

  • Guest
Re: Calculation
« Reply #5 on: June 17, 2010, 11:50:21 AM »
CAB beat me for that :)

Code: [Select]
(defun c:test (/ area press force pt ent)
  (if
    (and
      (setq area (getreal "\nEnter the Area: "))
      (setq press (getreal "\nEnter the Pressure: "))
      (setq force (* area press))
      (setq pt (getpoint "\nSpecify the text location."))
      (setq ent (entmakex
                  (list (cons 0 "TEXT")
                        (cons 10 pt)
                        (cons 40 (if (zerop (getvar "TEXTSIZE")) 2.0 (getvar "TEXTSIZE")))
                        (cons 7 (getvar "TEXTSTYLE"))
                        (cons 1 (strcat (rtos area 2 3) " x " (rtos press 2 3) " = " (rtos force 2 3)))
                  )
                )
      )
    )
  (princ "\nText Created")
  (princ "\n<!> No Text Specified <!>")
  )
  (princ)
)

~'J'~

Atwist

  • Guest
Re: Calculation
« Reply #6 on: June 17, 2010, 02:47:48 PM »
Cab & fixo,

Il have this error
Code: [Select]
test.lsp successfully loaded.
Command: ; error: bad argument type: numberp: nil
Command: ; error: bad argument type: numberp: nil
Command:

Whats is wrong


fixo

  • Guest
Re: Calculation
« Reply #7 on: June 17, 2010, 04:38:02 PM »
Working good for me

Code: [Select]
Command: appload
areatext.LSP successfully loaded.
Command:
Command:
Command: test
Enter the Area: 100.05
Enter the Pressure: 2.89
Specify the text location.
Text Created

~'J'~

efernal

  • Bull Frog
  • Posts: 206
Re: Calculation
« Reply #8 on: June 17, 2010, 04:55:10 PM »
another code...
e.fernal

Code: [Select]
;|
/* DIALOG FILE */

dialogo:dialog{label="Area x Pressure";width=36;fixed_width=true;
:spacer{height=0.5;}
:row{alignment=centered;fixed_width=true;
:column{
:text{label="Area";}
:edit_box{edit_width=12;key="area";action="(CALCULATE_AREA_PRESSURE)";}}
:column{
:text{label="Pressure";}
:edit_box{edit_width=12;key="pressure";action="(CALCULATE_AREA_PRESSURE)";}}}
:text{label="";key="result";alignment=centered;width=28;fixed_width_font=true;}
:spacer{height=0.5;}
ok_only;}

|;

(DEFUN c:apr (/ dh ar pr re CALCULATE_AREA_PRESSURE)
  ;; ***********************************************
  (DEFUN calculate_area_pressure ()
    (SETQ ar (ATOF (GET_TILE "area"))
          pr (ATOF (GET_TILE "pressure"))
          re (* ar pr)
    )
    (SET_TILE "result" (STRCAT "Result = " (RTOS re 2 4)))
  )
  ;; ***********************************************
  (IF (> (SETQ dh (LOAD_DIALOG "dialogo.dcl")) 0)
    (IF (NEW_DIALOG "dialogo" dh)
      (PROGN
        (set_tile "result" "Type and press ENTER")
        (START_DIALOG)
        (UNLOAD_DIALOG dh)
        (IF re
          (IF (SETQ p1 (GETPOINT "\n-> Insertion point : "))
            (ENTMAKE
              (LIST
                (CONS 0 "TEXT")
                (CONS 1 (STRCAT (RTOS ar 2 4) "x" (RTOS pr 2 4) "=" (RTOS (* ar pr) 2 4)))
                (CONS 10 p1)
                (CONS 40 (GETVAR "TEXTSIZE")) ; change if desired, EXAMPLE (cons 40 15.0)
                (CONS 50 0.0)
              )
            )
          )
        )
      )
      nil
    )
    (ALERT "Error:\n\n\tUnable to load dialog!\t\n\n")
  )
  (PRINC)
)

[edit:kdub:codeTagsAdded]
« Last Edit: June 17, 2010, 07:53:05 PM by Kerry Brown »
e.fernal

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Calculation
« Reply #9 on: June 17, 2010, 05:06:04 PM »

Atwist

  • Guest
Re: Calculation
« Reply #10 on: June 18, 2010, 11:46:00 AM »
hello,
 I'm stuck, I created the following using http://web2.airmail.net/terrycad/Tutorials/MyDialogs.htm
 Dialog is good but I do not know how to calculation and how I put this in the drawing.

The calculation shall then be in a text block

Sorry for my bad english
« Last Edit: June 18, 2010, 12:04:37 PM by Atwist »

fixo

  • Guest
Re: Calculation
« Reply #11 on: June 19, 2010, 08:04:41 AM »
I'm not sure about I've used right formula
because of don't understand what you exactly mean
Better yet attach a picture with resulting text

Say,

Cilinder diameter = 10.0

Werkdruk =5.0

What is the text should on screen?

Code: [Select]

(defun edit_action (val why)
  (if (or (= why 1) (= why 2))
    (set_tile  "Edit3" val)
  )
)

(defun c:cil (/ Dcl_Id% Edit1$ Edit2$ Edit3$ Return#)
 
  (princ "\n  >>  cil")
  (princ)
  ; Set Default Variables
  (if (not *cil@)   ;Unique global variable name to store dialog info
    (setq *cil@ (list nil "" "" ""))
    )   ;if
  (setq Edit1$ (nth 1 *cil@)
Edit2$ (nth 2 *cil@)
Edit3$ (nth 3 *cil@)
)   ;setq
  ; Load Dialog
  (setq Dcl_Id% (load_dialog "cil.dcl"))
  (new_dialog "cil" Dcl_Id%)
  ; Set Dialog Initial Settings
  (set_tile "Title" "Cilinder berekening")
  (set_tile "Text1" "Cilinder diameter")
  (set_tile "Edit1" Edit1$)
  (set_tile "Text2" "Werkdruk");;pressure
  (set_tile "Edit2" Edit2$)
  (set_tile "Text3" "Diameter zuigerstang") ;;stiffners diameter
  (set_tile "Edit3" Edit3$)
  ; Dialog Actions
  (action_tile "Edit1" "(setq Edit1$ $value)")
  (action_tile
    "Edit2"
    (strcat
      "(progn "
      "(setq Edit2$ $value)"
      "(edit_action (rtos (/ (atof Edit2$) (/ (* pi (expt (atof Edit1$) 2)) 4) ) 2 3) $reason)"
      "(mode_tile \"\" 2))"))

  (action_tile
    "accept"
    (strcat "(progn "
    "(setq Edit1$ (get_tile \"Edit1\"))"
    "(setq Edit2$ (get_tile \"Edit2\"))"
    "(setq Edit3$ (get_tile \"Edit3\"))"
    "(done_dialog 777))"))
  (setq Return# (start_dialog))
  ; Unload Dialog
  (unload_dialog Dcl_Id%)
  (if (= 777 Return#)
    (progn
      (setq pt (getpoint "\n >> Pick insertion point of text >>"))
      (entmakex (list (cons 0 "TEXT")
      (cons 10 pt)
      (cons 40
    (if (zerop (getvar "TEXTSIZE"))
      2.0;<--- default text size, change to suit
      (getvar "TEXTSIZE"))
    )
      (cons 1
    (strcat (rtos (atof Edit2$) 2 3)
    " / "
    (rtos (/ (* pi (expt (atof Edit1$) 2)) 4)2 3)
    " = "
    (rtos (atof Edit3$) 2 4)))
      )
)
      )
    )
  (setq *cil@ (list nil Edit1$ Edit2$ Edit3$))
  (princ)
);defun c:cil

~'J'~

Atwist

  • Guest
Re: Calculation
« Reply #12 on: June 21, 2010, 05:11:15 AM »
Hello Fixo,

Thanks for answer

Its don't works.
Code: [Select]
cil.lsp successfully loaded.
Command: ; error: malformed list on input
Command: ; error: malformed list on input
Command:

But il have the XL lisp from JPsanders. and that works for my oké

Thanks

fixo

  • Guest
Re: Calculation
« Reply #13 on: June 21, 2010, 06:37:20 AM »
Hello Fixo,

Thanks for answer

Its don't works.
Code: [Select]
cil.lsp successfully loaded.
Command: ; error: malformed list on input
Command: ; error: malformed list on input
Command:

But il have the XL lisp from JPsanders. and that works for my oké

Thanks
:pissed:
I just copied my code from the thread above and
it works nice on my machine:

Code: [Select]
Command: appload
cil.lsp successfully loaded.
Command:
Command:
Command: cil
  >>  cil
 >> Pick insertion point of text >>
Forgot to say, after you'll enter value into "Werkdrug" box you
need to press Enter to calculate data in the last box

~'J'~