Author Topic: Insert block from image button_problem  (Read 1736 times)

0 Members and 1 Guest are viewing this topic.

PPETROS

  • Newt
  • Posts: 27
Insert block from image button_problem
« 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

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Insert block from image button_problem
« Reply #1 on: December 21, 2020, 07:57:12 AM »
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.
Code: [Select]
(action_tile "VALVE" ...)is not the same as:
Code: [Select]
(action_tile "Valve" ...)
Additionally:
I would look at making the code more efficient and logical:
Code: [Select]
'(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.
« Last Edit: December 21, 2020, 01:10:20 PM by roy_043 »

PPETROS

  • Newt
  • Posts: 27
Re: Insert block from image button_problem
« Reply #2 on: December 21, 2020, 08:24:08 AM »
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.

d2010

  • Bull Frog
  • Posts: 326
Re: Insert block from image button_problem
« Reply #3 on: December 21, 2020, 08:39:42 AM »
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.
« Last Edit: December 21, 2020, 09:25:12 AM by d2010 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Insert block from image button_problem
« Reply #4 on: December 21, 2020, 01:11:53 PM »
Here are the LSP and DCL with some modifications.

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Insert block from image button_problem
« Reply #5 on: December 21, 2020, 06:21:01 PM »
Roy has provided a good solution you can look at library approach 4x4 4x3 etc dcl that loads from a list of slds.

Code: [Select]

//  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;
}


Code: [Select]
;;;               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.
« Last Edit: December 21, 2020, 06:36:30 PM by BIGAL »
A man who never made a mistake never made anything

PPETROS

  • Newt
  • Posts: 27
Re: Insert block from image button_problem
« Reply #6 on: December 22, 2020, 03:45:32 AM »
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.