Jump to content

i can't get the info out of a list.


patjeacad

Recommended Posts

On 9/10/2024 at 9:20 PM, rlx said:

can't fully test app without the blocks but try it now.

 

Only changed a few variable names so maybe working of program is a little clearer.

Also added a few extra princs for debug info. Those can be removed once app runs as expected.

 

🐉

 

(defun c:bout ( / *error* UpdateList data dcl-fn dcl-fp dcl-id drv M-pointer model S-pointer size selection)
  (defun *error* ( msg )
    (if dcl-id (unload_dialog dcl-id)) (if dcl-fp (close dcl-fp))
    (if (findfile dcl-fn)(vl-file-delete dcl-fn))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")(princ (strcat "\n** Error: " msg " **")))(princ)
  )
  (defun UpdateList ( key lst ) (start_list key)(mapcar 'add_list lst)(end_list))

  ;;; 3-zero fill (so "25" becomes "025")
  (defun 3ZFill (s) (while (> 3 (strlen s))(setq s (strcat "0" s))) s)
  (setq Data
   '(
     ("M4"  ("25" "30" "40"))
     ("M5"  ("30" "35" "40" "45" "50" "55" "60" "65" "70" "75" "80"))
     ("M6"  ("30" "35" "40" "45" "50" "55" "60" "65" "70" "75" "80"))
     ("M8"  ("35" "40" "45" "50" "55" "60" "65" "70" "75" "80" "90" "100" "110" "120" "140" "150" "160" "180" "200"))
     ("M10" ("45" "50" "55" "60" "65" "70" "75" "80" "90" "100" "110" "120" "140" "150" "160" "180" "200"))
     ("M12" ("45" "50" "55" "60" "65" "70" "75" "80" "100" "110" "120" "140" "150" "160" "180" "200")) 
     ("M14" ("50" "55" "60" "65" "70" "75" "80" "100" "110" "120" "140" "150" "160" "180" "200")) 
     ("M16" ("50" "55" "60" "65" "70" "75" "80" "100" "110" "120" "140" "150" "160" "180" "200")) 	 
    )
  )

  ;;; setup dialog
  (create_bout_dialog)
  (cond
    ((<= (setq dcl-id (load_dialog dcl-fn)) 0) (princ "\n--> DCL File not Found."))
    ((not (new_dialog "bout" dcl-id))
     (setq dcl-id (unload_dialog dcl-id)) (princ "\n--> Dialog Definition not Found."))
    (t
     (or M-pointer  (setq M-pointer  "0"))
     (or S-pointer (setq S-pointer "0"))
     (UpdateList "lst1" (mapcar 'car Data))
     (set_tile "lst1" M-pointer)
     (UpdateList "lst2" (cadr (nth (atoi S-pointer) Data)))
     (set_tile "lst2" S-pointer)
     (action_tile "lst1"
       (strcat
         "(UpdateList \"lst2\" (setq lst2 (cadr (nth (atoi (setq M-pointer $value)) Data))))"
         "(setq S-pointer"
         "  (set_tile \"lst2\""
         "    (if (< (atoi S-pointer) (length lst2)) S-pointer \"0\")"
         "  )"
         ")"
       )
     )
     (action_tile "lst2" "(setq S-pointer $value)")
     (action_tile "cancel" "(done_dialog 0)")
     (action_tile "accept" "(done_dialog 1)")
     (setq drv (start_dialog))
     (setq dcl-id (unload_dialog dcl-id))
     (if (findfile dcl-fn)(vl-file-delete dcl-fn))
    )
  )
  (if (= drv 1)
    (progn
      (setq selection (nth (atoi M-pointer) Data))
      ;;; testing only
      (princ (strcat "\nSelection : " (vl-princ-to-string selection)
         "\nM-pointer : " (vl-princ-to-string M-pointer) " S-ppointer : " (vl-princ-to-string S-pointer)))
      (setq model (car selection))
      (setq size (nth (atoi M-pointer) (cadr selection)))
      (cond
        ((eq model "M4") (setq WTBSYB (strcat "DIN931-A0M04x" (3ZFill size) "E")) (WTBSB))
        ((eq model "M5") (setq WTBSYB (strcat "DIN931-A0M05x" (3ZFill size) "E")) (WTBSB))
        ((eq model "M6") (setq WTBSYB (strcat "DIN931-A0M06x" (3ZFill size) "E")) (WTBSB))
        ((eq model "M8") (setq WTBSYB (strcat "DIN931-A0M08x" (3ZFill size) "E")) (WTBSB))
        ((eq model "M10")(setq WTBSYB (strcat "DIN931-A0M10x" (3ZFill size) "E")) (WTBSB))
        ((eq model "M12")(setq WTBSYB (strcat "DIN931-A0M12x" (3ZFill size) "E")) (WTBSB))
        ((eq model "M14")(setq WTBSYB (strcat "DIN931-A0M14x" (3ZFill size) "E")) (WTBSB))
        ((eq model "M16")(setq WTBSYB (strcat "DIN931-A0M16x" (3ZFill size) "E")) (WTBSB))
        (t (alert (strcat "Unknow combination :\nModel = " (vl-princ-to-string model) "\nsize = " (vl-princ-to-string size))))
      )
    )
  )
  (princ)
)

(defun wtbsb ( / old-cmdecho old-layer ip )
  (setq old-cmdecho (getvar "cmdecho")) (setvar "cmdecho" 0)
  (setq old-layer (getvar "clayer"))
  (if (not (tblsearch "layer" "03_geometrie_050"))
    (progn
      (command "layer" "m" "03_geometrie_050" "c" "7" "" "l" "continuous" "" "")
      (command "layer" "s" "03_geometrie_050" "")
    )
  )
  (cond
    ((or (null WTBSYB) (not (eq (type WTBSYB) 'STR)) (not (findfile (strcat WTBSYB ".dwg"))))
     (alert (strcat "Computer says no - bad or missing blockname : " (vl-princ-to-string WTBSYB))))
    ((not (setq ip (getpoint "\nGeef invoegpunt     : ")))
     (alert "Block insertion aborted"))
    (t (command "-insert" WTBSYB ip "" "" pause))
  )
  (setvar "clayer" old-layer)
  (setvar "cmdecho" old-cmdecho)
  (princ) 
)


;;; create the dialog on run-time
(defun create_bout_dialog ()
  (if (and (setq dcl-fn (vl-filename-mktemp "bout.dcl")) (setq dcl-fp (open dcl-fn "w")))
    (mapcar
      '(lambda (x)(write-line x dcl-fp))
       (list
         "lbox : list_box {width=25;fixed_width=true;alignment=centered;}"
         "bout : dialog { label =\"bout\"; spacer;"
         ":column {"
         "  :row {label = \"Materiaal :\" ;"
             ": radio_button {label=\"Gegalvaniseerd 8.8\";key=\"A0\";value=1;}"
		": radio_button {label=\"RVS A2\"; key=\"A2\";}"
		": radio_button {label=\"RVS A4\"; key=\"A4\";}"
           "}"
           ":spacer { width=1;}"
           ":row {label=\"Aanzicht :\";"
             ": radio_button {label=\"Zijaanzicht\";key=\"zijaanz\";value=1;}"
             ": radio_button {label=\"Doorsnede\";key=\"doorsn\";}"
           "}"
           ":spacer {width=1;}"
           ": row {"
             ": lbox {key=\"lst1\";label=\"size\";}"
             ": lbox {key=\"lst2\";label=\"Model\";}"
           "}"
         "}"
         "ok_cancel;"
         "}"
       )
    )
  )
  (if dcl-fp (close dcl-fp))(gc)
)

 

Hi RLX, the debug info works. when i insert for example a M4-25 that is 0-0 it works. When i insert M4-35 that is 0-2 not the corrst block inserts, it inserts 0-0. only the first insert of Mx works, the second with different length is the same as the first. I can sent some blocks if you want to. zipfile?

Link to comment
Share on other sites

I think that's the working of the program. Say you click on M3 , this has I believe 3 sizes in the right list box. When you then click on one with more sizes it tries to put the right side pointer also on the same size. But reversed, when you first click on lets say M10 and size 70 and afther that you click on M3 , this had no size 70 and so pointer will be reset to zero.

Link to comment
Share on other sites

1 hour ago, rlx said:

I think that's the working of the program. Say you click on M3 , this has I believe 3 sizes in the right list box. When you then click on one with more sizes it tries to put the right side pointer also on the same size. But reversed, when you first click on lets say M10 and size 70 and afther that you click on M3 , this had no size 70 and so pointer will be reset to zero.

Yes that is correct. Only when i need first a M4 - 25 lenght and after that i need a M4 - 35 it shows het right numbers at the control you build in. it inserts the same as the first one not a different lenght. So the first list is ok. the second list is different than the control numbers.

Link to comment
Share on other sites

I changed the listbox actions in a way I would expect it to work if I wrote this for me , myself & I. Rather looking @ the pointer position (bout2.lsp)  I look at the size itself (bout3.lsp). So if I select size 60 and then select another model , I don't set size pointer to the previous pointer position (and possibly end up with another size) but I try to find if the new model also has size 60 and set pointer to this posistion and if new model doesn't have this size then I set it to zero (the first size in the listbox)

 

🐉

 

 

bout2.lsp bout3.lsp

Edited by rlx
Link to comment
Share on other sites

@rlx I needed to save some values in a dwg so use Ldata so could do M4=60, M6=70 and so on, save the last value for each size separately. If no value then set value to the smallest value. Like you in my dcl's can save a Button number rather than actual size. 

Maybe do a defun as first step check all ldata exists and if not set to button 1. 

 

(if (= (vlax-ldata-get "Bolts" "M4") nil)
(setq m4but 1)
)
and each pick
(vlax-ldata-put "Bolts" "M4" m4but)

 

  • Like 1
Link to comment
Share on other sites

I'm gonna be totally honest with you bigal, I've never used ldata before  I know it exists and somewhat what it does but so far never felt the need to dig deeper into this so on this area you're way ahead of me 🤓

Link to comment
Share on other sites

I think you can do it here. 

(alert
        (strcat "\nSelection : " (vl-princ-to-string selection)
         "\nM-pointer : " (vl-princ-to-string M-pointer) " S-pointer : " (vl-princ-to-string S-pointer)
         "\nModel : " (vl-princ-to-string model) " , size : " (vl-princ-to-string size)
        )
      )
	  (dosavesize model size)

 

Need to think about (defun dosavesize.... as I mentioned before I use the order value in the list to set the default size as current. I need to find set the item in the list box as current. Eg M8 45 highlighted.

 

Found something 

(Set_tile key "0") is 1st value in the list.

Ok in your code just change the "0" to correct last chosen

(setq M-pointer  "0" S-pointer "0" selection (nth (atoi M-pointer) Data)

(if (= M-pointer  Nil)(check ldata here or else set to "0"))

 

 

Edited by BIGAL
Link to comment
Share on other sites

10 hours ago, rlx said:

I changed the listbox actions in a way I would expect it to work if I wrote this for me , myself & I. Rather looking @ the pointer position (bout2.lsp)  I look at the size itself (bout3.lsp). So if I select size 60 and then select another model , I don't set size pointer to the previous pointer position (and possibly end up with another size) but I try to find if the new model also has size 60 and set pointer to this posistion and if new model doesn't have this size then I set it to zero (the first size in the listbox)

 

🐉

 

 

bout2.lsp 5.97 kB · 1 download bout3.lsp 6.15 kB · 0 downloads

Thanks RLX. It works perfect now. al blocks i select are fount and correct for insert. I hava a nice working example for the other bolts a wil use in my bolt library

Many thanks for your time, also for all how spend some time to help me with this issue. 

Regards PAtrick

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