trying to do a lisp routine- help

Discussion in 'AutoCAD' started by mdsc, Oct 19, 2005.

  1. mdsc

    mdsc Guest

    I want to make a quick lisp routine that will take the cubic inches from a
    massprop command and calculate weight (lbs and kgs) from that. Anyone have
    a quick solution? Thanks.
     
    mdsc, Oct 19, 2005
    #1
  2. Show us the code you've got so far.
     
    Michael Bulatovich, Oct 19, 2005
    #2
  3. mdsc

    mdsc Guest

    LISP ROUTINE IS:

    (defun c:conv (/ input1 matx output)

    (setq dcl_id (load_dialog "conv1"))

    (new_dialog "conv1" dcl_id)



    (action_tile "cubin" "(do_cubin)")

    (action_tile "accept" "(done_dialog)")

    (action_tile "cancel" "(done_dialog) (cuberr)")





    (defun do_cubin ()

    (setq cubin1 (get_tile "cubin"))

    )

    (start_dialog)



    (setq output (* do_cubin 0.28355))

    (unload_dialog dcl_id)

    (princ "\nWeight in pounds is : " output)

    )



    DIALOG BOX IS:

    dcl_settings : default_dcl_settings {audit_level = 0;}

    conv1 : dialog

    {

    label = " converter";

    width = 40;

    spacer_1;

    : text {

    label = " Enter the cubic centimeters: ";

    width = 40;

    }

    : boxed_column

    {

    fixed_width = true;

    width = 17;

    alignment = centered;

    : edit_box {

    label = "cubic-centimeters:";

    key = "spout";

    mnemonic = "D";

    edit_width = 5;

    }

    }

    spacer_1;

    : text {

    label = " Once your entry is made, select the OK";

    }

    : row {

    width = 20;

    alignement = centered;

    spacer_0;

    : ok_button {

    label = "-OK-";

    key = "accept";

    fixed_width = true;

    width = 8;

    alignment = centered;

    }

    : cancel_button {

    label = "CANCEL";

    key = "cancel";

    fixed_width = true;

    width = 8;

    alignment = centered;

    }

    spacer_0;

    }

    }
     
    mdsc, Oct 19, 2005
    #3
  4. mdsc

    mdsc Guest

    nevermind. all set. here is the code I ended up with:

    (defun c:qw ()

    cmdech (getvar "CMDECHO")

    (setvar "CMDECHO" 0) ;turn echo off

    (setq out1 0)

    (setq outk 0)

    (setq ptX 0)

    (setq output 0)

    (setq outk 0)



    (setq thefile "tempx.mpr")

    (command "massprop" pause "" "y" thefile)

    (setq afile (open "tempx.mpr" "r"))


    (setq cpt 1)

    (while (setq aline (read-line afile))

    (if (= (substr aline 1 4) "Mass")

    (progn

    (setq ismass 1)

    (setq avalue 1)

    (setq ptX (atof (substr aline 26)))

    ) ;progn

    ); if

    )

    (close afile)

    (command "del" "tempx.mpr")



    (setq out1 (+ 0.28355))

    (setq outk (+ 0.4536))

    (setq output (* out1 ptX))

    (setq outputk (* output outk))

    (setq wt1 (rtos (* out1 ptX)))

    (setq wt2 (rtos (* output outk)))

    (setvar "CMDECHO" 1) ;turn echo on



    (princ "weight in pounds: ")

    (princ output)

    (princ " weight in kgs: ")

    (princ outputk)

    (princ)

    )
     
    mdsc, Oct 20, 2005
    #4
  5. Hi
    This one does in metric......
    ;Program written by Bill Le Couteur
    ;Auckland NZ
    ;Rev 0 date 3.11.04
    ;This program INSERTS A MASS BLOCK
    ;WITH THE MASS DERIVED FROM
    ;PICKING A SOLID
    ;-DERIVED FROM A TEXT FILE

    (defun c:GPM()

    (setq oldosmode (getvar "osmode"))
    (setvar "osmode" 0)
    (setvar "attdia" 0)

    (setvar "filedia" 0)


    (command "massprop" pause "" "Y" "C:/mass")


    ;;;;now open the list of drawings file
    (setq sfile (open "C:/mass.mpr" "r"))

    (setq count 5)


    (while (> count 0)(setq the_volume (read-line sfile))
    (progn;
    ;(print count)


    ;(print the_volume)
    (setq count (- count 1))

    );end progn
    );end while

    (setq howlong (strlen the_volume))

    (setq the_actualvolume (substr the_volume 26 howlongdes))

    (print the_actualvolume)
    (setq the_actualvolumef (atof the_actualvolume))
    (print the_actualvolumef)
    (setq the_actualvolumefcm ( / the_actualvolumef 1000000000))
    (setq the_mass (* the_actualvolumefcm 7850))

    (setq the_masss (rtos the_mass 2 2))
    (setq the_masss (strcat the_masss " kg"))




    (close sfile)
    (setvar "tilemode" 0)
    (command "-insert" "mass" "300,250" "1" "1" "0" the_masss)
    ;;comment---mass is just a little block with one attribute...
    (setvar "filedia" 1)
    (setvar "osmode" oldosmode)
    (setvar "attdia" 1)


    (princ)
    )
     
    Bill Le Couteur, Oct 21, 2005
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.