;------------------------------------------------------------------------------------------------------------------------------------- ; ; Modulname : liste_sortieren.lsp ; ; Modulbeschr. : Die Liste mit bestimmten Inhalt nach nach bestimmten Kriterien sortieren ; ;------------------------------------------------------------------------------------------------------------------------------------- ; ; Schnittstelle zu anderen Modulen: ; ; INPUT und INPUTRESTRIKTIONEN ; ============================ ; ; Parameter : ; ; Typ Variablename Variablebeschreibung [Wertebereich] ; list lunsortiert Liste unsortiert ; int isortart Sortierungsart ; 1 = String ; 2 = Integer ; 3 = Real ; 4 = Punkte nach X-Koordinaten ; 5 = Punkte nach Y-Koordinaten ; 6 = Punkte nach Z-Koordinaten ; ; ; OUTPUT und OUTPUTRESTRIKTIONEN ; ================================ ; ; Parameter : ; ; Typ Variablenname Variablenbeschreibung [Wertebereich] ; list lsortiert Liste sortiert ; ;------------------------------------------------------------------------------------------------------------------------------------- ; ( defun liste_sortieren ( lunsortiert isortart / ianzsort ianzsortiert ianzunsort ianzunsortiert izlersort izlerunsort lsortiert lsortiertvl xwertsort xwertunsort ) ; Die Liste sortieren (setq lsortiert nil) (cond ((= isortart 1) ; String (if (= lunsortiert nil) (progn (setq lsortiert lunsortiert) ) ; progn (progn ; else ; (setq lsortiert (acad_strlsort lunsortiert)) ; !!! ACHTUNG !!! Fehler beim Sortieren, wenn "Separater Namensbereich" in den Eigenschaften der VLX-Anwendung angekreuzt ist (siehe Befehl sortfehlerausg) (setq lsortiert (vl-sort lunsortiert (function (lambda (c1 c2) (strvergleichwinexpl c1 c2))))) ) ; progn ) ; if ) ((= isortart 2) ; Integer (setq lsortiert (vl-sort lunsortiert '<)) ; ist ein Wert mehrmals in der Liste enthalten, steht er aber nur EINmal in der Liste ) ((= isortart 3) ; Real (setq lsortiert (vl-sort lunsortiert '<)) ) ((= isortart 4) ; X-Koordinaten (setq lsortiert (vl-sort lunsortiert (function (lambda (r1 r2) (< (nth 0 r1) (nth 0 r2)))))) ) ((= isortart 5) ; Y-Koordinaten (setq lsortiert (vl-sort lunsortiert (function (lambda (r1 r2) (< (nth 1 r1) (nth 1 r2)))))) ) ((= isortart 6) ; Z-Koordinaten (setq lsortiert (vl-sort lunsortiert (function (lambda (r1 r2) (< (nth 2 r1) (nth 2 r2)))))) ) ) ; cond ; Die sortierte Liste kontrollieren, damit der GESAMTE Inhalt der unsortierten Liste enthalten ist (setq ianzunsortiert (length lunsortiert)) (setq ianzsortiert (length lsortiert)) (if (/= ianzunsortiert ianzsortiert) (progn (setq lsortiertvl lsortiert) (setq lsortiert nil) (setq ianzsort (length lsortiertvl)) (setq izlersort 0) (while (< izlersort ianzsort) (setq xwertsort (nth izlersort lsortiertvl)) (setq ianzunsort (length lunsortiert)) (setq izlerunsort 0) (while (< izlerunsort ianzunsort) (setq xwertunsort (nth izlerunsort lunsortiert)) (if (= xwertsort xwertunsort) (setq lsortiert (append lsortiert (list xwertunsort))) ) ; if (setq izlerunsort (+ izlerunsort 1)) ) ; while (setq izlersort (+ izlersort 1)) ) ; while ) ; progn ) ; if ; Rückgabewert lsortiert ) ; Modulende