TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Adesu on December 07, 2006, 11:29:17 PM
-
Hi Alls,
I'm attempt to "recreating" code from "Terry Miller",to more simple and easy to understand,here that code,what am I do wrong with this code.
LSP File
(defun *create_icon* (lst / cnt col x x1 x2 y y1 y2)
(if
(= (type lst) 'list)
(progn
(setq cnt 0)
(repeat
(/ (length lst) 2)
(setq x (nth cnt lst))
(setq y (nth (+ cnt 1) lst))
(if
(and (= (type x) 'str)(= (type y) 'int))
(if
(= (strcase x "c"))
(progn
(setq col y)
(setq x1 nil)
(setq y1 nil)
(setq x2 nil)
(setq y2 nil)
) ; progn
) ; if
(if
(and (= (type x) 'int) (= (type y) 'int))
(if
(and (= x1 nil) (= y1 nil))
(progn
(setq x1 x)
(setq y1 y)
) ; progn
(progn
(setq x2 x)
(setq y2 y)
(vector_image x1 y1 x2 y2 col)
(setq x1 x2)
(setq y1 y2)
(setq x nil)
(setq y nil)
) ; progn
) ; if
) ; if
) ; if
) ; repeat
(setq cnt (+ cnt 2))
) ; progn
) ; if
) ; defun
(defun *smile* ( )
(start_image "smile")
(*create_icon* lst1)
(*create_icon* lst2)
(*create_icon* lst3)
(end_image)
) ; defun
(defun c:ci (/ dcl_id ans)
(setq dcl_id (load_dialog "Create Icon.DCL"))
(if
(not (new_dialog "ci" dcl_id))
(exit)
) ; if
(setq lst1 (list "C" 2 2 12 2 19 "C" 2 3 9 3 22 4 23 4 8 "C" 2 5 6 5 25 6
26 6 5 7 5 7 26 8 27 8 4 9 3 9 28 10 28 10 3 11 3 11 28 12 29 12 2 13 2
13 29 14 29 14 2 15 2 15 29 16 29 16 2 17 2 17 29 18 29 18 2 19 2 19 29
20 28 20 3 21 3 21 28 22 28 22 3 23 4 23 27 24 26 24 5 25 5 25 26 26 25
26 6 "C" 2 27 8 27 23 28 22 28 9 "C" 2 29 19 29 12))
(setq lst2 (list "C" 250 12 30 19 30 20 29 22 29 24 27 25 27 27 25 27 24
29 22 29 20 30 19 30 12 29 11 29 9 27 7 27 6 25 4 24 4 22 2 20 2 19 1 12
1 11 2 9 2 7 4 6 4 4 6 4 7 2 9 2 11 1 12 1 19 2 20 2 22 4 24 4 25 6 27 7
27 9 29 11 29 "C" 250 6 18 8 20 9 20 10 21 12 21 13 22 18 22 19 21 21 21
22 20 23 20 25 18 "C" 250 11 12 11 10 12 9 12 13 13 12 13 10 "C" 250 18
12 18 10 19 9 19 13 20 12 20 10))
(setq lst3 (list "C" 8 7 28 8 29 "C" 8 14 32 21 32 "C" 8 10 30 11 30 11
31 24 31 25 30 20 30 "C" 8 27 29 23 29 24 28 28 28 29 27 26 27 27 26 29
26 29 23 28 24 28 25 "C" 8 30 20 30 25 31 24 31 11 30 11 30 10 "C" 8 32
21 32 14 "C" 8 28 7 29 8))
(*smile*)
(setq ans (start_dialog))
(unload_dialog dcl_id)
(princ)
) ; defun
and here DCL File
ci : dialog {label = "SAMPLE CREATE ICON";
spacer;
: row {
: column {
: image {key = "smile";
width = 5.42;
height = 2.51;
fixed_width = true;
fixed_height = true;
aspect_ratio = 1;
color = -15;
alignment = centered;}}}
spacer;
: ok_button{is_cancel = true;}}
-
Hi Alls,
... what am I do wrong with this code.
Adesu,
What is the problem that you see ?
/// kwb
-
More to the point, what are you trying to do in the first place?
-
Hi Kerry,
That problem is icon "smile" can not display in the dialog box ( there is not icon).
Hi Alls,
... what am I do wrong with this code.
Adesu,
What is the problem that you see ?
/// kwb
-
what happens when you change the lst data to something simple, like a line ?
what happens when you run it animated from the IDE ?
have you tried to step through the code.
the width an height of the display are different , yet the aspect ratio is st to 1 ... is this correct ?
Haven't tried to download the code, but it seems just from reading the code that only one list is used, why are there 3 ?
.... ahhh I see now !! Why are there 3 lists ?
-
A deferent approach, list of vectors grouped by color
'( (color (vectors)) (color (vectors)) (color (vectors)) )
I did not do a real test!
(defun group_on4 (inplst / outlst tmp grp idx sub)
(while inplst
(setq outlst
(cons
(list (car inplst) (cadr inplst) (caddr inplst) (cadddr inplst))
outlst
)
)
(setq inplst (cddddr inplst))
)
outlst
)
(defun c:test ()
(setq vectorlst
(list
(list 2
(list 2 12 2 19 3 9 3 22 4 23 4 8 5 6 5 25 6 26 6
5 7 5 7 26 8 27 8 4 9 3 9 28 10 28 10 3 11 3
11 28 12 29 12 2 13 2 13 29 14 29 14 2 15 2 15 29 16
29 16 2 17 2 17 29 18 29 18 2 19 2 19 29 20 28 20 3
21 3 21 28 22 28 22 3 23 4 23 27 24 26 24 5 25 5 25
26 26 25 26 6 27 8 27 23 28 22 28 9 29 19 29 12
)
)
(list 250
(list 7 28 8 29 14 32 21 32 10 30 11 30 11 31
24 31 25 30 20 30 27 29 23 29 24 28 28 28
29 27 26 27 27 26 29 26 29 23 28 24 28 25
30 20 30 25 31 24 31 11 30 11 30 10 32 21
32 14 28 7 ; 29 8
) )
(list 8
(list 7 28 8 29 14 32 21 32 10 30 11 30 11 31
24 31 25 30 20 30 27 29 23 29 24 28 28 28
29 27 26 27 27 26 29 26 29 23 28 24 28 25
30 20 30 25 31 24 31 11 30 11 30 10 32 21
32 14 28 7 ; 29 8
)
)
)
)
(start_image "smile")
(mapcar
'(lambda (x)
(mapcar '(lambda (v) (apply 'vector_image (append v (list (car x))))) (group_on4 (cadr x)))
)
vectorlst
)
(end_image)
)
-
Hi CAB,
That code you are just create is great,thanks for your share,it's only dot with yellow color,that code I would learn ,how that code work.
Thanks.
-
Lets start with the first mapcar, it feeds the vector list to the inner mapcar like this
(mapcar
'(lambda (x)
This gets x which is this
the first time through (2 (2 12 2 19 .....))
then this the second time (250 (7 28 8 29 14 ........))
then finally this (8 (7 28 8 29 14 32 .............))
vectorlst
)
This is the inner mapcar that takes the x and processes it like this
This (group_on4 (cadr x)) takes this (2 12 2 19 .....) and returns this ((2 12 2 19)(3 9 3 22)(4 23 4 8 )(5 6 5 25))
so v equals this on the first time (2 12 2 19) and second time (3 9 3 22) and so on
this (append v (list (car x))) creates this (2 12 2 19 2) the first time & this (3 9 3 22 2) the second time & so on
the apply passes a list of arguments to, and executes a specified function so it acts like
this the first time (vector_image 2 12 2 19 2) and this the second time (vector_image 3 9 3 22 2) and so on
(mapcar '(lambda (v)
(apply 'vector_image (append v (list (car x)))))
(group_on4 (cadr x))
)
Here is the working demo
(defun c:ci (/ ans dcl_id v vectorlst x group_on4)
;; Group a list into sub list with 4 items in it
;; '(2 12 2 19 3 9 3 22 4 23 4 8 5 6 5 25) becomes
;; '((2 12 2 19)(3 9 3 22)(4 23 4 8)(5 6 5 25))
(defun group_on4 (inplst / outlst tmp grp idx sub)
(while inplst
(setq outlst
(cons
(list (car inplst) (cadr inplst) (caddr inplst) (cadddr inplst))
outlst
)
)
(setq inplst (cddddr inplst))
)
outlst
)
(setq vectorlst
(list
(list 2
(list 2 12 2 19 3 9 3 22 4 23 4 8 5 6 5 25 6 26 6
5 7 5 7 26 8 27 8 4 9 3 9 28 10 28 10 3 11 3
11 28 12 29 12 2 13 2 13 29 14 29 14 2 15 2 15 29 16
29 16 2 17 2 17 29 18 29 18 2 19 2 19 29 20 28 20 3
21 3 21 28 22 28 22 3 23 4 23 27 24 26 24 5 25 5 25
26 26 25 26 6 27 8 27 23 28 22 28 9 29 19 29 12
)
)
(list 250
(list 7 28 8 29 14 32 21 32 10 30 11 30 11 31
24 31 25 30 20 30 27 29 23 29 24 28 28 28
29 27 26 27 27 26 29 26 29 23 28 24 28 25
30 20 30 25 31 24 31 11 30 11 30 10 32 21
32 14 28 7 ; 29 8
)
)
(list 8
(list 7 28 8 29 14 32 21 32 10 30 11 30 11 31
24 31 25 30 20 30 27 29 23 29 24 28 28 28
29 27 26 27 27 26 29 26 29 23 28 24 28 25
30 20 30 25 31 24 31 11 30 11 30 10 32 21
32 14 28 7 ; 29 8
)
)
)
)
(setq dcl_id (load_dialog "Create Icon.DCL"))
(if (new_dialog "ci" dcl_id)
(progn
(start_image "smile")
(mapcar
'(lambda (x)
(mapcar '(lambda (v) (apply 'vector_image (append v (list (car x)))))
(group_on4 (cadr x))
)
)
vectorlst
)
(end_image)
(setq ans (start_dialog))
(unload_dialog dcl_id)
)
)
(princ)
)
And the DCL code
dcl_settings : default_dcl_settings { audit_level = 3; }
ci : dialog {label = "SAMPLE CREATE ICON";
spacer ;
: row {
: column {
: image { key = "smile" ; width = 5.42; height = 2.51; color = -15;}
}
}
spacer;
: ok_button {is_cancel = true;}
}
-
Hi CAB,
I'm not yet understand what function is
dcl_settings : default_dcl_settings { audit_level = 3; }
-
dcl_settings : default_dcl_settings { audit_level = 3; }
Turns on error checking and will help trouble shoot any errors that you have in your DCL code. Valid settings are….
0 . No checking. Use only if the DCL files have been audited and have not been touched since.
1 . Errors. Finds DCL bugs that may cause AutoCAD to terminate. This level of checking is the default and involves almost no delay. Errors can include using undefined tiles and circular prototype definitions.
2 . Warnings. Finds DCL bugs that result in dialogs with undesired layout or behavior. A modified DCL file should be audited at this level at least once. The warning level catches mistakes, such as missing required attributes and inappropriate attribute values.
3 . Hints. Finds redundant attribute definitions.
/// kwb
-
Hi Kerry,
It's good information for me,good tutorial...thanks...thanks...thanks
********* "HAPPY NEW YEAR AND MARRY CHRISTMAS" *********
-
This may help too.
http://www.theswamp.org/index.php?topic=13915.0
-
I got in on the gatortail end of this! And CAB you do have a good alternative method that I might have used. The initial thread referenced simplifying the function “vector_line” in GetIcon.lsp. Just below the “Smile:” function in “GetIcon.lsp” is “GetPt”. With “GetPt” you set your snap to 1 and trace the endpoints of a polyline by picking every point. Then do a flip screen and copy and paste the X and Y points into your image function. The “C” was the trigger to tell the function either I have moved to a different area or have changed colors. Sort of a pen up / pen down method. The reason I wrote this is because I reviewed other works by others using the standard (vector_image 5 3 7 4 1) method, line after painful line, and I decided to create an easier method to just cut and paste X and Y points.
The main difference between the original “vector_line” code and “*create_icon*” was that the function “setq” was spanned over several lines and the variable names are different. There is only one minor but major error in your revised version. Move the line (setq cnt (+ cnt 2)) inside the repeat loop.
http://web2.airmail.net/terrycad/Images/GetIcon.htm
http://web2.airmail.net/terrycad/LISP/GetIcon.lsp
Also look into the mapcar version of creating images:
http://web2.airmail.net/terrycad/LISP/GetVectors.lsp
http://web2.airmail.net/terrycad/LISP/GetVectors.dcl
(defun *create_icon* (lst / cnt col x x1 x2 y y1 y2)
(if (= (type lst) 'LIST)
(progn
(setq cnt 0)
(repeat (/ (length lst) 2)
(setq x (nth cnt lst))
(setq y (nth (+ cnt 1) lst))
(if (and (= (type x) 'STR)(= (type y) 'INT))
(if (= (strcase x "C"));CAP
(progn
(setq col y)
(setq x1 nil)
(setq y1 nil)
(setq x2 nil)
(setq y2 nil)
); progn
); if
(if (and (= (type x) 'INT) (= (type y) 'INT))
(if (and (= x1 nil) (= y1 nil))
(progn
(setq x1 x)
(setq y1 y)
); progn
(progn
(setq x2 x)
(setq y2 y)
(vector_image x1 y1 x2 y2 col)
(setq x1 x2)
(setq y1 y2)
(setq x nil)
(setq y nil)
); progn
); if
); if
); if
(setq cnt (+ cnt 2))
); repeat
); progn
); if
); defun
-
Oh, I see how the vector list works now.
Thanks Terry for the explanation.
Here is a revised code that will handle those list.
(defun c:ci (/ vectorlists lst dcl_id)
(setq vectorlists
(list
(list "C" 2 2 12 2 19 "C" 2 3 9 3 22 4 23 4
8 "C" 2 5 6 5 25 6 26 6 5 7 5 7 26
8 27 8 4 9 3 9 28 10 28 10 3 11 3 11
28 12 29 12 2 13 2 13 29 14 29 14 2 15 2
15 29 16 29 16 2 17 2 17 29 18 29 18 2 19
2 19 29 20 28 20 3 21 3 21 28 22 28 22 3
23 4 23 27 24 26 24 5 25 5 25 26 26 25 26
6 "C" 2 27 8 27 23 28 22 28 9 "C" 2 29 19
29 12
)
(list "C" 250 12 30 19 30 20 29 22 29 24 27 25 27 27
25 27 24 29 22 29 20 30 19 30 12 29 11 29 9
27 7 27 6 25 4 24 4 22 2 20 2 19 1 12
1 11 2 9 2 7 4 6 4 4 6 4 7 2 9
2 11 1 12 1 19 2 20 2 22 4 24 4 25 6
27 7 27 9 29 11 29 "C" 250 6 18 8 20 9 20
10 21 12 21 13 22 18 22 19 21 21 21 22 20 23
20 25 18 "C" 250 11 12 11 10 12 9 12 13 13 12
13 10 "C" 250 18 12 18 10 19 9 19 13 20 12 20
10
)
(list "C" 8 7 28 8 29 "C" 8 14 32 21 32 "C" 8 10
30 11 30 11 31 24 31 25 30 20 30 "C" 8 27 29
23 29 24 28 28 28 29 27 26 27 27 26 29 26 29
23 28 24 28 25 "C" 8 30 20 30 25 31 24 31 11
30 11 30 10 "C" 8 32 21 32 14 "C" 8 28 7 29
8
)
)
)
(setq dcl_id (load_dialog "Create Icon.DCL"))
(if (new_dialog "ci" dcl_id)
(progn
(start_image "smile")
(mapcar
'(lambda (lst / idx x1 y1 x2 y2 #color)
(setq idx 0)
(while (setq x1 (nth idx lst))
(setq y1 (nth (1+ idx) lst))
(cond
((= x1 "C") (setq #color y1))
((= (nth (+ idx 2) lst) "C"))
((setq x2 (nth (+ idx 2) lst)
y2 (nth (+ idx 3) lst)
)
(vector_image x1 y1 x2 y2 #color)
)
)
(setq idx (+ 2 idx)) ; skip 2
)
)
vectorlists
)
(end_image)
(setq dcl_id (start_dialog))
(unload_dialog dcl_id)
)
)
(princ)
)
-
Terry,
Having read your DCL tutorials, I must say you have done a great job with them.
The vector routines are very helpful & take the pain out of creating vector images.
I have used it to create some images for my Dialog boxes. :-)
Thanks for all your hard work.
-
Hi Terry,
Thanks you very much for you correction,you are right my wrong only in "c" string.
Thanks a lot again.
-
You can see my variant DCL + VECTOR_IMAGE... :-)
http://www.theswamp.org/index.php?topic=12223.0
-
Hi Alls,
As long as one week,I attemp to create and analysis of building of icon,I know and I understand how to create icon,here that code.
Special thanks to "Terry Miller" for your share of code.
(defun clfp (lst / ?lst alst cnt div len xlst)
(setq len (length lst))
(setq div (/ len 4))
(setq cnt 0)
(repeat
div
(setq xlst (list (nth cnt lst)
(nth (setq cnt (1+ cnt)) lst)
(nth (setq cnt (1+ cnt)) lst)
(nth (setq cnt (1+ cnt)) lst)
))
(setq ?lst (append ?lst (list xlst)))
(setq cnt (1+ cnt))
) ; repeat
?lst
) ; defun
(defun c:test (/ dcl_id ans)
(setq dcl_id (load_dialog "Sample Create Icon.DCL"))
(if
(not (new_dialog "sci" dcl_id))
(exit)
) ; if
(setq lst1 '(11 0 13 0 ; create cicle
7 1 17 1
5 2 18 2
4 3 20 3
3 4 21 4
2 5 22 5
2 6 22 6
1 7 23 7
1 8 23 8
1 9 24 9
0 10 24 10
0 11 24 11
0 12 24 12
0 13 24 13
0 14 24 14
1 15 24 15
1 16 23 16
1 17 23 17
2 18 22 18
2 19 22 19
3 20 21 20
4 21 20 21
5 22 19 22
7 23 17 23
11 24 13 24))
(setq lst2 '(6 6 8 6 ; create eye
5 7 9 7
5 8 9 8
5 9 9 9
6 10 8 10))
(setq lst3 '(16 6 18 6 ; create eye
15 7 19 7
15 8 19 8
15 9 19 9
16 10 19 10))
(setq lst4 '(7 16 8 16 ; create mouth
8 16 9 17
9 17 10 17
10 17 11 18
11 18 12 18
12 18 13 18
13 18 14 17
14 17 15 17
15 17 16 16
16 16 17 16))
(setq blst1 (clfp lst1))
(setq blst2 (clfp lst2))
(setq blst3 (clfp lst3))
(setq blst4 (clfp lst4))
(start_image "temp")
(mapcar '(lambda (x)
(vector_image (car x)(cadr x)(caddr x)(cadddr x) 1)
) ; lambda
blst1
) ; mapcar
(mapcar '(lambda (x)
(vector_image (car x)(cadr x)(caddr x)(cadddr x) 250)
) ; lambda
blst2
) ; mapcar
(mapcar '(lambda (x)
(vector_image (car x)(cadr x)(caddr x)(cadddr x) 250)
) ; lambda
blst3
) ; mapcar
(mapcar '(lambda (x)
(vector_image (car x)(cadr x)(caddr x)(cadddr x) 250)
) ; lambda
blst4
) ; mapcar
(end_image)
(setq ans (start_dialog))
(unload_dialog dcl_id)
(princ)
) ; defun
here dcl file
sci : dialog {label = "SAMPLE CREATE ICON";
spacer;
: row {
: column {
: image {key = "temp";
width = 5.42;
height = 2.51;
fixed_width = true;
fixed_height = true;
aspect_ratio = 1;
color = -15;
alignment = centered;}}}
spacer;
: ok_button {is_cancel = true;}}