TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: PPETROS on December 21, 2020, 03:17:00 AM
-
Good morning to everyone,
I am trying to create a lisp routine with image_button for my blocks.
I tried a variety of solutions but every time the same issue appeared.
Always it stops when you pick in the slide (INSERT BLOCK TO THE SCREEN, do not work)
I would be grateful if someone can help me by fixing my issue (or have an idea how to do it)
In the attached lisp program.
Thank you all in advance
-
It is good to see a post from somebody who is actually trying to code. Thanks for that.
The cause of your issue:
Keys in DCL files are case-sensitive.
(action_tile "VALVE" ...)
is not the same as:
(action_tile "Valve" ...)
Additionally:
I would look at making the code more efficient and logical:
'(lambda (img-tile)
(slide_me img-tile (strcat img-tile ".sld"))
(action_tile img-tile "(setq bname $key) (done_dialog 2)")
)
EDIT: $key instead of img-tile.
-
I am thankful for your good sayings.
You are totally correct for the first comment. It works perfectly.
Because I am a beginner/ amateur coder can you help me by adding your last comment on the attached lisp routine and send it back.
Your help is much appreciated.
-
You have too many files.sld and every file.slide.sld have to a few lines.
That reason, you must convert all slide-sld-files to source-lisp-drawer, inside DCL-image.
:mrgreen:
Your help is much appreciated.
-
Here are the LSP and DCL with some modifications.
-
Roy has provided a good solution you can look at library approach 4x4 4x3 etc dcl that loads from a list of slds.
// DD3x3 dialogue. Used by the DD3x3 command in DD3x3.lsp.
// Called from the AutoCAD Release 12 Standard Menu.
dd3x3 : dialog {
label = "Please choose item";
: column {
: row {
: image_button {
key = "33sq1";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
: image_button {
key = "33sq2";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
: image_button {
key = "33sq3";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
}
: row {
: image_button {
key = "33sq4";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
: image_button {
key = "33sq5";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
: image_button {
key = "33sq6";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
}
: row {
: image_button {
key = "33sq7";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
: image_button {
key = "33sq8";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
: image_button {
key = "33sq9";
width = 10;
aspect_ratio = 1.0;
color = 0;
allow_accept = true;
}
}
}
ok_cancel;
}
;;; Uses DD3X3.DCL for the dialogue definition. The
;;; slide images are in list ai_pts_lst.120
; ctone is slb library name (tlds) is slide name in library
; use individual slide name if no library
(setq ai_pts_lst '("ctone(TLDS)" "ctone(dsdn)" "ctone(trds)"
"ctone(dsr)" "ca3blank" "ctone(DSL)"
"ctone(blds)" "ctone(dsup)" "ctone(brds)")
)
(setq ai_pts_lst2 '("33sq1" "33sq2" "33sq3" "33sq4" "33sq5" "33sq6""33sq7" "33sq8" "33sq9" ))
(defun sq_pick ()
(cond
((= ans "33sq1")(setq ang1 4.7125)(setq ang2 0.0)(tr))
((= ans "33sq2")(tm))
((= ans "33sq3")(setq ang1 3.1417)(setq ang2 4.7125)(tr))
((= ans "33sq4")(tm))
((= ans "33sq5")(princ "run other clean up"))
((= ans "33sq6")(tm))
((= ans "33sq7")(setq ang1 1.5708)(setq ang2 0.0)(tr))
((= ans "33sq8")(tm))
((= ans "33sq9")(setq ang1 1.5708)(setq ang2 3.1417)(tr))
)
)
; calculates next slide
(defun alan4 ()
(setq x (+ x 1))
(setq sldname (nth x ai_pts_lst))
)
; third step
; set up slide libraray
(defun ai_ptype_start ()
(setq x -1)
(foreach pts0 ai_pts_lst2
(alan4)
(start_image pts0)
(slide_image 0 0 (- (dimx_tile pts0) 1) (- (dimy_tile pts0) 1) sldname)
(end_image)
)
)
; this is second step
(defun ai_ptype_main (/ globals)
(ai_ptype_start)
;now check each sq if picked then run alan2
(foreach pd0 ai_pts_lst2
(action_tile pd0 "(done_dialog)(setq ans $key)")
)
(start_dialog)
)
; this is first step
(if (= w2 nil)(setw2))
(setq app "dd3x3.dcl")
(if (= id_3x3 nil)
(progn
(setq dcl_id (load_dialog app))
(setq id_3x3 dcl_id)
)
)
(if (not (new_dialog "dd3x3" id_3x3))
(exit))
(ai_ptype_main)
(sq_pick)
(setq *error* old_error old_error nil)
The code was written like 30 years ago that is R12 Autocad not 2012, I did not post code as would totally redo now to a single lsp that writes the dcl based on (dodcl 4 4 lst) ie a 4x4 image with a list "lst" same (dodcl 3 4 lst) so you decide size in code rather than writing multiple dcls.
(dodcl 3 3 ai_pt_lst)
Will add to the To do list.
-
Thank you all for the support.
Roy I am grateful your help and the code. It is far simpler and more logical.
I wish you all merry Christmas and a happy new year.