chornyak Posted September 5, 2022 Posted September 5, 2022 I am making a LISP to make subgroups of data. It sums up the attribute values of the blocks and makes groups as large as possible without going over the maximum group size. This is working okay, until it gets to the last group. I can't figure out how to exit while loop correctly. In this example dwg, the command to run is BLOCKDATA, select the one polyline in the middle of the drawing, then enter 9 as the max size. The correct output should be this when the while loop is fixed: group 1: ((3 1714232.9299 658479.2016) (3 1714251.5199 658479.2016) (3 1714270.1099 658479.2016)) group 2: ((3 1714288.6999 658479.2016) (3 1714307.2899 658479.2016) (3 1714325.8799 658479.2016)) group 3: ((3 1714344.4699 658479.2016)) Any help would be appreciated. The pertinent lines to this question are line 54 to the end, thanks. blockdata.lsp blockdata.dwg Quote
mhupp Posted September 6, 2022 Posted September 6, 2022 Can you post what alldata_trackers_sorted looks like. Quote
chornyak Posted September 6, 2022 Author Posted September 6, 2022 ((3 1714232.9299 658479.2016) (3 1714251.5199 658479.2016) (3 1714270.1099 658479.2016) (3 1714288.6999 658479.2016) (3 1714307.2899 658479.2016) (3 1714325.8799 658479.2016) (3 1714344.4699 658479.2016)) Quote
mhupp Posted September 6, 2022 Posted September 6, 2022 (edited) You need to stop the first while 1 loop early. and it will fix the last group error (while (> (length alldata_trackers_sorted) 1) when on the last group this will set alldata_trackers_sorted to nil (setq alldata_trackers_sorted (cdr alldata_trackers_sorted)) So when the next loop comes around you can't add string_cout to nil this is where it errors while (<= (setq string_count (+ string_count (caar alldata_trackers_sorted))) *max_strings*) You also keep resetting subarry_list each loop so it will only display the last group of alldata_trackers_sorted. when you do (print subarray_list) --edit maybe (while (> (length alldata_trackers_sorted) 1) (setq subarray_list (car alldata_trackers_sorted)) (repeat (if (> (length subarray_list) *max_strings*) (- *max_strings* (length subarray_list)) 0) (setq subarray_list (vl-remove (last subarray_list) subarray_list)) ) (setq lst (cons subarray_list lst)) ) (setq lst (reverse lst)) (print lst) (princ) ) Edited September 6, 2022 by mhupp Quote
Recommended Posts
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.