Jump to content

Click a Button, Perform an Action on the Drawing, and Return to the DCL


Recommended Posts

Posted

I have a question that has likely been answered before, but I couldn’t find it.

I want to click a button, select an entity in the drawing, get the distance, and then return to the dialog box with the information written in the edit_box. What’s the best way to do this? Could someone provide an example?

 

(defun c:OpenDCLDialog ( / dcl_id)
  (setq dcl_id (load_dialog "example_dialog.dcl"))
  (if (not (new_dialog "example_dialog" dcl_id))
    (exit)
  )  
  (action_tile "select_btn" "(done_dialog 2)")
  (action_tile "ok_btn" "(done_dialog 1)")
  (setq dclflag (start_dialog))
  (cond 
    ( (eq dclflag 2)
      (:select)
    )
    ((eq dclflag 2)
      (prompt "ok!")
    )
  )

  (unload_dialog dcl_id)

)

(defun :select ()
  (setq entity (car (entsel "\nSelect an entity: ")))
  (setq ponto (assoc 10 (entget entity)))
  (setq dist (getdist (cdr ponto) "Distance: "))
  ;;vou fazer algo aqui
)

;;(c:OpenDCLDialog)

 

 

example_dialog : dialog {
    label = "Entity Selection Example";
    
    : row {
        : edit_box {
            key = "distance";
            label = "Distance";
            edit_width = 25;
        }
    }

    : row {
        : button {
            key = "select_btn";
            label = "Select Entity";
        }
    }

    : row {
        : button {
            key = "ok_btn";
            label = "OK";
            is_default = true;
        }
        : button {
            key = "cancel_btn";
            label = "Cancel";
            is_cancel = true;
        }
    }
}

 

Posted (edited)

 

You are correct you have to close the dcl and reopen it. the key is distance so (set_tile "distance" dist)  the dist would be the object length as a string maybe need to check, when you start dcl the dist

(if (= dist nil)
(setq dist "0")
(setq dist (rtos len 2 2))
)
)  
(set_tile "distance" dist)
  (action_tile "select_btn" "(done_dialog 2)")

 

Edited by BIGAL
Posted

Hi

Use a while loop to re-open the dialog if "Select" button is picked.

 

Like this

(defun c:OpenDCLDialog ( / dcl_id dclflag dst) 
  (setq dclflag 2)
  (if
    (and
      (setq dcl_id (load_dialog "example_dialog.dcl"))
      (> dcl_id 0)
    )
    (progn
      (while
        (> dclflag 1)
        
        (new_dialog "example_dialog" dcl_id)
        (if dst (set_tile "distance" dst))
        (action_tile "distance" "(setq dst $value)")
        (action_tile "select_btn" "(done_dialog 2)")
        (action_tile "ok_btn" "(done_dialog 1)")
        (setq dclflag (start_dialog))
      
        (if
          (and
            (= dclflag 2)
            (setq dst (:select))
          )
          (setq dst (rtos dst))
        )
      );while
      
      (unload_dialog dcl_id)
      (if
        (= dclflag 1)
        (distof dst)
      )
    );progn
  )
)

(defun :select ()
  (setq entity (car (entsel "\nSelect an entity: ")))
  (setq ponto (assoc 10 (entget entity)))
  (setq dist (getdist (cdr ponto) "Distance: "))
  ;;vou fazer algo aqui
)

 

  • Thanks 1

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