modified the codes. devlay : disabling drawing setting to prevent incorrect placing. layout-base: prompting user to input starting index, instead of the hardcoded value. network-v2: new version of the network loop for the bna8 project. network-daigram-v3: new version of the diagrams of the dpm with 24 ports. pick cordinate : easy debugging
This commit is contained in:
parent
666728a819
commit
57ddaf188e
@ -1,3 +1,39 @@
|
||||
(defun disable-snap-states ()
|
||||
"Turn OFF Osnap, Ortho, and Object Snap Tracking"
|
||||
|
||||
;; Turn OFF Osnap using system variable
|
||||
(setvar "OSMODE" 0)
|
||||
(princ "\n<Osnap off>")
|
||||
|
||||
;; Turn OFF Ortho
|
||||
(command "ORTHO" "OFF")
|
||||
(princ "\n<Ortho off>")
|
||||
|
||||
;; Turn OFF Object Snap Tracking using system variable
|
||||
(setvar "AUTOSNAP" (boole 6 (getvar "AUTOSNAP") 2)) ; Turn off tracking bit
|
||||
(princ "\n<Object Snap Tracking off>")
|
||||
|
||||
(princ "\nSnap states disabled...")
|
||||
)
|
||||
|
||||
(defun enable-snap-states ()
|
||||
"Turn ON Osnap, Ortho, and Object Snap Tracking"
|
||||
|
||||
;; Turn ON Osnap using system variable (common snap modes)
|
||||
(setvar "OSMODE" 4133) ; Common snap modes: endpoint, midpoint, center, intersection, etc.
|
||||
(princ "\n<Osnap on>")
|
||||
|
||||
;; Turn ON Ortho
|
||||
(command "ORTHO" "ON")
|
||||
(princ "\n<Ortho on>")
|
||||
|
||||
;; Turn ON Object Snap Tracking using system variable
|
||||
(setvar "AUTOSNAP" (boole 7 (getvar "AUTOSNAP") 2)) ; Turn on tracking bit
|
||||
(princ "\n<Object Snap Tracking on>")
|
||||
|
||||
(princ "\nSnap states enabled...")
|
||||
)
|
||||
|
||||
;; Function to get attribute value by tag from a list of attributes
|
||||
(defun getAttVal (attList tag)
|
||||
(setq tag (strcase tag))
|
||||
@ -431,10 +467,12 @@
|
||||
)
|
||||
|
||||
(defun c:devlay_update ()
|
||||
(disable-snap-states)
|
||||
(delete-existing-devlay-blocks)
|
||||
(process-block-type "PLCIO_ARMORPOWERFLEX" 11)
|
||||
(process-block-type "PLCIO_ARMORBLOCK_SIO" 16)
|
||||
(process-block-type "PLCIO_ARMBLOCK_FIOM" 16)
|
||||
(process-block-type "PLCIO_ARMORBLOCK_FIOH" 16)
|
||||
(enable-snap-states)
|
||||
(princ)
|
||||
)
|
||||
@ -254,6 +254,9 @@
|
||||
(setvar "ATTREQ" 0)
|
||||
(setq offsetX 38.5)
|
||||
|
||||
;; prompt user for starting indexes
|
||||
(setq startIndex (getstring "\nEnter starting line index (e.g. 01600): "))
|
||||
|
||||
;; Layout loop
|
||||
(setq i 0)
|
||||
(while (< i layoutCount)
|
||||
@ -276,14 +279,16 @@
|
||||
(setq ptLeft (list (+ 0.75 currentOffset) 9.5 0))
|
||||
(setq ptRight (list (+ 20.0 currentOffset) 9.5 0))
|
||||
|
||||
;;todo fix the naming
|
||||
|
||||
(setq leftEnt (insertBlockAt "20_zone" basePt ptLeft))
|
||||
(setq leftBlock (vlax-ename->vla-object leftEnt))
|
||||
(update20ZoneBlockAttributes leftEnt i "04600")
|
||||
(update20ZoneBlockAttributes leftEnt i startIndex)
|
||||
(labelBlockLines leftBlock 1)
|
||||
|
||||
(setq rightEnt (insertBlockAt "20_zone" basePt ptRight))
|
||||
(setq rightBlock (vlax-ename->vla-object rightEnt))
|
||||
(update20ZoneBlockAttributes rightEnt i "04600")
|
||||
(update20ZoneBlockAttributes rightEnt i startIndex)
|
||||
(labelBlockLines rightBlock 21)
|
||||
|
||||
;; Add layout label
|
||||
|
||||
371
network-diagram-v3.lsp
Normal file
371
network-diagram-v3.lsp
Normal file
@ -0,0 +1,371 @@
|
||||
no (defun clearDrawing ( / ss)
|
||||
(setq ss (ssget "_X" '((0 . "*"))))
|
||||
(if ss (command "_.erase" ss ""))
|
||||
(princ "\nDrawing cleared.")
|
||||
)
|
||||
|
||||
(defun getVisibilityFromName (deviceName)
|
||||
(cond
|
||||
((wcmatch (strcase deviceName) "*APF*") "APF")
|
||||
((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
|
||||
)
|
||||
)
|
||||
|
||||
(defun str-trim (s)
|
||||
(vl-string-trim " \t\n\r" s)
|
||||
)
|
||||
|
||||
(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 ===
|
||||
(if (and device (vl-string-search "VFD" (strcase device)))
|
||||
(progn
|
||||
(setq spacePos (vl-string-search " " device))
|
||||
(if spacePos
|
||||
(progn
|
||||
(setq part1 (substr device 1 spacePos))
|
||||
(setq part2 (substr device (+ spacePos 2)))
|
||||
(setq slashPos (vl-string-search "/VFD" part1))
|
||||
(if slashPos
|
||||
(setq baseName (substr part1 1 slashPos))
|
||||
(setq baseName part1)
|
||||
)
|
||||
(setq tag2 (str-trim part1))
|
||||
(setq tag3 (strcat (str-trim baseName) "/" (str-trim part2)))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; === IP splitting logic for ip1 and ip2 ===
|
||||
(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
|
||||
((= tag "IP") (vla-put-textstring att ip1))
|
||||
((= tag "IP2") (vla-put-textstring att ip2))
|
||||
((= tag "TAG2") (vla-put-textstring att tag2))
|
||||
((= tag "PORT") (vla-put-textstring att port))
|
||||
((= tag "TAG3") (if (> (strlen tag3) 0) (vla-put-textstring att tag3)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(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 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 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))
|
||||
)
|
||||
)
|
||||
|
||||
(defun labelZone32Lines (ent / vlaBlock att basePt labelPt labelStr height index rotation)
|
||||
(if (and ent (eq (cdr (assoc 0 (entget ent))) "INSERT"))
|
||||
(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
|
||||
(setq labelStr (if (< index 10) (strcat "0" (itoa index)) (itoa index)))
|
||||
(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.9) ; up
|
||||
(caddr basePt)))
|
||||
|
||||
;; Create label text
|
||||
(entmake
|
||||
(list
|
||||
(cons 0 "TEXT")
|
||||
(cons 8 "0")
|
||||
(cons 7 "WD")
|
||||
(cons 62 7)
|
||||
(cons 10 labelPt)
|
||||
(cons 11 labelPt)
|
||||
(cons 40 height)
|
||||
(cons 72 1)
|
||||
(cons 73 2)
|
||||
(cons 1 labelStr)
|
||||
(cons 50 rotation)
|
||||
(cons 100 "AcDbEntity")
|
||||
(cons 100 "AcDbText")
|
||||
)
|
||||
)
|
||||
(setq index (1+ index))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(princ "\nInvalid entity passed to labelZone32Lines.")
|
||||
)
|
||||
(princ)
|
||||
)
|
||||
|
||||
(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 deviceIP port 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))
|
||||
|
||||
(setq dpm (nth 0 row)) ; DPM name (can be empty)
|
||||
(setq ip (nth 1 row))
|
||||
(setq name (nth 2 row))
|
||||
(setq deviceIP (nth 4 row))
|
||||
(setq port (nth 6 row))
|
||||
|
||||
;; 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)
|
||||
(setq currentGroup
|
||||
(append currentGroup
|
||||
(list (list
|
||||
(cons "NAME" "SPARE")
|
||||
(cons "IP" "")
|
||||
(cons "PORT" "")
|
||||
))
|
||||
)
|
||||
)
|
||||
)
|
||||
(setq deviceGroups (append deviceGroups (list currentGroup)))
|
||||
(setq currentGroup '())
|
||||
)
|
||||
)
|
||||
|
||||
;; Register new DPM
|
||||
(if (not (assoc dpm dpmList))
|
||||
(setq dpmList (append dpmList (list (cons dpm ip))))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Add valid device (skip blank names)
|
||||
(if (and name (/= name ""))
|
||||
(setq currentGroup
|
||||
(append currentGroup
|
||||
(list (list
|
||||
(cons "NAME" name)
|
||||
(cons "IP" deviceIP)
|
||||
(cons "PORT" port)
|
||||
))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; If group reaches 24 devices — finalize
|
||||
(if (= (length currentGroup) 24)
|
||||
(progn
|
||||
(setq deviceGroups (append deviceGroups (list currentGroup)))
|
||||
(setq currentGroup '())
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Handle final group if file ends before 24
|
||||
(if (> (length currentGroup) 0)
|
||||
(progn
|
||||
(while (< (length currentGroup) 24)
|
||||
(setq currentGroup
|
||||
(append currentGroup
|
||||
(list (list
|
||||
(cons "NAME" "SPARE")
|
||||
(cons "IP" "")
|
||||
(cons "PORT" "")
|
||||
))
|
||||
)
|
||||
)
|
||||
)
|
||||
(setq deviceGroups (append deviceGroups (list currentGroup)))
|
||||
)
|
||||
)
|
||||
|
||||
(close file)
|
||||
(list dpmList deviceGroups)
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
(defun c:init-diagrams ( / blockName count offsetX i x y)
|
||||
(clearDrawing)
|
||||
(setq blockName "layout")
|
||||
(setq csvData (getDPMDataFromCSV))
|
||||
(setq dpmList (car csvData))
|
||||
(setq deviceGroups (cadr csvData))
|
||||
(setq count (length dpmList))
|
||||
|
||||
|
||||
(if (and blockName (> count 0))
|
||||
(progn
|
||||
(setq offsetX 43.5)
|
||||
(setq i 0)
|
||||
(while (< i count)
|
||||
(setq x (* i offsetX))
|
||||
(setq y 0)
|
||||
(setq basePt '(0 0 0))
|
||||
(setq targetPt (list x y 0))
|
||||
|
||||
;; 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)
|
||||
)
|
||||
)
|
||||
|
||||
;; 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))
|
||||
|
||||
(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
|
||||
(setq dpmUpsObj (vlax-ename->vla-object lastEnt))
|
||||
(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)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Calculate insertion point
|
||||
(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))
|
||||
;; Label the ZONE_32H lines
|
||||
(labelZone32Lines ent)
|
||||
(setq insPt targetPt)
|
||||
(setq revTriPt (list (+ (car insPt) 42.7) (+ (cadr insPt) desiredY) (caddr insPt)))
|
||||
(command "_.-INSERT" "REVTRIANGLE2" revTriPt 1 0 1)
|
||||
)
|
||||
)
|
||||
|
||||
;; Insert ENETs
|
||||
(place-enet-devices x y deviceGroup)
|
||||
|
||||
(setq i (1+ i))
|
||||
)
|
||||
(princ (strcat "\nInserted " (itoa count) " layouts side-by-side."))
|
||||
)
|
||||
(princ "\nInvalid input.")
|
||||
)
|
||||
(princ)
|
||||
)
|
||||
791
network-v2.lsp
791
network-v2.lsp
@ -1,397 +1,3 @@
|
||||
(defun clearDrawing ( / ss)
|
||||
;; Select all visible, non-locked entities and delete them
|
||||
(setq ss (ssget "_X" '((0 . "*")))) ; select everything
|
||||
(if ss
|
||||
(progn
|
||||
(command "_.erase" ss "")
|
||||
(princ "\nDrawing cleared.")
|
||||
)
|
||||
)
|
||||
)
|
||||
(defun getGap (count)
|
||||
(cond
|
||||
((<= count 20) 3.95)
|
||||
((< count 25) 3.5)
|
||||
((< count 36) 2.2)
|
||||
((>= count 36) 1.3)
|
||||
)
|
||||
)
|
||||
|
||||
(defun getFinalOffsetY (numBlocks)
|
||||
(cond
|
||||
((>= numBlocks 36) 12.0)
|
||||
((>= numBlocks 25) 11.5)
|
||||
(T 10.5)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
;; Function to get final stop for "new block" with negative XScale
|
||||
(defun getFinalStopNewBlock ( / ss i ent obj xScale insPt finalX finalY finalZ finalStop)
|
||||
(vl-load-com)`
|
||||
(setq ss (ssget "X" '((0 . "INSERT") (2 . "new block"))))
|
||||
(if (and ss (> (sslength ss) 0))
|
||||
(progn
|
||||
(setq i 0)
|
||||
(while (< i (sslength ss))
|
||||
(setq ent (ssname ss i))
|
||||
(setq obj (vlax-ename->vla-object ent))
|
||||
(setq xScale (vlax-get obj 'XScaleFactor))
|
||||
(if (< xScale 0.0)
|
||||
(progn
|
||||
;; Get block insertion point and calculate final stop
|
||||
(setq insPt (vlax-get obj 'InsertionPoint))
|
||||
(setq finalX (+ (car insPt) 0.578))
|
||||
(setq finalY (- (cadr insPt) 0.0072))
|
||||
(setq finalZ (nth 2 insPt))
|
||||
(setq finalStop (list finalX finalY finalZ))
|
||||
|
||||
(setq i (sslength ss)) ; exit loop early
|
||||
)
|
||||
)
|
||||
(setq i (1+ i))
|
||||
)
|
||||
finalStop ; return
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(defun getFinalStopSecondNewBlock ()
|
||||
(vl-load-com)
|
||||
(setq finalStop nil)
|
||||
;; Get selection set of all "new block" inserts
|
||||
(setq ss (ssget "X" '((0 . "INSERT") (2 . "new block"))))
|
||||
(if (and ss (> (sslength ss) 0))
|
||||
(progn
|
||||
(setq i 0)
|
||||
(while (< i (sslength ss))
|
||||
(setq ent (ssname ss i))
|
||||
(setq obj (vlax-ename->vla-object ent))
|
||||
;; Get X scale
|
||||
(setq xScale (vlax-get obj 'XScaleFactor))
|
||||
(if (> xScale 0.0) ;; positive X scale = second block
|
||||
(progn
|
||||
;; Found second block
|
||||
(setq insPt (vlax-get obj 'InsertionPoint)) ; list of 3 coords
|
||||
(setq finalX (- (car insPt) 0.578))
|
||||
(setq finalY (- (cadr insPt) 0.0072))
|
||||
(setq finalStop (list finalX finalY (last insPt)))
|
||||
(setq i (sslength ss)) ; exit loop
|
||||
)
|
||||
)
|
||||
(setq i (1+ i))
|
||||
)
|
||||
)
|
||||
)
|
||||
finalStop
|
||||
)
|
||||
|
||||
|
||||
(defun drawHorizontalToFinalStop (startPt targetX)
|
||||
(setq endPt (list targetX (cadr startPt) (caddr startPt)))
|
||||
(entmake
|
||||
(list
|
||||
(cons 0 "LINE")
|
||||
(cons 8 "0") ; Layer 0
|
||||
(cons 62 3) ; Green color
|
||||
(cons 10 startPt)
|
||||
(cons 11 endPt)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defun labelLine (pt1 pt2 index moveRight? / midPt labelText offsetPt)
|
||||
;; Compose label text
|
||||
(setq labelText (strcat "8911-CBL " (itoa index)))
|
||||
|
||||
;; Calculate midpoint
|
||||
(setq midPt (list (/ (+ (car pt1) (car pt2)) 2.0)
|
||||
(/ (+ (cadr pt1) (cadr pt2)) 2.0)
|
||||
0.0))
|
||||
|
||||
;; Apply offset: if moveRight? then +2 in X, else -1 in X, and -0.05 in Y
|
||||
(setq offsetPt (list (+ (car midPt) (if moveRight? 1.5 -1.0))
|
||||
(- (cadr midPt) 0.05)
|
||||
0.0))
|
||||
|
||||
;; Create the text entity
|
||||
(entmake
|
||||
(list
|
||||
(cons 0 "TEXT")
|
||||
(cons 8 "0")
|
||||
(cons 10 offsetPt)
|
||||
(cons 40 0.3) ; text height
|
||||
(cons 1 labelText)
|
||||
(cons 7 "Standard") ; style
|
||||
(cons 72 1) ; left justified
|
||||
(cons 73 1) ; middle baseline
|
||||
(cons 11 offsetPt)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
(defun drawZigzagCables (connectorData targetPt centerOffset numBlocks / sorted i pt1 pt2 direction yDown turnPoint cur next moveTo)
|
||||
(setq lineIndex 2)
|
||||
(setq greenColor 3) ; green
|
||||
|
||||
;; Calculate movement offset (same as blocks)
|
||||
(setq moveTo
|
||||
(list
|
||||
(+ (car centerOffset) (if (>= numBlocks 36) 20.0 23.0))
|
||||
(+ (cadr centerOffset) (getFinalOffsetY numBlocks))
|
||||
0.0
|
||||
)
|
||||
)
|
||||
|
||||
;; Sort connectorData in snake order
|
||||
(setq sorted
|
||||
(vl-sort connectorData
|
||||
(function
|
||||
(lambda (a b)
|
||||
(cond
|
||||
((< (car a) (car b)) T) ; row
|
||||
((> (car a) (car b)) nil)
|
||||
;; same row, order by column - reversed for odd rows
|
||||
((= (rem (car a) 2) 1) (> (cadr a) (cadr b)))
|
||||
(T (< (cadr a) (cadr b)))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(setq i 0)
|
||||
(while (and (< i (length sorted)))
|
||||
|
||||
(setq cur (nth i sorted))
|
||||
(setq next (nth (1+ i) sorted))
|
||||
(setq isOddRow (= (rem (car cur) 2) 1))
|
||||
|
||||
;; Check if current block is the last in its row
|
||||
(if (or (= i (1- (length sorted))) ; last block overall
|
||||
(and next (/= (car cur) (car next)))) ; or next block is in different row
|
||||
(progn
|
||||
;; Get start point: x2 for even row, x1 for odd row
|
||||
(setq pt1 (mapcar '+ (list (if isOddRow (nth 2 cur) (nth 3 cur)) (nth 4 cur) 0.0) moveTo))
|
||||
|
||||
;; Step 1: short horizontal (1 unit left or right)
|
||||
(setq horizOffset (if isOddRow -3.0 1.0))
|
||||
(setq pt2 (list (+ (car pt1) horizOffset) (cadr pt1) 0.0))
|
||||
(setq shouldLabel T)
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor) (cons 10 pt1) (cons 11 pt2)))
|
||||
(setq shouldMoveRight (and (not isOddRow) ; even row
|
||||
(or (= i (1- (length sorted))) ; last block overall
|
||||
(and next (/= (car cur) (car next))))) ; or last in row
|
||||
)
|
||||
|
||||
(if shouldLabel (labelLine pt1 pt2 lineIndex shouldMoveRight))
|
||||
(setq lineIndex (1+ lineIndex))
|
||||
|
||||
;; Step 2: vertical drop if there's a next block
|
||||
(if next
|
||||
(progn
|
||||
(setq shouldLabel nil)
|
||||
(setq pt3 (list (car pt2) (+ (cadr moveTo) (nth 4 next)) 0.0))
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor) (cons 10 pt2) (cons 11 pt3)))
|
||||
|
||||
;; Step 3: horizontal to connector of next block
|
||||
(setq pt4 (list (if isOddRow (nth 2 next) (nth 3 next)) (nth 4 next) 0.0))
|
||||
|
||||
(setq pt4 (mapcar '+ pt4 moveTo))
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor) (cons 10 pt3) (cons 11 pt4)))
|
||||
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Horizontal connection to next block in same row
|
||||
(if (and next (= (car cur) (car next))) ; same row
|
||||
(progn
|
||||
;; Choose correct x sides for direction
|
||||
(if isOddRow
|
||||
(progn
|
||||
;; right to left
|
||||
(setq pt1 (mapcar '+ (list (nth 2 cur) (nth 4 cur) 0.0) moveTo)) ; x1 cur
|
||||
(setq pt2 (mapcar '+ (list (nth 3 next) (nth 4 next) 0.0) moveTo)) ; x2 next
|
||||
)
|
||||
(progn
|
||||
;; left to right
|
||||
(setq pt1 (mapcar '+ (list (nth 3 cur) (nth 4 cur) 0.0) moveTo)) ; x2 cur
|
||||
(setq pt2 (mapcar '+ (list (nth 2 next) (nth 4 next) 0.0) moveTo)) ; x1 next
|
||||
)
|
||||
)
|
||||
(setq shouldLabel T)
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor) (cons 10 pt1) (cons 11 pt2)))
|
||||
(if shouldLabel (labelLine pt1 pt2 lineIndex f))
|
||||
(setq lineIndex (1+ lineIndex))
|
||||
)
|
||||
)
|
||||
|
||||
(setq i (1+ i))
|
||||
)
|
||||
|
||||
;; Draw extra for last block
|
||||
(setq lastIndex (1- (length sorted)))
|
||||
(setq lastBlock (nth lastIndex sorted))
|
||||
(setq rowNum (car lastBlock))
|
||||
(setq isEvenRow (= (rem rowNum 2) 0))
|
||||
|
||||
;; Only draw the extra if last block didn't already connect downward
|
||||
(if (= lastIndex (1- (length sorted))) ; true last block
|
||||
(if isEvenRow
|
||||
(progn
|
||||
(setq finalStop (getFinalStopNewBlock))
|
||||
(if finalStop
|
||||
(progn
|
||||
;; Print finalStop for debug
|
||||
(prompt (strcat "\nFinal stop X: " (rtos (car finalStop) 2 4)
|
||||
", Y: " (rtos (cadr finalStop) 2 4)
|
||||
", Z: " (rtos (caddr finalStop) 2 4)))
|
||||
|
||||
;; EVEN row: x2 → right 1 → down 1
|
||||
(setq pt1 (mapcar '+ (list (nth 3 lastBlock) (nth 4 lastBlock) 0.0) moveTo)) ; x2
|
||||
(setq pt2 (list (+ (car pt1) 1.0) (cadr pt1) 0.0)) ; right 1
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt1) (cons 11 pt2)))
|
||||
|
||||
(setq pt3 (list (car pt2) (- (cadr pt2) 1.0) 0.0)) ; down 1
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt2) (cons 11 pt3)))
|
||||
|
||||
;; Step 3: go left to near finalStop.x
|
||||
(setq xTarget (+ (car finalStop) 1.0))
|
||||
(setq pt4 (list xTarget (cadr pt3) 0.0))
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt3) (cons 11 pt4)))
|
||||
|
||||
;; Step 4: vertical to finalStop.y
|
||||
(setq pt5 (list xTarget (cadr finalStop) 0.0))
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt4) (cons 11 pt5)))
|
||||
|
||||
;; Step 5: final horizontal to exact finalStop.x
|
||||
(setq pt6 (list (car finalStop) (cadr finalStop) 0.0))
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt5) (cons 11 pt6)))
|
||||
)
|
||||
(prompt "\nError: finalStop is NIL! 'new block' with negative XScale not found.")
|
||||
)
|
||||
)
|
||||
(progn
|
||||
(setq finalStop (getFinalStopNewBlock))
|
||||
|
||||
(if finalStop
|
||||
(progn
|
||||
;; Print finalStop for debug
|
||||
(prompt (strcat "\nFinal stop X: " (rtos (car finalStop) 2 4)
|
||||
", Y: " (rtos (cadr finalStop) 2 4)
|
||||
", Z: " (rtos (caddr finalStop) 2 4)))
|
||||
|
||||
;; Get x1 of last block + movement
|
||||
(setq pt1 (mapcar '+ (list (nth 2 lastBlock) (nth 4 lastBlock) 0.0) moveTo))
|
||||
|
||||
;; Calculate X target (1 unit before finalStop X)
|
||||
(setq xTarget (+ (car finalStop) 1.0))
|
||||
|
||||
;; Horizontal point (end of first line)
|
||||
(setq horizPt (list xTarget (cadr pt1) 0.0))
|
||||
|
||||
;; Vertical line end
|
||||
(setq vertPt (list xTarget (cadr finalStop) 0.0))
|
||||
|
||||
;; Draw horizontal
|
||||
(drawHorizontalToFinalStop pt1 xTarget)
|
||||
|
||||
;; Draw vertical
|
||||
(entmake (list
|
||||
(cons 0 "LINE")
|
||||
(cons 8 "0")
|
||||
(cons 62 greenColor)
|
||||
(cons 10 horizPt)
|
||||
(cons 11 vertPt)))
|
||||
;; Final horizontal: to reach exact finalStop X
|
||||
(setq finalPt (list (car finalStop) (cadr finalStop) 0.0))
|
||||
|
||||
(entmake (list
|
||||
(cons 0 "LINE")
|
||||
(cons 8 "0")
|
||||
(cons 62 greenColor)
|
||||
(cons 10 vertPt)
|
||||
(cons 11 finalPt)))
|
||||
)
|
||||
(prompt "\nError: finalStop is NIL! 'new block' with negative XScale not found.")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
;; Draw extra line for first block (x1 → left until aligned with final route)
|
||||
(setq finalStop (getFinalStopNewBlock))
|
||||
(if finalStop
|
||||
(progn
|
||||
;; Print finalStop for debug
|
||||
(prompt (strcat "\nFinal stop X: " (rtos (car finalStop) 2 4)
|
||||
", Y: " (rtos (cadr finalStop) 2 4)
|
||||
", Z: " (rtos (caddr finalStop) 2 4)))
|
||||
|
||||
(setq firstBlock (car sorted))
|
||||
(setq pt1 (mapcar '+ (list (nth 2 firstBlock) (nth 4 firstBlock) 0.0) moveTo)) ; x1
|
||||
(setq targetX (+ (car finalStop) 1.0)) ; align with the rest
|
||||
(setq pt2 (list targetX (cadr pt1) 0.0)) ; same Y, just X target
|
||||
|
||||
;; Draw the horizontal line
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt1) (cons 11 pt2)))
|
||||
(setq pt3 (list (car pt2) (+ (cadr finalStop) 2.0) 0.0))
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt2) (cons 11 pt3)))
|
||||
|
||||
;; Draw line label
|
||||
(labelLine pt1 pt2 1 f)\
|
||||
|
||||
;; Now get second final stop and add horizontal line from pt3 to second final stop X + 1
|
||||
(setq finalStop2 (getFinalStopSecondNewBlock))
|
||||
(if finalStop2
|
||||
(progn
|
||||
;; Print debug info for second stop
|
||||
(prompt (strcat "\nSecond Final stop X: " (rtos (car finalStop2) 2 4)
|
||||
", Y: " (rtos (cadr finalStop2) 2 4)
|
||||
", Z: " (rtos (caddr finalStop2) 2 4)))
|
||||
|
||||
;; Target point for second horizontal line (to second final stop X + 1, same Y as pt3)
|
||||
(setq pt4 (list (- (car finalStop2) 1.0) (cadr pt3) 0.0))
|
||||
|
||||
;; Draw horizontal line to second final stop X + 1
|
||||
(entmake (list (cons 0 "LINE") (cons 8 "0") (cons 62 greenColor)
|
||||
(cons 10 pt3) (cons 11 pt4)))
|
||||
|
||||
;; Draw vertical line down from pt4 to finalStop2 Y (keeping pt4.X)
|
||||
(setq vertPt (list (car pt4) (cadr finalStop2) 0.0))
|
||||
(entmake (list
|
||||
(cons 0 "LINE")
|
||||
(cons 8 "0")
|
||||
(cons 62 greenColor)
|
||||
(cons 10 pt4)
|
||||
(cons 11 vertPt)))
|
||||
|
||||
;; Draw horizontal line from vertPt to finalStop2 (full X and Y)
|
||||
(entmake (list
|
||||
(cons 0 "LINE")
|
||||
(cons 8 "0")
|
||||
(cons 62 greenColor)
|
||||
(cons 10 vertPt)
|
||||
(cons 11 finalStop2)))
|
||||
)
|
||||
(prompt "\nError: finalStop2 is NIL! 'new block' with positive XScale not found.")
|
||||
)
|
||||
|
||||
)
|
||||
(prompt "\nError: finalStop is NIL! 'new block' with negative XScale not found.")
|
||||
)
|
||||
)
|
||||
|
||||
(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))
|
||||
@ -409,237 +15,242 @@
|
||||
)
|
||||
)
|
||||
|
||||
(defun c:Init_Network ( / numBlocks cols rows i row col x y
|
||||
spacing gap baseGap totalWidth totalHeight
|
||||
xStart yStart basePt targetPt ent blkRef
|
||||
attList centerOffset)
|
||||
|
||||
;; Clear everything first
|
||||
(clearDrawing)
|
||||
|
||||
|
||||
(setq deviceList (readDeviceListFromFile))
|
||||
(if (not deviceList)
|
||||
(defun updateTagAttribute (ent tagValue / obj attribs att)
|
||||
;; Convert entity to VLA object
|
||||
(setq obj (vlax-ename->vla-object ent))
|
||||
(if (and obj (eq (vla-get-hasattributes obj) :vlax-true))
|
||||
(progn
|
||||
(princ "\nError: Device list file not found or empty.")
|
||||
(setq attribs (vlax-invoke obj 'GetAttributes))
|
||||
(foreach att attribs
|
||||
(if (eq (strcase (vla-get-TagString att)) "TAG1")
|
||||
(vla-put-TextString att tagValue)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defun c:Init_Network ( / dpmCount rowCount colCount i row col x y spacingX spacingY blkName scaleFactor
|
||||
startPt endPt zigzagStart secondCableEnds zigzagStarts )
|
||||
|
||||
(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
|
||||
|
||||
(command "_.ERASE" "ALL" "")
|
||||
|
||||
|
||||
(setq devices (readDeviceListFromFile))
|
||||
|
||||
(if (not devices)
|
||||
(progn
|
||||
(princ "\nNo device file selected or file was empty.")
|
||||
(exit)
|
||||
)
|
||||
)
|
||||
|
||||
(setq numBlocks (length deviceList))
|
||||
(setq dpmCount (length devices))
|
||||
|
||||
; Grid dimensions
|
||||
(setq rows (fix (sqrt numBlocks))) ; fewer rows
|
||||
(setq cols (fix (/ (+ numBlocks rows -1) rows))) ; more columns
|
||||
|
||||
(if (or (= numBlocks 25) (= numBlocks 36))
|
||||
(setq cols (1+ cols))
|
||||
;; Calculate grid size
|
||||
(setq colCount (fix (sqrt dpmCount)))
|
||||
(if (< (* colCount colCount) dpmCount)
|
||||
(setq colCount (+ colCount 1))
|
||||
)
|
||||
;; Dynamic gap
|
||||
(setq gap (getGap numBlocks))
|
||||
(setq spacing 3.0)
|
||||
(setq step (+ spacing gap)) ; actual distance between blocks
|
||||
(setq rowCount (fix (/ (+ dpmCount colCount -1) colCount)))
|
||||
|
||||
;; Insert background grid block
|
||||
(setvar "CLAYER" "AS_GRID")
|
||||
(setq basePt "0,0,0")
|
||||
(command "_-INSERT" "A$Cae272396" basePt 1 1 0)
|
||||
;; Calculate centering offset for DPM blocks
|
||||
(setq gridWidth (* (- colCount 1) spacingX))
|
||||
(setq centerOffsetX (- (/ gridWidth 2.0)))
|
||||
|
||||
;; UPS block layer and setup
|
||||
(setvar "CLAYER" "AS_ENET CABLE")
|
||||
(setvar "ATTDIA" 0)
|
||||
(setvar "ATTREQ" 0)
|
||||
;; Insert HDV block at (0, hdvY) on layer 0
|
||||
(command "_.LAYER" "S" "0" "")
|
||||
(command "_.INSERT" hdvBlkName (list 0 hdvY) scaleFactor scaleFactor 0)
|
||||
|
||||
;; Calculate offsets for centering
|
||||
(setq totalWidth (* cols step))
|
||||
(setq totalHeight (* rows step))
|
||||
(setq xStart (- (/ totalWidth 2.0)))
|
||||
(setq yStart (/ totalHeight 2.0))
|
||||
(setq centerOffset (list (/ spacing 2.0) (/ spacing 2.0) 0.0))
|
||||
|
||||
(setq extraColGap (if (>= numBlocks 36) 0.75 0.0))
|
||||
;; Loop to place blocks and draw lines
|
||||
(setq i 0)
|
||||
;; Place UPS blocks
|
||||
(while (< i numBlocks)
|
||||
(setq row (/ i cols))
|
||||
(setq col (rem i cols))
|
||||
(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
|
||||
|
||||
;; Snake pattern
|
||||
(if (= (rem row 2) 1)
|
||||
(setq col (- cols 1 col))
|
||||
)
|
||||
;; Insert DPM block on layer 0
|
||||
(command "_.LAYER" "S" "0" "")
|
||||
(command "_.INSERT" blkName (list x y) scaleFactor scaleFactor 0)
|
||||
|
||||
;; Grid point
|
||||
(setq x (+ xStart (* col step) (* col extraColGap)))
|
||||
(setq y (- yStart (* row step)))
|
||||
(setq targetPt (list x y 0))
|
||||
|
||||
;; Insert block at 0,0 and scale
|
||||
(command "_-INSERT" "UPS_DPM_BRACKET" "0,0,0" 0.2212 0.2212 0.2212 0)
|
||||
;; Get the last inserted entity
|
||||
(setq ent (entlast))
|
||||
(if ent
|
||||
(setq blkRef (vlax-ename->vla-object ent))
|
||||
(princ "\nError: Block insert failed.")
|
||||
)
|
||||
|
||||
;; Move to adjusted centered position
|
||||
(setq moveTo
|
||||
(mapcar '+ targetPt
|
||||
(list
|
||||
(+ (car centerOffset) (if (>= numBlocks 36) 20.0 23.0))
|
||||
(+ (cadr centerOffset) (getFinalOffsetY numBlocks))
|
||||
0.0
|
||||
)
|
||||
)
|
||||
)
|
||||
(vla-move blkRef (vlax-3d-point '(0 0 0)) (vlax-3d-point moveTo))
|
||||
;; Call the function
|
||||
(updateTagAttribute ent dpmName)
|
||||
|
||||
;; Get device name for current block
|
||||
(setq deviceName (nth i deviceList))
|
||||
;; First cable: vertical up
|
||||
(setq startPt (list (+ x 7.3656) (+ y 4.4406)))
|
||||
(setq endPt (list (car startPt) (+ (cadr startPt) 2.0)))
|
||||
(entmakex (list '(0 . "LINE") (cons 10 startPt) (cons 11 endPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
|
||||
(setq secondCableEnds (append secondCableEnds (list endPt)))
|
||||
|
||||
;; Set TAG2 attribute to zigzag index
|
||||
(setq attList (vlax-invoke blkRef 'GetAttributes))
|
||||
(foreach att attList
|
||||
(if (= (strcase (vla-get-TagString att)) "TAG2")
|
||||
(vla-put-TextString att deviceName)
|
||||
)
|
||||
;; 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
|
||||
)
|
||||
(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")))
|
||||
|
||||
;; === Draw connector lines ===
|
||||
(setq start1 (list (+ (car moveTo) 3.99) (- (cadr moveTo) 3.196) 0.0))
|
||||
(setq end1 (list (car start1) (- (cadr start1) 0.25) 0.0))
|
||||
;; 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")))
|
||||
|
||||
(setq start2 (list (+ (car moveTo) 4.155) (cadr start1) 0.0))
|
||||
(setq end2 (list (car start2) (- (cadr start2) 0.25) 0.0))
|
||||
|
||||
(setvar "CLAYER" "0") ; or create a special cable layer if needed
|
||||
(setq greenColor 3) ; AutoCAD color index for green
|
||||
|
||||
;; Draw first line
|
||||
(entmake
|
||||
(list
|
||||
(cons 0 "LINE")
|
||||
(cons 8 "0") ; layer
|
||||
(cons 62 greenColor) ; color
|
||||
(cons 10 start1)
|
||||
(cons 11 end1)
|
||||
)
|
||||
)
|
||||
|
||||
;; Draw second line
|
||||
(entmake
|
||||
(list
|
||||
(cons 0 "LINE")
|
||||
(cons 8 "0") ; layer
|
||||
(cons 62 greenColor)
|
||||
(cons 10 start2)
|
||||
(cons 11 end2)
|
||||
;; Store the end point of the upward line (second cable's end)
|
||||
(setq zigzagStarts (append zigzagStarts (list endPt)))
|
||||
)
|
||||
)
|
||||
|
||||
(setq i (1+ i))
|
||||
)
|
||||
|
||||
;; Layer and attribute prompt settings
|
||||
(setvar "CLAYER" "PSYMS")
|
||||
(setvar "ATTDIA" 0)
|
||||
(setvar "ATTREQ" 0)
|
||||
|
||||
;; Target positions
|
||||
(setq ptTop (list 1.0 16.0 0.0)) ; Top block
|
||||
(setq ptBot (list 1.86 10.0 0.0)) ; Bottom block
|
||||
|
||||
;; If block count is 16 or less, shift X positions by +4.0
|
||||
(cond
|
||||
((<= numBlocks 16)
|
||||
(setq ptTop (list (+ (car ptTop) 4.0) (cadr ptTop) (caddr ptTop)))
|
||||
(setq ptBot (list (+ (car ptBot) 4.0) (cadr ptBot) (caddr ptBot))))
|
||||
|
||||
((and (>= numBlocks 25) (< numBlocks 31))
|
||||
(setq ptTop (list (+ (car ptTop) 3.0) (cadr ptTop) (caddr ptTop)))
|
||||
(setq ptBot (list (+ (car ptBot) 3.0) (cadr ptBot) (caddr ptBot))))
|
||||
)
|
||||
|
||||
;; Insert top block (1783-BMS20CGL)
|
||||
(command "_-INSERT" "1783-BMS20CGL" "0,0,0" 0.75 0.75 0.75 0)
|
||||
(setq blk1 (vlax-ename->vla-object (entlast)))
|
||||
(vla-put-Rotation blk1 0.0) ; <- Force zero rotation
|
||||
(vla-move blk1 (vlax-3d-point '(0 0 0)) (vlax-3d-point ptTop))
|
||||
|
||||
;; Insert bottom block (PATCH_PANEL)
|
||||
(command "_-INSERT" "PATCH_PANEL" "0,0,0" 0.75 0.75 0.75 0)
|
||||
(setq blk2 (vlax-ename->vla-object (entlast)))
|
||||
(vla-put-Rotation blk2 0.0) ; <- Force zero rotation
|
||||
(vla-move blk2 (vlax-3d-point '(0 0 0)) (vlax-3d-point ptBot))
|
||||
|
||||
;; Calculate new Y position based on second block (PATCH_PANEL)
|
||||
(setq newBlockY (+ (cadr ptBot) 1.3702))
|
||||
|
||||
;; X positions relative to second block X
|
||||
(setq newBlock1X (+ (car ptBot) 0.4274))
|
||||
(setq newBlock2X (+ (car ptBot) 1.5219))
|
||||
|
||||
;; Y position for both new blocks
|
||||
(setq newBlockYPos newBlockY)
|
||||
|
||||
;; Insert first "new block"
|
||||
(command "_-INSERT" "new block" "0,0,0" 0.5909 0.5909 0.5909 0)
|
||||
(setq newBlk1 (vlax-ename->vla-object (entlast)))
|
||||
(vla-put-Rotation newBlk1 0.0)
|
||||
(vla-move newBlk1 (vlax-3d-point '(0 0 0)) (vlax-3d-point (list newBlock1X newBlockYPos 0.0)))
|
||||
|
||||
;; Insert second "new block" mirrored on X scale
|
||||
(command "_-INSERT" "new block" "0,0,0" -0.5909 0.5909 0.5909 0)
|
||||
(setq newBlk2 (vlax-ename->vla-object (entlast)))
|
||||
(vla-put-Rotation newBlk2 0.0)
|
||||
(vla-move newBlk2 (vlax-3d-point '(0 0 0)) (vlax-3d-point (list newBlock2X newBlockYPos 0.0)))
|
||||
|
||||
;; === Collect connector info ===
|
||||
(setq connectorData '())
|
||||
;; Connect second cable end to next block's first cable end (if not last in row)
|
||||
(setq i 0)
|
||||
(while (< i numBlocks)
|
||||
(setq row (/ i cols))
|
||||
(setq col (rem i cols))
|
||||
(prompt (strcat "numBlocks: " (itoa numBlocks)))
|
||||
(prompt (strcat "cols: " (itoa cols)))
|
||||
(if (= (rem row 2) 1)
|
||||
(setq col (- cols 1 col))
|
||||
(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")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(setq x (+ xStart (* col step) (* col extraColGap)))
|
||||
(setq y (- yStart (* row step)))
|
||||
|
||||
(setq x1 (+ x 3.99))
|
||||
(setq x2 (+ x 4.155))
|
||||
(setq yLine (- y 3.446))
|
||||
|
||||
;; Debug: print each block being added
|
||||
(prompt (strcat "Adding block " (itoa i) ": Row " (itoa row) " Col " (itoa col)))
|
||||
|
||||
(setq connectorData (append connectorData (list (list row col x1 x2 yLine))))
|
||||
(setq i (1+ i))
|
||||
)
|
||||
(prompt (strcat "Total connectorData entries: " (itoa (length connectorData))))
|
||||
|
||||
;; === Draw horizontal cables ===
|
||||
(drawZigzagCables connectorData targetPt centerOffset numBlocks)
|
||||
;; 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
|
||||
|
||||
;; Insert "CONDUCTOR" block at center point
|
||||
(setq centerPt (list 40.1 1.1 0.0)) ; Adjust this if needed
|
||||
(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 downwardEndPt (list (- (+ x 7.2677) 0.2) (- (- (+ y 3.6094) 0.2) 4.5)))
|
||||
|
||||
(entmake
|
||||
(list
|
||||
(cons 0 "INSERT")
|
||||
(cons 2 "CONDUCTOR") ; Block name
|
||||
(cons 8 "0") ; Layer
|
||||
(cons 10 centerPt) ; Insertion point
|
||||
(cons 41 1.0) ; X scale
|
||||
(cons 42 1.0) ; Y scale
|
||||
(cons 43 1.0) ; Z scale
|
||||
(cons 50 0.0) ; Rotation
|
||||
;; 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 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
|
||||
(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
|
||||
(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 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 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
|
||||
(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
|
||||
(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
|
||||
(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
|
||||
(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
|
||||
(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)
|
||||
(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)))
|
||||
(entmakex (list '(0 . "LINE") (cons 10 lastBlockVerticalEnd) (cons 11 horizontalEnd) '(62 . 256) '(8 . "AS_ENET_CABLE")))
|
||||
|
||||
;; Step 2: Vertical line to final destination
|
||||
(entmakex (list '(0 . "LINE") (cons 10 horizontalEnd) (cons 11 hdvLastEndPt) '(62 . 256) '(8 . "AS_ENET_CABLE")))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(princ (strcat "\nPlaced " (itoa numBlocks) " UPS blocks with dynamic spacing."))
|
||||
(princ)
|
||||
)
|
||||
BIN
pick coordinate ( CD1).fas
Normal file
BIN
pick coordinate ( CD1).fas
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user