Jump to content

Please..correct and complete my simple lisp


Recommended Posts

Posted (edited)

Hi,...I still very beginner in autolisp.:):(

 

I had try a simple lisp (with DCL) and have completed by my friend, but there are some problem.

The first how to temporary save and show the lastest value in the Edit Boxes when the command repeated (but not shown after close then open again Autocad).:(

 

The others program how to fast when autolisp run the program (if possible, please the simple method..because I'm still new).

 

Can someone helpme? please don't join between lisp and dcl, but separated them..i'm still confused..:?:?:)

 

This my lisp:

 

[size=2][color=blue](defun c:pdtk (/ ans dcl_id K1 K2 K3 K4 T1 T2 T3 L1 L2 p11 p12 p13 p14 p15 p16 p17 p18 p1 p2 p3 p4 p5 p6 p7 p8 p9 p9a p10 p10a p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 tdk yat D1)
 
(setq dcl_id (load_dialog "pdtk.DCL"))
 (if
   (not (new_dialog "pdtk1" dcl_id))
   (exit)                                             
   ) ; if[/color][/size]
[size=2][color=blue] (setq w (dimx_tile "img"))
(setq h (dimy_tile "img"))
(start_image "img")
(vector_image 0 0 0 h 250)
(vector_image 0 h w h 250)
(vector_image w h w 0 250)
(vector_image w 0 0 0 250)
(fill_image 0 0 w h 250)
(slide_image 0 0 w h "pdtk")
(end_image)[/color][/size]
[size=2][color=blue]  (mode_tile "a" 3)
 (action_tile "a" "(setq T1 (atoi (get_tile \"a\")))")        ; Panjang telapak
 (mode_tile "b" 3)
 (action_tile "b" "(setq T2 (atoi (get_tile \"b\")))")        ; lebar telapak
 (mode_tile "c" 3)
 (action_tile "c" "(setq T3 (atoi (get_tile \"c\")))")        ; tebal telapak
 (mode_tile "d" 3)
 (action_tile "d" "(setq K1 (atoi (get_tile \"d\")))")        ; Panjang kolom
 (mode_tile "e" 3)
 (action_tile "e" "(setq K2 (atoi (get_tile \"e\")))")        ; lebar kolom
 (mode_tile "g" 3)
 (action_tile "g" "(setq K4 (atoi (get_tile \"g\")))")        ; Pedestal kolom
 (mode_tile "f" 3)
 (action_tile "f" "(setq K3 (atoi (get_tile \"f\")))")        ; dalam kolom
 (mode_tile "h" 3)
 (action_tile "h" "(setq L1 (atoi (get_tile \"h\")))")        ; tebal pasir
 (mode_tile "i" 3)
 (action_tile "i" "(setq L2 (atoi (get_tile \"i\")))")        ; tebal pemadatan tanah

 (action_tile "yat" "(setq yat (get_tile \"yat\"))")          ; ya
 (action_tile "tdk" "(setq tdk (get_tile \"tdk\"))")          ; tidak[/color][/size]
[size=2][color=blue]  (mode_tile "m" 3)
 (action_tile "m" "(setq D1 (atoi (get_tile \"m\")))")        ; tebal pemadatan tanah
 
 (action_tile "accept" "(done_dialog 1)")
 (action_tile "cancel" "(done_dialog 0)(exit)")
 (setq ans (start_dialog))[/color][/size]
[size=2]
[color=blue]  (setq p1 (getpoint "\nTentukan letak penggambaran:"))
 (setq p2 (polar p1 0 T1))
 (setq p3 (polar p2 (/ pi 2) T3))
 (setq p4 (polar p3 pi (/ (- T1 K1) 2)))
 (setq p5 (polar p1 (/ pi 2) T3))
 (setq p6 (polar p5 0 (/ (- T1 K1) 2)))
 (setq p7 (polar p4 (/ pi 2) K3))
 (setq p8 (polar p7 (/ pi 2) K4))  
 (setq p9 (polar p6 (/ pi 2) K3))
 (setq p10 (polar p9 (/ pi 2) K4))
 (setq p71 (polar p7 0 (* 1.6 (/ (- T1 K1) 2))))
 (setq p91 (polar p9 pi (* 1.6 (/ (- T1 K1) 2))))
 (setq p11 (polar p1 (/ pi 2) (+ (+ T3 K3 K4) (* 35.0 D1))))
 (setq p12 (polar p11 0 T1))
 (setq p13 (polar p12 (/ pi 2) T2))
 (setq p14 (polar p13 pi T1))
 (setq p15 (list (+ (car p11) (/ (- T1 K1) 2)) (+ (cadr p11) (/ (- T2 K2) 2))))
 (setq p16 (polar p15 0 k1))
 (setq p17 (polar p16 (/ pi 2) K2))
 (setq p18 (polar p17 pi K1))
 (setq p19 (list (+ (car p1) T1) (- (cadr p1) L1)))
 (setq p20 (polar p19 pi T1))
 (setq p21 (list (+ (car p20) T1) (- (cadr p1) L2)))
 (setq p22 (polar p21 pi T1))
 (setq p23 (polar p22 (* pi 1.5) (* 13.0 D1)))
 (setq p24 (polar p5 pi (* 22.0 D1)))
 (setq p25 (polar p8 (* pi 0.5) (* 10.0 D1)))
 (setq p26 (polar p14 (* pi 0.5) (* 11.0 D1)))
 (setq p27 (polar p14 pi (* 22.0 D1)))
 (setq p28 (polar p11 (* pi 1.5) (+ (/ (- T2 K2) 2) (* 1.0 D1))))
 (setq p29 (polar p13 0 (+ (/ (- T1 K1) 2) (* 5.0 D1))))
 (setq p30 (polar p21 0 (* 20.0 D1)))
 (cond
   ((= yat "1")
    (command "color" "3" "" "")
    (command "pline" p1 p2 p3 p4 p7 p8 p10 p9 p6 p5 "c")
    (command "color" "2" "" "")
    (command "line" p7 p71 "")
    (command "line" p9 p91 "")
    (command "color" "3" "" "")
    (command "pline" p11 p12 p13 p14 "c")
    (command "pline" p15 p16 p17 p18 "c")
    (command "color" "7" "" "")
    (command "line" p20 p19 "")
    (command "line" p21 p22 "")
    (setq olddimscale (getvar 'dimscale))
    (setvar "dimscale" D1)
    (command "_dimlinear" P21 P22 p23)
    (command "_dimlinear" P1 P5 p24)
    (command "_DIMCONTINUE" P91 p10 "" "")
    (command "_dimlinear" P8 P10 p25)
    (command "_dimlinear" P13 P14 p26)
    (command "_dimlinear" P11 P14 p27)
    (command "_dimlinear" P15 P16 p28)
    (command "_dimlinear" P16 P17 p29)
    (command "_dimlinear" P21 P19 p30)
    (command "_DIMCONTINUE" P2 "" "")
    (setvar "dimscale" olddimscale))
   ((= tdk "1")
    (command "color" "3" "" "")
    (command "pline" p1 p2 p3 p4 p7 p8 p10 p9 p6 p5 "c")
    (command "color" "2" "" "")
    (command "line" p7 p71 "")
    (command "line" p9 p91 "")
    (command "color" "3" "" "")
    (command "pline" p11 p12 p13 p14 "c")
    (command "pline" p15 p16 p17 p18 "c")
    (command "color" "7" "" "")
    (command "line" p20 p19 "")
    (command "line" p21 p22 ""))) ; cond
 (princ)
 ) ; defun
[/color] 

and the DCL:

[color=blue]// pdtk.dcl
pdtk1   : dialog { label = "PONDASI TELAPAK" ;[/color]
[color=blue]      : row {[/color]
[color=blue]      : boxed_radio_column {label = "Gambar" ;      
      
     : image {key = "img" ;
              height = 32.0 ;
              width = 40.0 ;}
     }         
              
     : boxed_radio_column { [/color]
[color=blue]      : boxed_radio_column { label = "Telapak" ; 
      
     : edit_box {key = "a" ;
                 label = "Panjang = T1" ;
                 edit_width = 8 ;}                       //value = 1000 ;} 
     : edit_box {key = "b" ;
                 label = "Lebar = T2" ;
                 edit_width = 8 ;}                       //value = 800 ;}
     : edit_box {key = "c" ;
                 label = "Tebal = T3" ;
                 edit_width = 8 ;}                       //value = 250 ;}
     }
     
     : boxed_radio_column {label = "Kolom" ; [/color]
[color=blue]      : edit_box {key = "d" ;
                 label = "Panjang = K1" ;
                 edit_width = 8 ;}                       //value = 400 ;} 
     : edit_box {key = "e" ;
                 label = "Lebar = K2" ;
                 edit_width = 8 ;}                       //value = 350 ;} 
     }[/color]
[color=blue]      : boxed_radio_column {label = "Elevasi" ;[/color]
[color=blue]      : edit_box {key = "g" ;
                 label = "Pedestal Kolom = K4" ;
                 edit_width = 8 ;}                       //value = 150 ;} 
     : edit_box {key = "f" ;
                 label = "Kedalaman Kolom = K3" ;
                 edit_width = 8 ;}                       //value = 600 ; } 
     : edit_box {key = "h" ;
                 label = "Lapisan Pasir = L1" ;
                 edit_width = 8 ;}                       //value = 100 ; } 
     : edit_box {key = "i" ;
                 label = "Lapisan Pemadatan = L2" ;
                 edit_width = 8 ;}                       //value = 200 ; } 
     }
     
     : boxed_radio_row {label = "Cetak Dimensi" ; [/color]
[color=blue]      : radio_button {label = "Ya";
                     key = "yat";}                       //value = 1;}
     : radio_button {label = "Tidak";
                     key = "tdk";}                       //value = 0;} [/color]
[color=blue]      }[/color]
[color=blue]      : edit_box {key = "m" ;
                 label = "Skala Dimensi" ;
                 edit_width = 6 ;}                       //value = 15 ;} [/color]
[color=blue]      }   
     }
     ok_cancel ; 
         [/color]
[color=blue]      }[/color]
[/size] 







Edited by Tiger
added code tags
Posted

pdtk.lsp

pdtk.DCL

 

 

I have rewritten most of your dcl function, to allow for global values in the dialog box. I have also separated the dcl function, rather than running it all together(this is not good practice) with the main function. You will have to finish off the code - I have done the first 3 values. I have also added a default to edit box values. The dcl file is also slightly amended.

I am not sure what your second question means?

The others program how to fast when autolisp run the program

 

 
(defun c:pdtk (/ ans dcl_id K1 K2 K3 K4 L1 L2 p11 p12
p13 p14 p15 p16 p17 p18 p1 p2 p3 p4 p5 p6 p7
p8 p9 p9a p10 p10a p19 p20 p21 p22 p23 p24 p25
p26 p27 p28 p29 tdk yat D1);don't declare variables
;that you want to keep values of (eg T1 T2 T3...)

;; Make Global values and set default values
(setq T1(cond (T1) (T 1000)));Retain value for next use (default set to 1000)
(setq T2(cond (T2) (T 800))) 
(setq T3(cond (T3) (T 250)))
;etc....

(pdtkdcl);activate dcl

(setq T1 (atof T1));convert string to real number
(setq T2 (atof T2))
(setq T3 (atof T3))
;etc.......

(setq p1 (getpoint "\nTentukan letak penggambaran:"))
(setq p2 (polar p1 0 T1))
(setq p3 (polar p2 (/ pi 2) T3))
(setq p4 (polar p3 pi (/ (- T1 K1) 2)))
(setq p5 (polar p1 (/ pi 2) T3))
(setq p6 (polar p5 0 (/ (- T1 K1) 2)))
(setq p7 (polar p4 (/ pi 2) K3))
(setq p8 (polar p7 (/ pi 2) K4)) 
(setq p9 (polar p6 (/ pi 2) K3))
(setq p10 (polar p9 (/ pi 2) K4))
(setq p71 (polar p7 0 (* 1.6 (/ (- T1 K1) 2))))
(setq p91 (polar p9 pi (* 1.6 (/ (- T1 K1) 2))))
(setq p11 (polar p1 (/ pi 2) (+ (+ T3 K3 K4) (* 35.0 D1))))
(setq p12 (polar p11 0 T1))
(setq p13 (polar p12 (/ pi 2) T2))
(setq p14 (polar p13 pi T1))
(setq p15 (list (+ (car p11) (/ (- T1 K1) 2)) (+ (cadr p11) (/ (- T2 K2) 2))))
(setq p16 (polar p15 0 k1))
(setq p17 (polar p16 (/ pi 2) K2))
(setq p18 (polar p17 pi K1))
(setq p19 (list (+ (car p1) T1) (- (cadr p1) L1)))
(setq p20 (polar p19 pi T1))
(setq p21 (list (+ (car p20) T1) (- (cadr p1) L2)))
(setq p22 (polar p21 pi T1))
(setq p23 (polar p22 (* pi 1.5) (* 13.0 D1)))
(setq p24 (polar p5 pi (* 22.0 D1)))
(setq p25 (polar p8 (* pi 0.5) (* 10.0 D1)))
(setq p26 (polar p14 (* pi 0.5) (* 11.0 D1)))
(setq p27 (polar p14 pi (* 22.0 D1)))
(setq p28 (polar p11 (* pi 1.5) (+ (/ (- T2 K2) 2) (* 1.0 D1))))
(setq p29 (polar p13 0 (+ (/ (- T1 K1) 2) (* 5.0 D1))))
(setq p30 (polar p21 0 (* 20.0 D1)))
(cond
((= yat "1")
(command "color" "3" "" "")
(command "pline" p1 p2 p3 p4 p7 p8 p10 p9 p6 p5 "c")
(command "color" "2" "" "")
(command "line" p7 p71 "")
(command "line" p9 p91 "")
(command "color" "3" "" "")
(command "pline" p11 p12 p13 p14 "c")
(command "pline" p15 p16 p17 p18 "c")
(command "color" "7" "" "")
(command "line" p20 p19 "")
(command "line" p21 p22 "")
(setq olddimscale (getvar 'dimscale))
(setvar "dimscale" D1)
(command "_dimlinear" P21 P22 p23)
(command "_dimlinear" P1 P5 p24)
(command "_DIMCONTINUE" P91 p10 "" "")
(command "_dimlinear" P8 P10 p25)
(command "_dimlinear" P13 P14 p26)
(command "_dimlinear" P11 P14 p27)
(command "_dimlinear" P15 P16 p28)
(command "_dimlinear" P16 P17 p29)
(command "_dimlinear" P21 P19 p30)
(command "_DIMCONTINUE" P2 "" "")
(setvar "dimscale" olddimscale))
((= tdk "1")
(command "color" "3" "" "")
(command "pline" p1 p2 p3 p4 p7 p8 p10 p9 p6 p5 "c")
(command "color" "2" "" "")
(command "line" p7 p71 "")
(command "line" p9 p91 "")
(command "color" "3" "" "")
(command "pline" p11 p12 p13 p14 "c")
(command "pline" p15 p16 p17 p18 "c")
(command "color" "7" "" "")
(command "line" p20 p19 "")
(command "line" p21 p22 ""))) ; cond
(princ)
); defun

(defun pdtkdcl (/ TempT1 TempT2 TempT3 )
(defun CheckOnClose (/ )

(setq T1 TempT1) ;set global values for T1
(setq T2 TempT2) ;set global values for T2
(setq T3 TempT3) ;set global values for T3
(cond
(T
(setq T1 (get_tile "T1"))
(setq T2 (get_tile "T2")) 
(setq T3 (get_tile "T3")) 
(done_dialog 1)
);T
);cond
);defun

(setq DCL_IDX (load_dialog "pdtk.dcl"))
(if (not (new_dialog "pdtk" DCL_IDX))
(exit)
);if

;write the globals to temporary variables
;this allows to hold the original values
;in case of cancel
(setq TempT1 T1 )
(setq TempT2 T2 ) 
(setq TempT3 T3 ) 

(setq w (dimx_tile "img"))
(setq h (dimy_tile "img"))
(start_image "img")
(vector_image 0 0 0 h 250)
(vector_image 0 h w h 250)
(vector_image w h w 0 250)
(vector_image w 0 0 0 250)
(fill_image 0 0 w h 250)
(slide_image 0 0 w h "pdtk")
(end_image)
;;; (mode_tile "a" 3)
;;; (action_tile "a" "(setq T1 (atoi (get_tile \"a\")))") ; Panjang telapak
;;; (mode_tile "b" 3)
;;; (action_tile "b" "(setq T2 (atoi (get_tile \"b\")))") ; lebar telapak
;;; (mode_tile "c" 3)
;;; (action_tile "c" "(setq T3 (atoi (get_tile \"c\")))") ; tebal telapak
;;; (mode_tile "d" 3)
;;; (action_tile "d" "(setq K1 (atoi (get_tile \"d\")))") ; Panjang kolom
;;; (mode_tile "e" 3)
;;; (action_tile "e" "(setq K2 (atoi (get_tile \"e\")))") ; lebar kolom
;;; (mode_tile "g" 3)
;;; (action_tile "g" "(setq K4 (atoi (get_tile \"g\")))") ; Pedestal kolom
;;; (mode_tile "f" 3)
;;; (action_tile "f" "(setq K3 (atoi (get_tile \"f\")))") ; dalam kolom
;;; (mode_tile "h" 3)
;;; (action_tile "h" "(setq L1 (atoi (get_tile \"h\")))") ; tebal pasir
;;; (mode_tile "i" 3)
;;; (action_tile "i" "(setq L2 (atoi (get_tile \"i\")))") ; tebal pemadatan tanah
;;; 
;;; (action_tile "yat" "(setq yat (get_tile \"yat\"))") ; ya
;;; (action_tile "tdk" "(setq tdk (get_tile \"tdk\"))") ; tidak
;;; (mode_tile "m" 3)
;;; (action_tile "m" "(setq D1 (atoi (get_tile \"m\")))") ; tebal pemadatan tanah
(if TempT1 (set_tile "T1" (rtos TempT1 2 0))
(setq TempT1 "")
);if
(if TempT2 (set_tile "T2" (rtos TempT2 2 0))
(setq TempT2 "")
);if
(if TempT3 (set_tile "T3" (rtos TempT3 2 0))
(setq TempT3 "")
);if

(action_tile "T1" "(ErrorDLG 0)")
(action_tile "T2" "(ErrorDLG 0)")
(action_tile "T3" "(ErrorDLG 0)")
(action_tile "accept" "(CheckOnClose)")
(action_tile "cancel" "(exit)")

(start_dialog)
(unload_dialog DCL_IDx)

(princ)

);defun pdtkdcl
(defun ErrorDLG (pErr)
(cond
((= pErr 0) (set_tile "error" ""))
);cond
);defun


Posted

Thanks..

I have allready test your code but cannot run. On command line shown "; error: no function definition: PDTKDCL".

 

I check in vlide, there is no problem or mistake on the lisp....:?

 

Regards,

PR

Posted

I have just checked it and it works fine. Remember to use the dcl file I have made rather than use your old one.

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...