Squirltech Posted March 20, 2017 Posted March 20, 2017 In the survey business, here in Texas anyway, we do LOTS of record information ( ) and adjoiner record information [ ]. I'm trying to either create a table, in the general format shown in the image attached BUT I'd like the order of the line numbers to be L1, then (L1), then [L1] (if applicable), so on and so forth. Currently I only have the option to sort data based on ascending or descending. I've looked in all of the table options and I'm not seeing anything that will allow me to do this. Any help is appreciated. Thanks! T Quote
BIGAL Posted March 21, 2017 Posted March 21, 2017 A crude way may be to read the table into a list and hopefully Lee will read this and sort the list recognising the "(alpha" v's "alpha". Then rewrite the table in the new order. It may need a non display character so like above you have 3 characters to sort on. Quote
Squirltech Posted March 21, 2017 Author Posted March 21, 2017 This is what I was thinking too but I have no clue how to make it happen. Maybe a column on the left that is used for sorting only. A dynamic block perhaps? Quote
welldriller Posted March 23, 2017 Posted March 23, 2017 In the survey business, here in Texas anyway, we do LOTS of record information ( ) and adjoiner record information [ ]. I'm trying to either create a table, in the general format shown in the image attached BUT I'd like the order of the line numbers to be L1, then (L1), then [L1] (if applicable), so on and so forth. Currently I only have the option to sort data based on ascending or descending. I've looked in all of the table options and I'm not seeing anything that will allow me to do this. Any help is appreciated.Thanks! Could you possible do the in Excel. Then you can accomplish what you are trying to do. Quote
BIGAL Posted March 23, 2017 Posted March 23, 2017 Weldriller try a sort on column A with (a7) 2 a3 (a6) I will save the suspense does not work thats what I tried 1st. Lee where are you your the only master I know that can possibly work this out, yes may need a hidden character for (a1) v's a1 Quote
SLW210 Posted March 23, 2017 Posted March 23, 2017 I moved your thread to the AutoLISP, Visual LISP & DCL Forum, maybe you'll get some solutions here. Quote
Lee Mac Posted March 23, 2017 Posted March 23, 2017 OK Al, you got my attention I'm not sure of the intended sort order, but the following function demonstrates a sorting method: (defun surveysort-i ( lst ) (vl-sort-i (mapcar 'strcase lst) (function (lambda ( a b / x y ) (setq x (ascii a) y (ascii b) ) (cond ( (or (= 91 x y) (= 40 x y) (and (not (or (= 40 x) (= 91 x))) (not (or (= 40 y) (= 91 y))) ) ) (< (vl-string-trim "()[]" a) (vl-string-trim "()[]" b)) ) ( (not (or (= 40 x) (= 91 x)))) ( (not (or (= 40 y) (= 91 y))) nil) ( (= 40 x)) ) ) ) ) ) Example: _$ (setq lst '("L3" "[A1]" "[b1]" "(L1)" "B2" "[A2]" "(A1)" "L1" "(B1)" "A1")) _$ (mapcar '(lambda ( n ) (nth n lst)) (surveysort-i lst)) ("A1" "B2" "L1" "L3" "(A1)" "(B1)" "(L1)" "[A1]" "[A2]" "[b1]") The current code will still have problems with sorting "L1" and "L10", but it demonstrates the concept. Quote
BIGAL Posted March 23, 2017 Posted March 23, 2017 Thanks Lee thats a lot closer, at least now you have a sorted list and I would rewrite the whole table as I suggested in my 1st post comparing two lists the sorted as per Lee and the table entries ("A1" "B2" "L1" "L3" "(A1)" "(B1)" "(L1)" "[A1]" "[A2]" "[b1]") ("A1" "N23" "12" "32" "E" "401.123" "B2" "N31" "23'" "45" "E" "104.256".......... Quote
Lee Mac Posted March 24, 2017 Posted March 24, 2017 No need for the list comparison as the sorting function I propose uses vl-sort-i and so the indexes of the repositioned items are already known - I wanted to confirm the sort order before going any further with the example however. Quote
BIGAL Posted March 24, 2017 Posted March 24, 2017 Thanks Lee you must be up late reading this post now. Quote
Roy_043 Posted March 24, 2017 Posted March 24, 2017 But maybe the OP wants this order?: ("A1" "(A1)" "[A1]" "[A2]" "(B1)" "[b1]" "B2" "L1" "(L1)" "L3") Quote
Lee Mac Posted March 24, 2017 Posted March 24, 2017 But maybe the OP wants this order?: ("A1" "(A1)" "[A1]" "[A2]" "(B1)" "[b1]" "B2" "L1" "(L1)" "L3") This is what I wanted to clarify before moving any further. Quote
Squirltech Posted March 24, 2017 Author Posted March 24, 2017 Thanks guys for your help. The order I'm looking for is: A1, (A1), [A1], B2, (B2), [b2], etc The table image shown in the original post gives an idea of what I'm dealing with using a LINE TABLE from Civil3d. When doing a parcel the user has the bearing & distance (B/D) of the subject line, the record B/D of the subject parcel ( ) and then the record B/D of the adjoining parcel [ ]. So when sorted, I'd like to have the first line number be without parenthesis or brackets, the next with parenthesis and the next with brackets, then that same order repeated for the next line number(s). T Quote
Lee Mac Posted March 24, 2017 Posted March 24, 2017 The order I'm looking for is: A1, (A1), [A1], B2, (B2), [b2], etc Thanks - here is a refinement of my earlier function to yield the required sort order: (defun surveysort-i ( lst ) (vl-sort-i (mapcar 'strcase lst) (function (lambda ( a b / x y ) (setq x (ascii a) y (ascii b) ) (if (= (vl-string-trim "()[]" a) (vl-string-trim "()[]" b)) (cond ( (not (or (= 40 x) (= 91 x)))) ( (not (or (= 40 y) (= 91 y))) nil) ( (= 40 x)) ) (< (vl-string-trim "()[]" a) (vl-string-trim "()[]" b)) ) ) ) ) ) Alternatively, using wcmatch: (defun surveysort-i ( lst ) (vl-sort-i (mapcar 'strcase lst) (function (lambda ( a b / x y ) (if (= (setq x (vl-string-trim "()[]" a)) (setq y (vl-string-trim "()[]" b))) (cond ( (wcmatch a "[~[(]*[~])]")) ( (wcmatch b "[~[(]*[~])]") nil) ( (wcmatch a "(*)")) ) (< x y) ) ) ) ) ) Example: _$ (setq lst '("L3" "[A1]" "[b1]" "(L1)" "B2" "[A2]" "(A1)" "L1" "(B1)" "A1")) ("L3" "[A1]" "[b1]" "(L1)" "B2" "[A2]" "(A1)" "L1" "(B1)" "A1") _$ (mapcar '(lambda ( n ) (nth n lst)) (surveysort-i lst)) ("A1" "(A1)" "[A1]" "[A2]" "(B1)" "[b1]" "B2" "L1" "(L1)" "L3") The table image shown in the original post gives an idea of what I'm dealing with using a LINE TABLE from Civil3d. Is a 'Line Table' a type of object native to Civil 3D? Or does it appear as a standard AutoCAD table and 'Line Table' describes the table content in this context? Are you able to upload a sample drawing containing a typical example of such a table? Quote
Grrr Posted March 24, 2017 Posted March 24, 2017 Very impressive work, Lee! I say so, because I don't understand a thing in these codes - some spare time will be required for analysing. Quote
Roy_043 Posted March 24, 2017 Posted March 24, 2017 Or: (defun surveysort-i (lst) (vl-sort-i (mapcar 'strcase lst) (function (lambda (a b) (< (vl-string-left-trim "([" a) (vl-string-left-trim "([" b)) ) ) ) ) Quote
Roy_043 Posted March 24, 2017 Posted March 24, 2017 Or (better): (defun surveysort-i (lst) (vl-sort-i (mapcar '(lambda (str) (strcase (vl-string-left-trim "([" str))) lst) '< ) ) Quote
Grrr Posted March 24, 2017 Posted March 24, 2017 The second is a good one, Roy. I remember once I used something like your first code (but with vl-sort). With vl-sort-i and the technque you demonstrate on the second code - my guess is that it should be alot faster. Quote
Lee Mac Posted March 24, 2017 Posted March 24, 2017 A nice idea Roy, but those methods rely on the codes (A1, A2 etc.) always being two characters, as (ascii ")") Quote
Roy_043 Posted March 25, 2017 Posted March 25, 2017 @Lee: You are right: (setq lst '("L3" "A10" "[A10]" "[b1]" "(L1)" "(A1)" "B2" "[A2]" "(A10)" "[A1]" "L1" "(B1)" "A1")) (mapcar '(lambda ( n ) (nth n lst)) (roy-surveysort-i lst)) => ("A1" "(A1)" "A10" "(A10)" "[A10]" [b][color=red]"[A1]"[/color][/b] "[A2]" "(B1)" "[b1]" "B2" "L1" "(L1)" "L3") 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.