Jump to content

DCL - load next number value into box


Recommended Posts

Posted

Recently I started learning DCL dialogs and so far I figured out everything I needed but this one I can't, so maybe someone here can help me. Its a simplified example of a much longer code, so I'll just post this part that is bothering me.

I have a lot of blocks that have numeric label attribute values, hundreds of them but not all numbers are used (example of labels: 10, 11, 12, 14, 15, 17). I would want a lisp that is asking me to either put a number by keyboard or I could press LOAD button and it would put the next available number in text box (from previous example, by pressing LOAD it would write number 18 and by OK it would start inserting blocks with number 18). So what would be the best solutions to this problem?


Here is what I have so far

Lisp part:

(defun c:test6 ()
  (setq dcl (load_dialog "test6.dcl"))
  (new_dialog "test6" dcl)
  (set_tile "number" "")
  (action_tile "number" "(setq maxnmbr $value)")
  (start_dialog)
  (unload_dialog dcl)
  (setq count (atoi maxnmbr))
  (while (setq pt (getpoint))
  (command "-insert" "label" pt 1 1 0 count)
  (setq count (1+ count)))
 );defun


DCL part:
 

test6 : dialog {
	: column {
	: row {
        : edit_box {
          key = "number" ;
          edit_width = 15;
          fixed_width = true;}
	    : button {label = "Load";
	      key = "load";
	      width = 12;}}
	: row {
	    : button {label = "OK";
	      key = "accept";
	      alignment = left; width = 12;
		  is_default = true;}}}}

 

Posted

And I just noticed typo in the title of this topic, don't know how or if I can change it or not, but if someone can please change DLC to DCL 😀

Posted (edited)

When you (set_tile "number" "") why would number not be a value ? In my dcl's if number = nil set it to a value, for you a 2nd "if" would be find last number used if and then if still nil then number would be 1. You know block name "label" so ssget "X" and look at the attributes, use  a defun simpler to debug.

 

If need help post.

 

Ps have a look at Multi Radio Buttons.lsp in Downloads section it could be simply modified to have the choice for you.

 

image.png.264a07f10398ae0874470a2a04164564.png

 

 

 

 

Edited by BIGAL
Posted

@BIGAL thank you for reply, I will look into the lisp you mentioned. I probably should have said I'm not an expert in lisp, and even less in dcl. I strarted with it recently to make my job easier and now trying to learn new things and figure out how to implement them in lisp. I put (set_tile "number" "") because I want it to be empty field to enter a number. Sometimes I dont need next available 10 or so numbers so I just write what I need. That part is working but I'd like when I would press "Load" button, it would write next available number in the box so I can see what the next available is, and if its okay I would press ok and accept it. If not, I would edit it in the box by hand. So basically I could either write a new number for label, or by Load it would show me next available and write in the the box, and I could still change it if needed. I attached a photo where you can see it more clearly.

 

123.png

  • lastknownuser changed the title to DCL - load next number value into box
Posted (edited)

I think still much easier get last number and accept or change. Look at multi getvals.lsp.

 

The question I have is simple is the text on a layer with no other stuff then look at this yes change number. 

 

This is a sample code of a possible method.

 


;(setq ss (ssget "X" (list (cons 0 "Text")(cons 8 "Yourlayername"))))
(setq ss (ssget (list (cons 0 "Text"))))
(if (/= ss nil)
  (progn
    (setq lastnum 0)
    (repeat (setq x (sslength ss))
      (setq txt (cdr (assoc 1 (entget (ssname ss (setq x (- x 1)))))))
      (setq num (atoi txt))
      (if (> num lastnum)(setq lastnum num))
    )
  )
)

(setq lastnum (+ lastnum 1))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq lastnum (atoi (car (AH:getvalsm (list "Check number " "Next number" 5 4 (rtos lastnum 2 0))))))

; last num holds the answer

Multi GETVALS.lsp

 

Edited by BIGAL
Posted

I'm working with blocks here, so I need to compare the attributes values (10, 11, 12, 14, 15, 17), get the max value and then add +1 to show me the next available. That is the idea.

First thing, how can I determine the maximum attribute value? I know how to get attribute value as string, but don't know how to compare them to get maximum, any help on that for starters?

And then later, I would just like to know how to, using the dcl, load the max+1 number into that text box.

Posted

Here's part of my code for determining max value, and its not working, I'm getting the minimum value because of some reason.  "label" is string value of attribute LABEL from blocks.
Any help would be welcome?

 

