This commit is contained in:
Salijoghli 2025-10-16 19:31:53 +04:00
parent c042a34879
commit 65b3f959a8
3 changed files with 289 additions and 194 deletions

View File

@ -727,6 +727,7 @@
(setq devUpper (strcase deviceTag))
(setq blk
(cond
((vl-string-search "VFD" devUpper) "PLCIO_ARMORPOWERFLEX")
((vl-string-search "APF" devUpper) "PLCIO_ARMORPOWERFLEX")
((vl-string-search "SIO" devUpper) "PLCIO_ARMORBLOCK_SIO")
((vl-string-search "FIOH" devUpper) "PLCIO_ARMORBLOCK_FIOH")

View File

@ -1,4 +1,4 @@
no (defun clearDrawing ( / ss)
(defun clearDrawing ( / ss)
(setq ss (ssget "_X" '((0 . "*"))))
(if ss (command "_.erase" ss ""))
(princ "\nDrawing cleared.")
@ -10,9 +10,8 @@ no (defun clearDrawing ( / ss)
((wcmatch (strcase deviceName) "*VFD*") "VFD")
((wcmatch (strcase deviceName) "*SIO*") "SIO")
((wcmatch (strcase deviceName) "*FIO*") "FIO")
((wcmatch (strcase deviceName) "*EX*") "EX")
((wcmatch (strcase deviceName) "*SPARE*") "")
(T "DEFAULT") ;; fallback
(T "DEFAULT")
)
)
@ -21,13 +20,12 @@ no (defun clearDrawing ( / ss)
)
(defun setDeviceAttributes (blk ip device port / tag2 tag3 isVFD spacePos slashPos baseName part2 tag ip1 ip2 spacePosIP)
;; Default values
(setq tag2 device)
(setq tag3 "")
(setq ip1 ip)
(setq ip2 "")
;; === VFD logic for tag2 and tag3 ===
;; === VFD logic ===
(if (and device (vl-string-search "VFD" (strcase device)))
(progn
(setq spacePos (vl-string-search " " device))
@ -47,17 +45,15 @@ no (defun clearDrawing ( / ss)
)
)
;; === IP splitting logic for ip1 and ip2 ===
;; === IP splitting ===
(setq spacePosIP (vl-string-search " " ip))
(if spacePosIP
(progn
(setq ip1 (str-trim (substr ip 1 spacePosIP)))
(setq ip2 (str-trim (substr ip (+ spacePosIP 2))))
)
;; else no space, ip2 stays ""
)
;; Set attributes
(foreach att (vlax-invoke blk 'GetAttributes)
(setq tag (strcase (vla-get-tagstring att)))
(cond
@ -70,52 +66,42 @@ no (defun clearDrawing ( / ss)
)
)
(defun place-enet-devices (originX originY deviceGroup / blockName width count i x y basePt lastEnt targetPt blk visibilityValue deviceName device ip fullBlockName port)
(setq blockName "HDV2_ENET_DEVICE_")
(setq width 1.2)
(setq count (length deviceGroup))
(setq count (length deviceGroup))
(setq i 0)
(setq y 20.4718)
(while (< i count)
(setq count (length deviceGroup))
(setq blockSpacing 1.2)
(setq groupWidth (* blockSpacing (1- count)))
(setq centerX 21.2)
(setq startX (- centerX (/ groupWidth 2.0)))
(setq x (+ startX (* i blockSpacing) 0.3))
(setq x (+ startX (* i blockSpacing) 0.3))
(setq basePt '(0 0 0))
(setq targetPt (list (+ originX x) (+ originY y) 0))
(setq devicePair (nth i deviceGroup))
(setq device (cdr (assoc "NAME" devicePair)))
(setq ip (cdr (assoc "IP" devicePair)))
(setq port (cdr (assoc "PORT" devicePair)))
;; Create block name based on device visibility
(setq deviceName (getVisibilityFromName device))
(setq fullBlockName (strcat blockName deviceName))
(command "_.-INSERT" fullBlockName basePt 0.8 0.8 0.8 0)
;; Process the inserted block
(if (setq lastEnt (entlast))
(progn
;; Convert to VLA object
(setq blk (vlax-ename->vla-object lastEnt))
;; Move the block to target point
(vla-move blk
(vlax-3d-point basePt)
(vlax-3d-point targetPt)
)
(vla-put-rotation blk 0.0)
(setDeviceAttributes blk ip device port)
)
)
(princ "\nFailed to get last entity.")
)
(setq i (1+ i))
)
)
@ -125,7 +111,6 @@ no (defun clearDrawing ( / ss)
(progn
(setq vlaBlock (vlax-ename->vla-object ent))
(setq index 1)
(foreach att (vlax-invoke vlaBlock 'GetAttributes)
(if (wcmatch (strcase (vla-get-tagstring att)) "LINE*")
(progn
@ -133,13 +118,10 @@ no (defun clearDrawing ( / ss)
(setq basePt (vlax-get att 'InsertionPoint))
(setq height (vla-get-height att))
(setq rotation (vla-get-rotation att))
(setq labelPt
(list (- (car basePt) 0.05) ; left
(+ (cadr basePt) 0.65) ; up
(list (- (car basePt) 0.05)
(+ (cadr basePt) 0.65)
(caddr basePt)))
;; Create label text
(entmake
(list
(cons 0 "TEXT")
@ -167,6 +149,42 @@ no (defun clearDrawing ( / ss)
(princ)
)
(defun setLayoutWireNumbers (layoutEnt zoneNumber layoutIndex / vlaBlock att tag wireNumber cblIndex layoutNum)
(if (and layoutEnt (eq (cdr (assoc 0 (entget layoutEnt))) "INSERT"))
(progn
(setq vlaBlock (vlax-ename->vla-object layoutEnt))
(setq cblIndex 5)
;; Format layout number as 3-digit string (702, 703, 704, etc.)
(setq layoutNum (itoa (+ 702 layoutIndex)))
(foreach att (vlax-invoke vlaBlock 'GetAttributes)
(setq tag (strcase (vla-get-tagstring att)))
(if (= tag "WIRENO")
(progn
;; Concatenate: zone + layoutNum + "-CBL" + cblNum
(setq wireNumber
(strcat
zoneNumber
layoutNum
"-CBL"
(if (< cblIndex 10)
(strcat "0" (itoa cblIndex))
(itoa cblIndex)
)
)
)
(vla-put-textstring att wireNumber)
(setq cblIndex (1+ cblIndex))
)
)
)
)
(princ "\nInvalid layout entity passed to setLayoutWireNumbers.")
)
(princ)
)
(defun parseCSVLine (line / pos result)
(setq result '())
(while (setq pos (vl-string-search "," line))
@ -176,7 +194,7 @@ no (defun clearDrawing ( / ss)
(append result (list line))
)
(defun getDPMDataFromCSV ( / file filename line headers row dpm ip name deviceIP port dpmList deviceGroups currentGroup)
(defun getDPMDataFromCSV ( / file filename line headers row dpm ip name deviceIP port dpmList deviceGroups currentGroup zoneRaw zoneNumber)
(setq filename (getfiled "Select CSV File" (strcat (getenv "USERPROFILE") "\\Desktop\\") "csv" 0))
(if (not filename)
(progn (princ "\nNo file selected.") (exit))
@ -186,25 +204,40 @@ no (defun clearDrawing ( / ss)
(progn (princ "\nFailed to open file.") (exit))
)
;; Read header line
(read-line file)
(setq dpmList '())
(setq deviceGroups '())
(setq currentGroup '())
(setq zoneNumber "")
(while (setq line (read-line file))
(setq row (parseCSVLine line))
(setq dpm (nth 0 row)) ; DPM name (can be empty)
(setq dpm (nth 0 row))
(setq ip (nth 1 row))
(setq name (nth 2 row))
(setq deviceIP (nth 4 row))
(setq port (nth 6 row))
(setq deviceIP (nth 3 row))
(setq port (nth 4 row))
(setq zoneRaw (nth 5 row))
;; Extract zone number - preserve it as-is with leading zeros
(if (and zoneRaw (/= zoneRaw ""))
(progn
;; Extract only digits from zone string (e.g., "MCM01" -> "01")
(setq zoneNumber
(str-trim
(vl-list->string
(vl-remove-if-not
'(lambda (c) (<= 48 c 57))
(vl-string->list zoneRaw)
)
)
)
)
)
)
;; If a new DPM is found
(if (and dpm (/= dpm ""))
(progn
;; If current group is not empty, pad and save it
(if (> (length currentGroup) 0)
(progn
(while (< (length currentGroup) 24)
@ -214,6 +247,7 @@ no (defun clearDrawing ( / ss)
(cons "NAME" "SPARE")
(cons "IP" "")
(cons "PORT" "")
(cons "ZONE" zoneNumber)
))
)
)
@ -222,15 +256,12 @@ no (defun clearDrawing ( / ss)
(setq currentGroup '())
)
)
;; Register new DPM
(if (not (assoc dpm dpmList))
(setq dpmList (append dpmList (list (cons dpm ip))))
(setq dpmList (append dpmList (list (cons dpm (list ip zoneNumber)))))
)
)
)
;; Add valid device (skip blank names)
(if (and name (/= name ""))
(setq currentGroup
(append currentGroup
@ -238,12 +269,12 @@ no (defun clearDrawing ( / ss)
(cons "NAME" name)
(cons "IP" deviceIP)
(cons "PORT" port)
(cons "ZONE" zoneNumber)
))
)
)
)
;; If group reaches 24 devices — finalize
(if (= (length currentGroup) 24)
(progn
(setq deviceGroups (append deviceGroups (list currentGroup)))
@ -252,7 +283,6 @@ no (defun clearDrawing ( / ss)
)
)
;; Handle final group if file ends before 24
(if (> (length currentGroup) 0)
(progn
(while (< (length currentGroup) 24)
@ -262,6 +292,7 @@ no (defun clearDrawing ( / ss)
(cons "NAME" "SPARE")
(cons "IP" "")
(cons "PORT" "")
(cons "ZONE" zoneNumber)
))
)
)
@ -274,14 +305,13 @@ no (defun clearDrawing ( / ss)
(list dpmList deviceGroups)
)
(defun c:init-diagrams ( / blockName count offsetX i x y)
(defun c:init-diagrams ( / blockName count offsetX i x y basePt targetPt lastEnt dpmPair dpmName dpmIP deviceGroup dpmUpsPt dpmUpsObj tag ent vlaObj zoneName zoneNumber dpmData)
(clearDrawing)
(setq blockName "layout")
(setq csvData (getDPMDataFromCSV))
(setq dpmList (car csvData))
(setq deviceGroups (cadr csvData))
(setq count (length dpmList))
(setq userInput (getstring "\nEnter zone number (e.g., 01, 02): "))
(if (and blockName (> count 0))
(progn
@ -293,27 +323,32 @@ no (defun clearDrawing ( / ss)
(setq basePt '(0 0 0))
(setq targetPt (list x y 0))
;; Get DPM data and zone number
(setq dpmPair (nth i dpmList))
(setq dpmName (car dpmPair))
(setq dpmData (cdr dpmPair))
(setq dpmIP (car dpmData))
(setq zoneNumber (cadr dpmData))
(setq deviceGroup (nth i deviceGroups))
;; Insert layout
(command "_.-INSERT" blockName basePt 1 1 0)
(setq lastEnt (entlast))
(if lastEnt
(vla-move
(vlax-ename->vla-object lastEnt)
(vlax-3d-point basePt)
(vlax-3d-point targetPt)
(progn
(vla-move
(vlax-ename->vla-object lastEnt)
(vlax-3d-point basePt)
(vlax-3d-point targetPt)
)
(setLayoutWireNumbers lastEnt zoneNumber i)
)
)
;; Insert DPM-UPS at fixed offset inside layout
(setq dpmPair (nth i dpmList))
(setq dpmName (car dpmPair))
(setq dpmIP (cdr dpmPair))
(setq deviceGroup (nth i deviceGroups))
;; Insert DPM-UPS
(setq dpmUpsPt (list (+ x 16.1) (+ y 2.1173) 0))
(command "_.-INSERT" "DPM-UPS" dpmUpsPt 1 1 0)
;; Set IPADDRESS attribute if found
(setq lastEnt (entlast))
(if lastEnt
(progn
@ -321,45 +356,31 @@ no (defun clearDrawing ( / ss)
(foreach att (vlax-invoke dpmUpsObj 'GetAttributes)
(setq tag (strcase (vla-get-tagstring att)))
(cond
((= tag "IPADDRESS")
(vla-put-textstring att dpmIP)
)
((= tag "TAG2")
(vla-put-textstring att dpmName)
)
((= tag "IPADDRESS") (vla-put-textstring att dpmIP))
((= tag "TAG2") (vla-put-textstring att dpmName))
)
)
)
)
;; Calculate insertion point
;; Insert ZONE_32H
(setq desiredX (+ x 0.7658))
(setq desiredY (+ y 25.6873))
;; Insert ZONE_32H at origin
(command "_.-INSERT" "ZONE_32H" '(0 0 0) 1 1 0)
;; Get the last inserted entity
(setq ent (entlast))
;; Move the inserted block from (0,0,0) to desired point
(if ent
(progn
(setq vlaObj (vlax-ename->vla-object ent))
(vla-move vlaObj (vlax-3d-point 0 0 0) (vlax-3d-point desiredX desiredY 0))
;; Set ALL attributes in the ZONE_32H block to E8912., E8913., etc.
(setq zoneName (strcat userInput (itoa (+ 702 i)) "."))
(setq zoneName (strcat zoneNumber (itoa (+ 702 i)) "."))
(foreach att (vlax-invoke vlaObj 'GetAttributes)
(vla-put-textstring att zoneName)
)
;; Label the ZONE_32H lines
(labelZone32Lines ent)
(labelZone32Lines ent)
)
)
;; Insert ENETs
(place-enet-devices x y deviceGroup)
(place-enet-devices x y deviceGroup)
(setq i (1+ i))
)
(princ (strcat "\nInserted " (itoa count) " layouts side-by-side."))
@ -367,4 +388,4 @@ no (defun clearDrawing ( / ss)
(princ "\nInvalid input.")
)
(princ)
)
)

View File

@ -1,20 +1,58 @@
(defun readDeviceListFromFile ( / file filePath line result)
;; Open file dialog for user to pick device list text file
(setq filePath (getfiled "Select Device List File" "" "txt" 0))
(if filePath
(defun parseCSVLine (line / pos result)
(setq result '())
(while (setq pos (vl-string-search "," line))
(setq result (cons (substr line 1 pos) result))
(setq line (substr line (+ pos 2)))
)
(reverse (cons line result))
)
(defun readDPMNamesAndZoneFromCSV ( / file filename line zone dpmList counter row name)
;; Ask user to select CSV
(setq filename (getfiled "Select CSV File" (strcat (getenv "USERPROFILE") "\\Desktop\\") "csv" 0))
(if (not filename)
(progn (princ "\nNo file selected.") nil)
(progn
(setq file (open filePath "r"))
(setq result '()) ;; initialize empty list before appending
(while (setq line (read-line file))
(setq result (append result (list (strcase (vl-string-trim " \t\r\n" line)))))
(setq file (open filename "r"))
(if (not file)
(progn (princ "\nFailed to open file.") nil)
(progn
;; Skip first line (header)
(read-line file)
;; Read first line (A2..F2) to get zone
(setq line (read-line file))
(setq row (parseCSVLine line))
(setq zone (nth 5 row)) ;; F2
;; Keep only digits from zone
(setq zone (vl-list->string (vl-remove-if-not '(lambda (c) (<= 48 c 57)) (vl-string->list zone))))
;; Initialize DPM list
(setq dpmList '())
(setq counter 1)
;; Read rest of the file
(while (setq line (read-line file))
(setq row (parseCSVLine line))
(setq name (nth 0 row)) ;; Column A
;; Only take every 24th row starting from first
(if (= (rem counter 24) 1)
(if (and name (/= name ""))
(setq dpmList (append dpmList (list (list (cons "NAME" name) (cons "ZONE" zone)))))
)
)
(setq counter (1+ counter))
)
(close file)
dpmList
)
)
(close file)
result
)
nil
)
)
(defun updateTagAttribute (ent tagValue / obj attribs att)
;; Convert entity to VLA object
(setq obj (vlax-ename->vla-object ent))
@ -30,28 +68,79 @@
)
)
(defun c:Init_Network ( / dpmCount rowCount colCount i row col x y spacingX spacingY blkName scaleFactor
startPt endPt zigzagStart secondCableEnds zigzagStarts )
(defun addTextLabel (pt1 pt2 labelText / midPt textHeight alignPt)
;; Calculate midpoint of horizontal line
(setq midPt (list (/ (+ (car pt1) (car pt2)) 2.0) (cadr pt1)))
(setq textHeight 0.3) ;; Adjust text height as needed
(setq alignPt (list (car midPt) (+ (cadr midPt) 0.2))) ;; 0.3 units above line
;; Create text entity above the line with center alignment
(entmakex (list
'(0 . "TEXT")
(cons 10 alignPt) ;; Insertion point
(cons 11 alignPt) ;; Alignment point (required for centered text)
(cons 40 textHeight)
(cons 1 labelText)
(cons 72 1) ;; Center horizontal alignment
(cons 73 0) ;; Baseline vertical alignment
'(8 . "AS_ENET_CABLE") ;; Same layer as cables
'(62 . 7) ;; White color
))
)
(setq blkName "DPM") ; Block name
(setq hdvBlkName "HDV2_1756-EN4TR_CHILD") ; HDV block name
(setq scaleFactor 0.45) ; Scale of each block
(setq spacingX 15.0) ; Horizontal spacing between blocks
(setq spacingY 9.0) ; Vertical spacing between rows
(setq dpmOffsetX 5.0) ; X offset for DPM blocks
(setq hdvY 4.0) ; Y position for HDV block
(setq secondCableEnds '()) ; Store vertical line tops
(setq zigzagStarts '()) ; Store zigzag start points
(defun c:Init_Network ( / dpmCount rowCount colCount i row col x y spacingX spacingY blkName scaleFactor
startPt endPt zigzagStart secondCableEnds zigzagStarts cableCounter )
(setq firstHorizontalLabeled nil)
(setq cableCounter 2)
(setq blkName "DPM")
(setq hdvBlkName "HDV2_1756-EN4TR_CHILD")
(setq scaleFactor 0.45)
(setq spacingX 15.0)
(setq spacingY 9.0)
(setq dpmOffsetX 5.0)
(setq hdvY 4.0)
(setq secondCableEnds '())
(setq zigzagStarts '())
(command "_.ERASE" "ALL" "")
(setq devices (readDeviceListFromFile))
(if (not devices)
(setq filename (getfiled "Select CSV File" (strcat (getenv "USERPROFILE") "\\Desktop\\") "csv" 0))
(if (not filename)
(progn (princ "\nNo file selected.") (exit))
(progn
(princ "\nNo device file selected or file was empty.")
(exit)
(setq file (open filename "r"))
(if (not file)
(progn (princ "\nFailed to open file.") (exit))
(progn
;; Skip header line
(read-line file)
;; Read first data line for zone
(setq line (read-line file)) ;; <-- assign to line
(setq row (parseCSVLine line))
(setq devices '())
(setq zone (nth 5 row)) ;; column F
;; extract digits only
(setq zone (vl-list->string
(vl-remove-if-not
'(lambda (c) (<= 48 c 57))
(vl-string->list zone)
)
))
;; Read rest of the lines for DPM names
(while (and (setq line (read-line file)) (/= line ""))
(setq row (parseCSVLine line))
(setq name (nth 0 row))
(if (and name (/= name ""))
(setq devices (append devices (list name)))
)
)
(close file)
)
)
)
)
@ -64,31 +153,24 @@
)
(setq rowCount (fix (/ (+ dpmCount colCount -1) colCount)))
;; Calculate centering offset for DPM blocks
(setq gridWidth (* (- colCount 1) spacingX))
(setq centerOffsetX (- (/ gridWidth 2.0)))
;; Insert HDV block at (0, hdvY) on layer 0
(command "_.LAYER" "S" "0" "")
(command "_.INSERT" hdvBlkName (list 0 hdvY) scaleFactor scaleFactor 0)
;; Loop to place blocks and draw lines
(setq i 0)
(repeat dpmCount
(setq row (fix (/ i colCount)))
(setq col (rem i colCount))
(setq x (+ (* col spacingX) dpmOffsetX)) ; Use variable
(setq y (* -1 row spacingY)) ; No Y offset
(setq dpmName (nth i devices)) ;; get line content
(setq x (+ (* col spacingX) dpmOffsetX))
(setq y (* -1 row spacingY))
(setq dpmName (nth i devices))
;; Insert DPM block on layer 0
(command "_.LAYER" "S" "0" "")
(command "_.INSERT" blkName (list x y) scaleFactor scaleFactor 0)
;; Get the last inserted entity
(setq ent (entlast))
;; Call the function
(updateTagAttribute ent dpmName)
;; First cable: vertical up
@ -97,29 +179,24 @@
(entmakex (list '(0 . "LINE") (cons 10 startPt) (cons 11 endPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
(setq secondCableEnds (append secondCableEnds (list endPt)))
;; Check if last block in row OR last block in entire drawing
(if (or (= (rem (1+ i) colCount) 0) (= i (- dpmCount 1)))
(progn
;; Last block in row or last block overall — elbow and downward
(setq startPt (list (+ x 7.2677) (+ y 3.6094)))
(setq elbowPt (list (- (car startPt) 0.2) (- (cadr startPt) 0.2)))
(entmakex (list '(0 . "LINE") (cons 10 startPt) (cons 11 elbowPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
(setq endPt (list (car elbowPt) (- (cadr elbowPt) 4.5)))
(entmakex (list '(0 . "LINE") (cons 10 elbowPt) (cons 11 endPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
(setq zigzagStarts (append zigzagStarts (list nil))) ; Placeholder
(setq zigzagStarts (append zigzagStarts (list nil)))
)
(progn
;; Zigzag jump
(setq zigzagStart (list (+ x 7.3656) (+ y 3.7852)))
(setq elbowPt (list (+ x 7.8585) (+ y 5.1262)))
(entmakex (list '(0 . "LINE") (cons 10 zigzagStart) (cons 11 elbowPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Upward line
(setq startPt elbowPt)
(setq endPt (list (car startPt) (+ (cadr startPt) 1.3144)))
(entmakex (list '(0 . "LINE") (cons 10 startPt) (cons 11 endPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Store the end point of the upward line (second cable's end)
(setq zigzagStarts (append zigzagStarts (list endPt)))
)
)
@ -127,130 +204,126 @@
(setq i (1+ i))
)
;; Connect second cable end to next block's first cable end (if not last in row)
;; Combined loop
(setq i 0)
(repeat (- dpmCount 1)
(if (/= (rem (1+ i) colCount) 0) ; Only if not last in row
(progn
(setq pt1 (nth i zigzagStarts)) ; Current block's second line end
(setq pt2 (nth (1+ i) secondCableEnds)) ; Next block's first line end
(if (and pt1 pt2 (listp pt1) (listp pt2)) ; Enhanced check
(entmakex
(list
'(0 . "LINE")
(cons 10 pt1)
(cons 11 pt2)
'(62 . 256)
'(8 . "AS_ENET_CABLE")
(repeat rowCount
(setq j (* i colCount))
(repeat (- colCount 1)
(if (< (1+ j) dpmCount)
(progn
(setq pt1 (nth j zigzagStarts))
(setq pt2 (nth (1+ j) secondCableEnds))
(if (and pt1 pt2 (listp pt1) (listp pt2))
(progn
(entmakex
(list
'(0 . "LINE")
(cons 10 pt1)
(cons 11 pt2)
'(62 . 256)
'(8 . "AS_ENET_CABLE")
)
)
(addTextLabel pt1 pt2 (strcat zone "701-CBL" (itoa cableCounter)))
(setq cableCounter (1+ cableCounter))
)
)
)
)
(setq j (1+ j))
)
(setq i (1+ i))
)
;; Connect last block in row to first block in next row
(setq i 0)
(repeat rowCount
(setq lastInRowIndex (- (* (1+ i) colCount) 1)) ; Last block index in current row
(setq firstInNextRowIndex (* (1+ i) colCount)) ; First block index in next row
;; Connect last in row to first in next row
(setq lastInRowIndex (- (* (1+ i) colCount) 1))
(setq firstInNextRowIndex (* (1+ i) colCount))
(if (and (< lastInRowIndex dpmCount) (< firstInNextRowIndex dpmCount))
(progn
;; Get the downward line end point from last block in row
(setq row i)
(setq col (- colCount 1)) ; Last column
(setq x (+ (* col spacingX) dpmOffsetX)) ; Use variable
(setq y (* -1 row spacingY)) ; Use variable
(setq col (- colCount 1))
(setq x (+ (* col spacingX) dpmOffsetX))
(setq y (* -1 row spacingY))
(setq downwardEndPt (list (- (+ x 7.2677) 0.2) (- (- (+ y 3.6094) 0.2) 4.5)))
;; Get first block coordinates in next row
(setq nextRow (1+ i))
(setq nextCol 0) ; First column
(setq nextX (+ (* nextCol spacingX) dpmOffsetX)) ; Use variable
(setq nextY (* -1 nextRow spacingY)) ; Use variable
(setq nextCol 0)
(setq nextX (+ (* nextCol spacingX) dpmOffsetX))
(setq nextY (* -1 nextRow spacingY))
(setq nextBlockFirstLineEnd (list (+ nextX 7.3656) (+ (+ nextY 4.4406) 2.0)))
;; Draw horizontal line from downward end to next block's X coordinate
(setq horizontalEndPt (list (car nextBlockFirstLineEnd) (cadr downwardEndPt)))
(entmakex (list '(0 . "LINE") (cons 10 downwardEndPt) (cons 11 horizontalEndPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Draw vertical line up to next block's first line end
(addTextLabel downwardEndPt horizontalEndPt (strcat zone "701-CBL" (itoa cableCounter)))
(setq cableCounter (1+ cableCounter))
(entmakex (list '(0 . "LINE") (cons 10 horizontalEndPt) (cons 11 nextBlockFirstLineEnd) '(62 . 256) '(8 . "AS_ENET_CABLE")))
)
)
(setq i (1+ i))
)
;; Connect first block to HDV block
;; Connect first block to HDV
(if (> dpmCount 0)
(progn
;; First block coordinates
(setq firstX (+ (* 0 spacingX) dpmOffsetX)) ; First block X
(setq firstY (* -1 0 spacingY)) ; First block Y (row 0)
;; First block's first line end point
(setq firstX (+ (* 0 spacingX) dpmOffsetX))
(setq firstY (* -1 0 spacingY))
(setq firstBlockEnd (list (+ firstX 7.3656) (+ (+ firstY 4.4406) 2.0)))
;; HDV connection end point
(setq hdvEndPt (list (+ 0 1.4) (- hdvY 2.8))) ; HDV is at (0, hdvY)
;; Step 1: Horizontal line to X destination - 0.5
(setq hdvEndPt (list (+ 0 1.4) (- hdvY 4.4)))
(setq horizontalEnd (list (+ (car hdvEndPt) 0.5) (cadr firstBlockEnd)))
(entmakex (list '(0 . "LINE") (cons 10 firstBlockEnd) (cons 11 horizontalEnd) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Step 2: Vertical line to Y destination - 0.5
;; This is intentionally first cable: label as first
(addTextLabel firstBlockEnd horizontalEnd (strcat zone "701-CBL1"))
(setq verticalEnd (list (car horizontalEnd) (+ (cadr hdvEndPt) 0.5)))
(entmakex (list '(0 . "LINE") (cons 10 horizontalEnd) (cons 11 verticalEnd) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Step 3: Final line to HDV end point
(entmakex (list '(0 . "LINE") (cons 10 verticalEnd) (cons 11 hdvEndPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
)
)
;; Connect last block to HDV block
;; Connect last block to HDV
(if (> dpmCount 0)
(progn
;; Last block index and coordinates
(setq lastBlockIndex (- dpmCount 1))
(setq lastRow (fix (/ lastBlockIndex colCount)))
(setq lastCol (rem lastBlockIndex colCount))
(setq lastX (+ (* lastCol spacingX) dpmOffsetX))
(setq lastY (* -1 lastRow spacingY))
;; HDV connection end point for last block
(setq hdvLastEndPt (list (+ 0 0.1) (- hdvY 5.83))) ; HDV is at (0, hdvY)
;; Check if we have only one row
(setq hdvLastEndPt (list (+ 0 1.1) (- hdvY 5.83)))
(if (= rowCount 1)
(progn
;; Single row: extend vertical line down by 1.5 units below destination Y, keeping same X
(setq startPt (list (- (+ lastX 7.2677) 0.2) (- (+ lastY 3.6094) 0.2)))
(setq extendedVerticalEnd (list (car startPt) (- (cadr hdvLastEndPt) 1.5)))
(entmakex (list '(0 . "LINE") (cons 10 startPt) (cons 11 extendedVerticalEnd) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Horizontal line LEFT to final destination X
;; Reduce final horizontal length by 1 unit
(setq horizontalEnd (list (car hdvLastEndPt) (cadr extendedVerticalEnd)))
(entmakex (list '(0 . "LINE") (cons 10 extendedVerticalEnd) (cons 11 horizontalEnd) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Vertical line UP to final destination
;; Single-row: last cable label (uses cableCounter)
(addTextLabel extendedVerticalEnd horizontalEnd (strcat zone "701-CBL" (itoa cableCounter)))
(entmakex (list '(0 . "LINE") (cons 10 horizontalEnd) (cons 11 hdvLastEndPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
)
(progn
;; Multiple rows: use original 2-segment path
;; Last block's vertical line end point (downward line end)
;; Multiple rows:
(setq lastBlockVerticalEnd (list (- (+ lastX 7.2677) 0.2) (- (- (+ lastY 3.6094) 0.2) 4.5)))
;; Step 1: Horizontal line LEFT to X destination
(setq horizontalEnd (list (car hdvLastEndPt) (cadr lastBlockVerticalEnd)))
(setq horizontalEnd (list (car hdvLastEndPt) (cadr lastBlockVerticalEnd)))
(entmakex (list '(0 . "LINE") (cons 10 lastBlockVerticalEnd) (cons 11 horizontalEnd) '(62 . 256) '(8 . "AS_ENET_CABLE")))
;; Step 2: Vertical line to final destination
(addTextLabel lastBlockVerticalEnd horizontalEnd (strcat zone "701-CBL" (itoa cableCounter)))
(entmakex (list '(0 . "LINE") (cons 10 horizontalEnd) (cons 11 hdvLastEndPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
)
)
)
)
(princ)
)
)