Jump to content

Please Help Me! Create Mleader from DCL and TXT


Kvlar

Recommended Posts

Posted (edited)

hi, I have managed to fix the code error before. The problem now is that I can't change the value in the DCL input box.

Maybe you can help me, this is the code I use

 

   (setq dcl_file (open (setq tmp-dcl-file-name (vl-filename-mktemp nil nil  ".DCL")) "w"))
              (progn
                 (foreach x 
                   '(  

                     "ROOMNAME : dialog {"  
                     "          label = \"testing\";          "  
                     "          : column {"  
                     "            : row {"  
                     "              : boxed_column {"  
                     "               : list_box {                  "  
                     "                  label =\"Select\";"  
                     "                  key = \"mylist\";"  
                     "                  height = 10;"  
                     "                  width = 30;"  
                     "                  multiple_select = false;   "  
                     "                  value = \"\";"  
                     "                }"  
                     "              }"  
                     "            }"  
                     "	    : edit_box {"  
                     "              label = \"Input : \";"  
                     "	      key = \"userinput\";"  
                     "              edit_width = 20;"  
                     "	      value = \"FFL \\U+00B1 0.00\";"  
                     "                  }"  
                     "            : row {"  
                     "              : boxed_row {"  
                     "                : button {"  
                     "                  key = \"accept\";"  
                     "                  label = \" Select \";"  
                     "                  is_default = true;"  
                     "                }"  
                     "                : button {"  
                     "                  key = \"cancel\";"  
                     "                  label = \" Cancel \";"  
                     "                  is_default = false;"  
                     "                  is_cancel = true;"  
                     "                }"  
                     "              }"  
                     "            }"  
                     "          }"  
                     "}"  
     ) (write-line x dcl_file) )
     (setq dcl_file (close dcl_file)))

  (setq elev(get_tile "userinput"))