(setq i 0 n (sslength sset))
(while (< i n)
(setq maxval 0)
(setq numlab (atof label))  
(if  (or (not maxval) (> numlab maxval))
(setq maxval numlab))
(setq i (1+ i))

 

Posted

Use this to get the max value ( assuming a list of strings )

(apply 'max (mapcar 'atof '("10" "11" "12" "14" "15" "17")))

 

Posted

Good to see you having a go

 

1 In the code example I posted look for  ssget so change "TEXT" to "INSERT" and add  (cons 2 yourblockname)

 

2 So now you have all the blocks with the same name in a selection set

 

3 Search here get textstring from block attribute using tag name 

 

4 Modify my code. 

 

Posted (edited)

EDIT: I figured it out, how to select the max value! And now next thing, the main question, how to add it to text box with load button using dcl?

@ronjonp I need a max value of selection set of strings. How could I implement what you wrote for that?

@BIGAL My ssget is next: (setq sset (ssget "A" '((2 . "LABEL")))), I could add (cons 0 "INSERT") if its needed, and why its needed? I searched but couldn't find what you wrote or I didn't figure out what I needed to find. Any additional link for that?

My code is selecting first inserted block as the max (not the minimum value like I wrote in my last post). I don't understand why is that, since it should compare each label value from selection set (that is converted from string to real) and select the maximum value, but its not working, I'm doing something wrong.
I'm more familiar with other programming languages so the lisp is a bit difficult for me tu understand, any help welcome.
 

Edited by lastknownuser
I found the solution
Posted (edited)

(setq sset (ssget "A" '( (0 . "INSERT") (2 . "LABEL")))) 

 

Make a selection set of Blocks "INSERT" where block name is "LABEL" a good idea to do in correct sequence object/s 1st  then filters could add (8 . "layerxx") so blocks only on 1 layer.

 

Google ssget help Autocad etc also Lee-mac.com has a good explanation about ssget.

Edited by BIGAL
Posted

Bump for any kind of help for loading variable into edit box?

By pressing load button I would want that the variable (in this case max+1) is just written in edit box. Don't know where to even start, I tried some things but nothing works. I looked for this kind of thing on afralisp and autolisp-exchange sites but didn't find this kind of example. I can't figure out how to put this condition, if button is pressed then do all that, determine max val and load into box.

 

Posted

Try this not sure what your tagname is for Label block, change code.

 

; https://www.cadtutor.net/forum/topic/73046-dcl-load-next-number-value-into-box/
; version by AlanH May  2021

(defun writedcl ( / fo) 
(if (= cnt nil)(setq cnt 1))
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line "test6 : dialog {" fo)
(write-line ": column { " fo)
(write-line ": row { " fo)
(write-line ": edit_box { " fo)
(write-line "key = \"number\" ; " fo)
(write-line "edit_width = 15 ; " fo)
(write-line "fixed_width = true ; } " fo)
(write-line ": button { label = \"Load\" ; " fo)
(write-line "key = \"load\" ; " fo)
(write-line "width = 12 ; }} " fo)
(write-line ": row { " fo)
(write-line ": button {label = \"OK\" ; " fo)
(write-line "key = \"accept\" ; " fo)
(write-line "alignment = left ; width = 12 ; " fo)
(write-line "is_default = true ; }}}} " fo)
(close fo)
(princ)
)

(defun resetnum ( / numl ss)
(setq numl 0)
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 "Label"))))
(repeat (setq x (sslength ss))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS (setq x (- x 1))) ) 'getattributes)
        (if (= tagname (vla-get-tagstring att))
        (princ (setq num (atoi (vla-get-textstring att))))
        )
)
(if (< maxnbr num)(setq maxnbr num))
)
(set_tile "number" (rtos maxnbr 2 0))
(princ)
)

(defun pickpt ( / pt )
(while (setq pt (getpoint "\nPick insertion point "))
  (command "-insert" "label" pt 1 1 0 (rtos maxnbr 2 0))
  (setq maxnbr (1+ maxnbr))
  )
  (princ)
)
  
(setq tagname "TAG1") ; for testing 

(defun c:test6 (  /  pt)
(if (= maxnbr nil)(setq maxnbr 1))
(writedcl)
(setq dcl_id (load_dialog fname))
  (if (not (new_dialog "test6" dcl_id))
  (exit)
  )
(set_tile "number" (rtos maxnbr 2 0))
(mode_tile "number" 3)
  (action_tile "number" "(setq maxnbr (atoi $value))")
  (action_tile "load" "(resetnum)")
  (action_tile "accept" "(unload_dialog dcl_id)")
  (start_dialog)
  (vl-file-delete fname)
(pickpt)
(princ)
)

(c:test6)

 

 

 

 

  • Like 1
Posted

@BIGAL Thanks a lot, it works! I actually only needed information about writing separate defun for next maximum number and that it is loaded with (action_tile "load" "(resetnum)"), but I will study your code to maybe improve mine.

Now I only have a little problem, because it loads the number into box but it doesnt select it unless I click inside the box, if you understand what I mean. So its an extra mouse click but sometimes you can forget, so I'd like for it to select whatever number is just loaded, shown inside the box, any way to achieve that?

Posted

It was doing that I will have to look again threw away test dwg. Maybe Mode_tile "number" 0. 

Posted

@BIGAL I did figure it out in the end, I had a typo at defining certain variable, corrected it and now it works fine all together. Thanks again for your time and help.

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