175 lines
4.7 KiB
Common Lisp
175 lines
4.7 KiB
Common Lisp
(defun parseCSVLine (line / pos result)
|
|
(setq result '())
|
|
(while (setq pos (vl-string-search "," line))
|
|
(setq result (append result (list (substr line 1 pos))))
|
|
(setq line (substr line (+ pos 2)))
|
|
)
|
|
(append result (list line))
|
|
)
|
|
|
|
(defun getDPMDataFromCSV ( / file filename line headers row dpm ip name dpmList deviceGroups currentGroup)
|
|
(setq filename (getfiled "Select CSV File" (strcat (getenv "USERPROFILE") "\\Desktop\\") "csv" 0))
|
|
(if (not filename)
|
|
(progn (princ "\nNo file selected.") (exit))
|
|
)
|
|
(setq file (open filename "r"))
|
|
(if (not file)
|
|
(progn (princ "\nFailed to open file.") (exit))
|
|
)
|
|
|
|
;; Read header line
|
|
(read-line file)
|
|
(setq dpmList '())
|
|
(setq deviceGroups '())
|
|
(setq currentGroup '())
|
|
|
|
(while (setq line (read-line file))
|
|
(setq row (parseCSVLine line))
|
|
|
|
;; DPM name and IP
|
|
(setq dpm (nth 0 row))
|
|
(setq ip (nth 1 row))
|
|
|
|
;; Debug output
|
|
(princ (strcat "\nProcessing: DPM=" (if dpm dpm "NIL") " IP=" (if ip ip "NIL")))
|
|
|
|
;; Add unique DPM to list
|
|
(if (and dpm (/= dpm "") (not (assoc dpm dpmList)))
|
|
(progn
|
|
(setq dpmList (append dpmList (list (cons dpm ip))))
|
|
(princ (strcat "\nAdded new DPM: " dpm " with IP: " ip))
|
|
)
|
|
)
|
|
|
|
;; Device NAME (column 2)
|
|
(setq name (nth 2 row))
|
|
(if (and name (/= name ""))
|
|
(progn
|
|
(setq currentGroup (append currentGroup (list name)))
|
|
(princ (strcat "\nAdded device: " name " (Group size: " (itoa (length currentGroup)) ")"))
|
|
)
|
|
)
|
|
|
|
;; Once 8 devices are collected, add to deviceGroups
|
|
(if (= (length currentGroup) 8)
|
|
(progn
|
|
(setq deviceGroups (append deviceGroups (list currentGroup)))
|
|
(princ (strcat "\nCompleted group " (itoa (length deviceGroups)) " with 8 devices"))
|
|
(setq currentGroup '())
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
(close file)
|
|
(list dpmList deviceGroups)
|
|
)
|
|
|
|
(defun printDPMData (dpmList deviceGroups / i dpm ip devices device)
|
|
(princ "\n--- DPM Data ---")
|
|
(princ (strcat "\nTotal DPMs: " (itoa (length dpmList))))
|
|
(princ (strcat "\nTotal Device Groups: " (itoa (length deviceGroups))))
|
|
|
|
(setq i 0)
|
|
(foreach dpm dpmList
|
|
(princ (strcat "\n\nDPM: " (car dpm)))
|
|
(princ (strcat "\nIP: " (cdr dpm)))
|
|
(princ "\nDevices:")
|
|
|
|
(if (< i (length deviceGroups))
|
|
(progn
|
|
(setq devices (nth i deviceGroups))
|
|
(foreach device devices
|
|
(princ (strcat "\n - " device))
|
|
)
|
|
)
|
|
(princ "\n No devices found for this DPM")
|
|
)
|
|
(setq i (1+ i))
|
|
)
|
|
(princ "\n--- End of Data ---")
|
|
)
|
|
|
|
(defun createTextObjects (dpmList deviceGroups / i dpm ip devices device yPos xPos textContent startY row col)
|
|
(setq yPos 0)
|
|
(setq xPos 0)
|
|
(setq i 0)
|
|
|
|
(princ "\nCreating text objects...")
|
|
|
|
(foreach dpm dpmList
|
|
(setq startY yPos)
|
|
|
|
;; Create text for DPM name
|
|
(setq textContent (strcat "DPM: " (car dpm)))
|
|
(command "TEXT" (list xPos yPos) "2.5" "0" textContent)
|
|
(setq yPos (- yPos 5))
|
|
|
|
;; Create text for IP
|
|
(setq textContent (strcat "IP: " (cdr dpm)))
|
|
(command "TEXT" (list xPos yPos) "2.0" "0" textContent)
|
|
(setq yPos (- yPos 4))
|
|
|
|
;; Create text for devices in 4x2 grid
|
|
(if (< i (length deviceGroups))
|
|
(progn
|
|
(setq devices (nth i deviceGroups))
|
|
(setq row 0)
|
|
(setq col 0)
|
|
|
|
(foreach device devices
|
|
;; Calculate position: 4 rows, 2 columns
|
|
;; Devices 1,2,3,4 go in left column (col 0)
|
|
;; Devices 5,6,7,8 go in right column (col 1)
|
|
(if (< row 4)
|
|
(setq col 0)
|
|
(progn
|
|
(setq col 1)
|
|
(setq row (- row 4))
|
|
)
|
|
)
|
|
|
|
;; Position: left column at xPos, right column at xPos + 40
|
|
;; Each row is 3 units apart
|
|
(setq textContent device)
|
|
(command "TEXT"
|
|
(list (+ xPos (* col 40)) (- yPos (* row 3)))
|
|
"1.5"
|
|
"0"
|
|
textContent
|
|
)
|
|
(setq row (1+ row))
|
|
)
|
|
)
|
|
)
|
|
|
|
;; Move down for next DPM (leave space for 4 rows + extra spacing)
|
|
(setq yPos (- yPos 20))
|
|
|
|
;; Move to next column if too many entries
|
|
(if (< yPos -200)
|
|
(progn
|
|
(setq xPos (+ xPos 120))
|
|
(setq yPos 0)
|
|
)
|
|
)
|
|
|
|
(setq i (1+ i))
|
|
)
|
|
|
|
(princ "\nText objects created successfully!")
|
|
)
|
|
|
|
(defun c:getDPMsWithNamesFromCSV ( / result dpmList deviceGroups)
|
|
(setq result (getDPMDataFromCSV))
|
|
(setq dpmList (nth 0 result))
|
|
(setq deviceGroups (nth 1 result))
|
|
|
|
;; Print the data
|
|
(printDPMData dpmList deviceGroups)
|
|
|
|
;; Create text objects
|
|
(createTextObjects dpmList deviceGroups)
|
|
|
|
(princ)
|
|
) |