(defun C:RN()
 (if (setq fname (findfile "list bigal.txt"))
   (progn
     (setq file (open fname "r")
    l nil)
     (while (setq line (read-line file))
       (setq l (append l (list line)))
     )
     (close file)

     (setq i (load_dialog tmp-dcl-file-name))
     (if (not (new_dialog "ROOMMAME" i)) (exit))

     (setq elev(get_tile "userinput"))

          (start_list "mylist" 3)
          (mapcar 'add_list l)
          (end_list)

          (setq rtn (set_tile "list" "0"))
          (action_tile "list" "(setq rtn $value)")
          (action_tile "accept" "(setq I (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"myIist\") \")\")))) (done_dialog)") ;; |JH| Line added
          (start_dialog)
          (unload_dialog i)

            (foreach room I
	      (setq p1(getpoint "\nSelect a point:"))

	      (setq oAttreq(getvar 'attreq))
	      (setq oAttdia(getvar 'attdia))
	  
    	      (setvar 'attreq 1)
           	      (setvar 'attdia 0)

	      (command "-INSERT" "floorplan" p1 1 1 0 eIev room)

	      (setvar 'attreq oAttreq)
	      (setvar 'attdia oAttdia)
            )
          )       
        )
      )
    )
  )

  (princ)

)

 

Edited by Kvlar
Link to comment
Share on other sites

@Kvlar First, check your parenthesis - you have way too many closing in the RN command.

 

2nd: You have an extra (setq elev (get_tile "userinput")) outside the function that will crash on loading.

 

3rd: you need to have to add and (action_tile) statement to the code to get the value when it changes:

(action_tile "userinput" "(setq elev $value)")

 

4th: you set the "multiple_select" attribute in the DCL to "false", which makes all the list parsing code you are using useless, as you don't need to parse out multiple selected items. You could make the code much simpler.

Change:

(action_tile "accept" "(setq l (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"mylist\") \")\")))) (done_dialog)") ;; |JH| Line added

TO:

(action_tile "accept" "(setq room (nth (atoi rtn) l)) (done_dialog)")

Then remove the loop (foreach room l ... ) and just call the stuff inside it once.

Of course, you could just set "multiple_select" back to "true" and still use it with the original code. 

 

5th: you haven't changed the (set_tile) statements from "list" to the correct key of "mylist", as I explained before. Did you study the code I sent you previously?

(set_tile "mylist" (setq rtn "0"))
(action_tile "mylist" "(setq rtn $value)")

These set_tile statements and the rtn variable are not needed if, as I stated above, you set "multiple_select" to "true", because Jonathon's code reads the value of "mylist" directly.

 

6th: you should write the DCL code with a function instead of at load, then delete the DCL afterwards from the system TEMP folder. Paste (startapp "explorer.exe" (getvar "tempprefix")) at the command line, and look in the folder it brings up right now - I bet you have a whole bunch of randomly named DCL files in there just building up.

 

Again, I have attached my version of your code for you to study.

 

 

 

 

 

 

 

 

Test_RN.lsp

Edited by pkenewell
Link to comment
Share on other sites

@Kvlar Just FYI - I have been editing my post above just in case you looked at it. I made some mistakes in my first draft and corrected them. If you are having problems still, check to make sure on the time of my last post edit. 😜

 

EDIT: My last edit again - updated above. I need to test code more thoroughly before posting LOL.

 

I hope my post above is not too confusing. I am trying to help you understand what the code does.

Edited by pkenewell
  • Like 1
Link to comment
Share on other sites

2 hours ago, pkenewell said:

@Kvlar First, check your parenthesis - you have way too many closing in the RN command.

 

To add to this, over about 6 lines my head spins around a little so I tend to always note what the closing brackets are for which really helps. Also when building the code I'll add the closing bracket straight after with the note to keep the order right. Same applies with DCL codes

 

Simple example by way of explanation, a silly routine.

;;1.:

(setq acount 0)
(while (< acount 10)
                
                
) ;; end while
                
                
                
2.:

(setq acount 0)
(while (< acount 10)
  (if (= acount 5)


  ) ; end if

  (setq acount (+ acount 1))                
) ;; end while




3.:

(setq acount 0)
(while (< acount 10)
  (if (= acount 5)
    (progn
      (princ "Thats 5!")                
    ) ; end progn
    (progn

    ) ; end progn
  ) ; end if

  (setq acount (+ acount 1))                
) ;; end while
                
                
                
                
                
4.:

(setq acount 0)
(while (< acount 10)
  (if (= acount 5)
    (progn
      (princ "\nThats 5!")
    ) ; end progn
    (progn
        (princ (strcat
            "\n"
            (rtos acount 2 2)
            " isn't 5"
        )) ; end strcat, end princ
    ) ; end progn
  ) ; end if

  (setq acount (+ acount 1))
) ;; end while

 

 

  • Agree 1
Link to comment
Share on other sites

8 hours ago, pkenewell said:

@Kvlar First, check your parenthesis - you have way too many closing in the RN command.

 

2nd: You have an extra (setq elev (get_tile "userinput")) outside the function that will crash on loading.

 

3rd: you need to have to add and (action_tile) statement to the code to get the value when it changes:

(action_tile "userinput" "(setq elev $value)")

 

4th: you set the "multiple_select" attribute in the DCL to "false", which makes all the list parsing code you are using useless, as you don't need to parse out multiple selected items. You could make the code much simpler.

Change:

(action_tile "accept" "(setq l (mapcar '(lambda (x) (nth x l)) (read (strcat \"(\" (get_tile \"mylist\") \")\")))) (done_dialog)") ;; |JH| Line added

TO:

(action_tile "accept" "(setq room (nth (atoi rtn) l)) (done_dialog)")

Then remove the loop (foreach room l ... ) and just call the stuff inside it once.

Of course, you could just set "multiple_select" back to "true" and still use it with the original code. 

 

5th: you haven't changed the (set_tile) statements from "list" to the correct key of "mylist", as I explained before. Did you study the code I sent you previously?

(set_tile "mylist" (setq rtn "0"))
(action_tile "mylist" "(setq rtn $value)")

These set_tile statements and the rtn variable are not needed if, as I stated above, you set "multiple_select" to "true", because Jonathon's code reads the value of "mylist" directly.

 

6th: you should write the DCL code with a function instead of at load, then delete the DCL afterwards from the system TEMP folder. Paste (startapp "explorer.exe" (getvar "tempprefix")) at the command line, and look in the folder it brings up right now - I bet you have a whole bunch of randomly named DCL files in there just building up.

 

Again, I have attached my version of your code for you to study.

 

 

 

 

 

 

 

 

Test_RN.lsp 3.91 kB · 5 downloads

Wow, thank you very much.
I already understand which parts I need to change and what I need to improve.
Now the code is working as I expected

  • Like 1
Link to comment
Share on other sites

Posted (edited)

my problem has been resolved. Thank you to all of you

Edited by Kvlar
  • Like 2
Link to comment
Share on other sites

Posted (edited)

my problem has been resolved. Thank you to all of you

Edited by Kvlar
  • Like 1
Link to comment
Share on other sites

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