Lisp : Reorder a LIST containing multiple LISTS by the elements contained in the lists
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello world !
I'm having trouble sorting a list of layers names by the contents of said layers names.
Some context :
I have a modeless dialog in which I can create layers based on predetermined lists or text boxes.
The final goal is to extract information from the polylines of the created layers. Information contained in a legend.
What I would like is to sort my legend according to my "lists" "Type" and "Dalle/Slab" (see modeless form). So at the top i will have all the "Plancher" ones, then "Platelage"...
____________________________________________
I have looked at a few posts on this forum and others, about sorting lists containing lists. But nothing that sorts a list (A) containing lists (B) according to the contents of the lists (B). (if the content isnt numbers or "strings" where i can run a "basic" sort fonction)
Currently, I get my legend by running a loop on a list that contains all the layers of selected polylines. Inside my loop and with the help of Lee-Mac's code that allows me to transform a string into a list. I transform my layer name in several elements that I assign to different variables. "ACE-DQE_Level_Type_Slab_Thickness_Height_Support_Hatch". Those elements or variables i assign to my legend bloc and then increment my loop and run it again.
Before making my loop I would like to have my A list sorted by "Type" then by "Dalle/Slab" and finally by color.
The type sort order being (Plancher>Poutre>Rampe>...>Palier)
The slab sort order being (CEP>...)
The color sort order being (Bleu (5) > Rouge (1) > Vert (3)> ...).
(For the colors i need to retrieve the layer color with the string name X but i dont think it's an essential addition)
Being a beginner on the LISP language, openDCL I don't see how I could proceed in order to realize this.
If some of you can help me, even if it's only by giving me some ideas, I would be grateful.
(defun c:BetonCADLegende ( /)
(ACE:init)
(setvar "OSMODE" 0)
(setq ls (ACE:BetonCadMajSurface)) ;; I retrieve my list of layers
;; Thats's where i think i will reorder my layer list (ls)
(setvar "osmode" 8)
(setq pt (getpoint "\nPoint de départ de la nomenclature...")) ;;Starting point of the legend
(setq ix 0)
(repeat (length ls)
(setq nomcalque (car (nth ix ls)))
(setvar "clayer" nomcalque)
(setq vsurface (rtos (/ (cadr (nth ix ls)) 10000) 2 0))
(setq pt2 (list (+ 255 (car pt)) (- (cadr pt) 112.5)))
(command-s "rectangle" "H" "0" "L" "0" pt pt2)
(setq ent (entlast))
(if (vl-string-search "ACE-DQE" nomcalque)
(progn
(defun Str2Lst ( s d / p ) ;; LeeMac String to list
(if (setq p (vl-string-search d s))
(cons (substr s 1 p) (Str2Lst (substr s (+ p 1 (strlen d))) d)) (list s))
)
(setq CalqueLst (Str2Lst nomcalque "_"))
(setq T_Nvx (nth 1 CalqueLst))
(setq T_Type (nth 2 CalqueLst))
(setq T_Dalle (nth 3 CalqueLst))
(setq T_EP (vl-string-translate "." "," (nth 4 CalqueLst)))
(setq T_HT (vl-string-translate "." "," (nth 5 CalqueLst)))
(setq T_App (vl-string-translate "-" "/" (nth 6 CalqueLst)))
(setq T_Hatch (nth 7 CalqueLst))
)
)
(if (= T_Hatch "SOLID") (command "-hachures" "p" T_Hatch "s" ent "" ""))
(if (= T_Hatch "45") (command "-hachures" "p" "U" T_Hatch "30" "N" "s" ent "" "" ))
(if (= T_Hatch "135") (command "-hachures" "p" "U" T_Hatch "30" "N" "s" ent "" "" ))
(if (= T_Hatch "ZIGZAG") (command "-hachures" "p" T_Hatch "10" "0" "s" ent "" "" ))
(if (= T_Hatch "ANSI37") (command "-hachures" "p" T_Hatch "10" "0" "s" ent "" "" ))
(if (= T_Hatch "HONEY") (command "-hachures" "p" T_Hatch "10" "0" "s" ent "" "" ))
(if (= T_Hatch "AR-HBONE") (command "-hachures" "p" T_Hatch "0.5" "0" "s" ent "" "" ))
(setvar "attreq" 0)
(setq ptleg (list (+ 290 (car pt )) (cadr pt)))
(command "inserer" "NomenclatureBetonCad" ptleg "2" "2" "0")
(setq ent (entlast))
(setvar "attreq" 1)
(if
(and (= T_Type "Plancher") (= T_App "escalier"))
(ACE:BetonCadMajAtt ent "L1" (strcat "Fermeture d'escalier " T_Dalle))
(if
(and (= T_Type "Platelage") (= T_Dalle "circulation"))
(ACE:BetonCadMajAtt ent "L1" T_Type)
(ACE:BetonCadMajAtt ent "L1" (strcat T_Type " " T_Dalle))
)
)
(if
(and (= T_Type "Platelage") (= T_Dalle "support de banche"))
(ACE:BetonCadMajAtt ent "L2" (strcat "Banche HT: " T_EP))
(if
(or (= T_Type "Poutre") (and (= T_Type "Platelage") (= T_Dalle "poutre CEP")))
(ACE:BetonCadMajAtt ent "L2" (strcat "Section: " T_EP))
(ACE:BetonCadMajAtt ent "L2" (strcat "Epaisseur de dalle: " T_EP))
)
)
(if
(= T_App "réhausse")
(ACE:BetonCadMajAtt ent "L3" (strcat "Hauteur réhaussage: " T_HT))
(if
(= T_Type "Platelage")
(ACE:BetonCadMajAtt ent "L3" (strcat "Hauteur sous platelage: " T_HT))
(if
(= T_Type "Poutre")
(ACE:BetonCadMajAtt ent "L3" (strcat "Hauteur sous poutre: " T_HT))
(ACE:BetonCadMajAtt ent "L3" (strcat "Hauteur sous dalle: " T_HT))
)
)
)
(if
(= T_App "réhausse")
(ACE:BetonCadMajAtt ent "L4" "Réhaussage PH N-1")
(ACE:BetonCadMajAtt ent "L4" (strcat "Appui sur " T_App))
)
(if
(and (= T_Type "Poutre") (= T_Dalle "préfa"))
(ACE:BetonCadMajAtt ent "L5" (strcat "Quantité: " vsurface " ù"))
(if
(or (and (= T_Type "Poutre") (= T_Dalle "CEP")) (= T_Type "Casquette"))
(ACE:BetonCadMajAtt ent "L5" (strcat "Lineaire: " vsurface " ml"))
(ACE:BetonCadMajAtt ent "L5" (strcat "Surface: " vsurface " m²"))
)
)
(setq ptnvx (list (+ (car pt ) 127.5) (+ (cadr pt) 20)))
(command-s "_LAYER" "e" "ACE - Papier" "CO" "4" "ACE - Papier" "T" "a" "ACE - Papier" "s" "NON TRACE - Fenetre pres" "ACE - Papier" "o" "")
(command-s "-MTEXT" ptnvx "J" "BC" "H" "30" "R" "" ptnvx T_Nvx "")
(setq pt (list (car pt ) (- (cadr pt) 475)))
(setq ix (+ ix 1))
)
(ACE:end)
)