TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pBe on October 24, 2010, 09:10:17 AM
-
Why cant i create a dynamic variable inside an action_tile line?
(defun Get_Folder ()
(setq sObj (vla-getInterfaceObject
(vlax-get-acad-object)"Shell.Application")
cFold(vlax-invoke-method sObj 'BrowseForFolder 0 "Select Folder for Layer Files" 0))
(vlax-release-object sObj)
(setq fObj(vlax-get-property cFold 'Self)
oVal (vlax-get-property fObj 'Path))
(setq ftl (vl-directory-files oval "*.dwg"))
(foreach sto ftl
(setq fto (strcat oval "\\" sto) ftl_ ftl)
;(takbo fto)
)
(vlax-release-object cFold)
(vlax-release-object fObj)
(princ)
)
(defun c:GD2 ()
[color=blue](setq Dsc_l '("CVL_" "ARCHL_" "STCL_" "ELCTL_" "MECH_" "PLMBG_" "GENR_"))[/color] ;result from another routine
(setq cs_dcl (load_dialog "Cover_tbed.DCL"))
(if (not (new_dialog "Drw_index" cs_dcl))
(exit)
)
(start_list "DW_LST")
(mapcar 'add_list ftl_)
(end_list)
(foreach md_ Dsc_l
(mode_tile (strcat md_ "C") 1))
;(action_tile "Remove_" "(setq Nt_rl (get_tile \"DW_LST\") itm 0)")
(foreach ad_str Dsc_l
[color=red]; (setq &# (vl-position ad_str Dsc_l))[/color]
(action_tile [color=blue]ad_str[/color] (vl-prin1-to-string
(quote
(progn
(setq Ds_rl (get_tile "DW_LST") Ad_ls nil tmp_l nil)
(while (/= Ds_rl "")
(setq Ad_ls (cons (atoi Ds_rl) Ad_ls)
Ds_rl (vl-string-left-trim (strcat " "(itoa (atoi Ds_rl))) Ds_rl))
)
;(ds_tm Ad_ls)
(foreach & Ad_ls
(setq tmp_l (cons (nth & ftl_) tmp_l))
(setq ftl_ (vl-remove (nth & ftl_) ftl_)))
(start_list "DW_LST")(mapcar 'add_list ftl_)(end_list)
(set (setq cc (read (strcat [color=blue]$key[/color] "ls"))) tmp_l)[color=blue](mode_tile $key 1)[/color]
)
)
)
)
)
(mode_tile "Remove_C" 1)
(action_tile "Remove_" (vl-prin1-to-string
(quote
(progn
(setq Nt_rl (get_tile "DW_LST") rm_ls nil)
(while (/= Nt_rl "")
(setq rm_ls (cons (atoi Nt_rl) rm_ls)
Nt_rl (vl-string-left-trim (strcat " "(itoa (atoi Nt_rl))) Nt_rl))
)
(foreach & rm_ls
(setq ftl_ (vl-remove (nth & ftl_) ftl_)))(set_tile "Remove_C" (itoa (length rm_ls)))
(start_list "DW_LST")(mapcar 'add_list ftl_)(end_list)
)
)
)
)
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(start_dialog)
(unload_dialog cs_dcl)
)
running the routine only give me the last variable name on my list.. and the rest is nil
what do you guys think is wrong?
:-)
Edit: silly me .forgot to paste the whole routine :-P
Update DCL: Lee Mac Edition
Update Code to include $key
Thanks guys
-
Welcome to theSwamp pBe :-)
Slightly outside the scope of your question, but you could perhaps simplify your DCL slightly to something like this:
ed2 : edit_box { edit_limit = 2; edit_width = 2; }
bta : button { label = "Add to -->"; }
btr : button { label = "Remove -->"; }
Drw_index : dialog { label = "Drawing index"; spacer;
: row {
: boxed_column { label = "Drawing List";
: list_box { key = "DW_LST"; multiple_select = true; width = 40; height = 20; } spacer ;
}
: boxed_column {
: bta { key = "CVL_" ; }
: bta { key = "ARCHL_"; }
: bta { key = "STCL_" ; }
: bta { key = "ELCTL_"; }
: bta { key = "MECH_" ; }
: bta { key = "PLMBG_"; }
: bta { key = "GENR_" ; }
: btr { key = "Remove_"; }
spacer;
}
: boxed_column { label = "Discipline";
: ed2 { label = "Civil"; key = "CVL_C"; }
: ed2 { label = "Architectural"; key = "ARCHL_C"; }
: ed2 { label = "Structural"; key = "STCL_C"; }
: ed2 { label = "Electrical"; key = "ELCTL_C"; }
: ed2 { label = "Mechanical"; key = "MECH_C"; }
: ed2 { label = "Plumbing"; key = "PLMBG_C"; }
: ed2 { label = "General"; key = "GENR_C"; }
: ed2 { label = "Remove" ; key = "Remove_C";}
spacer;
}
}
spacer; ok_cancel;
}
-
ed2 : edit_box { edit_limit = 2; edit_width = 2; }
bta : button { label = "Add to -->"; }
btr : button { label = "Remove -->"; }
Like I said... a mile long.. cheese and rice Lee i never knew you can do that with DCL.... for every call to any of that lines will definitely shorten it...
MILE LOOOOOOOONG little by little i'm learning..... :-D ........is there anything in Lisp that you dont know? :lol:
Thanks Lee
-
Like I said... a mile long.. cheese and rice Lee i never knew you can do that with DCL.... for every call to any of that lines will definitely shorten it...
MILE LOOOOOOOONG little by little i'm learning..... :-D ........is there anything in Lisp that you dont know? :lol:
Thanks :-)
Don't worry, there's plenty I don't know..
-
@ pBe: Dsc_l is not defined. I don't know if that is the problem but I can't test that without Dsc_l.
-
Perhaps change this:
(set (setq cc (read (strcat (nth &# Dsc_l) "ls"))) tmp_l)
To:
(set (setq cc (read (strcat $key "ls"))) tmp_l)
If this solves it, the problem is related to the use of (quote).
Tip:
Change this:
(foreach ad_str Dsc_l
(setq &# (vl-position ad_str Dsc_l))
(action_tile (nth &# Dsc_l) (vl-prin1-to-string
To:
(foreach ad_str Dsc_l
(action_tile ad_str (vl-prin1-to-string
:wink:
-
(set (setq cc (read (strcat [color=red]$key[/color] "ls"))) tmp_l)
Thats the one...
I did it this way because i thought the problem lies with the quote
(set (setq cc (read (strcat (nth &# Dsc_l) "ls"))) tmp_l)
it was originally like what you wrote there...
(foreach ad_str Dsc_l
(action_tile ad_str (vl-prin1-to-string
but quote reads the variable ad_str differently so i throw in a call to a list...
but then.... still the same result.. so what i did is separate the routine into two... which makes the codes longer..
(action_tile "CVL_" "(setq ds_pst 0)(ds_tm ds_pst)(mode_tile \"CVL_\" 1)").....
(defun ds_tm (ds_pst / Ds_rl Ad_ls tmp_l)
(setq Ds_rl (get_tile "DW_LST") Ad_ls nil tmp_l nil)
(while (/= Ds_rl "")
(setq Ad_ls (cons (atoi Ds_rl) Ad_ls)
Ds_rl (vl-string-left-trim (strcat " "(itoa (atoi Ds_rl))) Ds_rl))
)
(foreach & Ad_ls
(setq tmp_l (cons (nth & ftl_) tmp_l))
(setq ftl_ (vl-remove (nth & ftl_) ftl_)))
(set (setq cc (read (strcat (nth ds_pst Dsc_l) "ls"))) tmp_l)
(start_list "DW_LST")(mapcar 'add_list ftl_)(end_list)
)
Not good.... the codes are just too long
so now you came up with the $key .... that did the trick
thanks buddy
btw here's the missing variable Dsc_l
(setq Dsc_l '("CVL_" "ARCHL_" "STCL_" "ELCTL_" "MECH_" "PLMBG_" "GENR_"))
Thanks Lee for the DCL pattern...
good catch roy_043
first post updated