Here is the LISP that I'm writing.
It goes through every cable in the drawing and it splits them according to the amount of fibres it has. Each fibre is then associated to the main cable.
To achieve this a new app is created for each cable using their DXF code 5 data. From there it gets linked to the Fibre by means of xdata, the data (Main cable handle and fibre number) is then stored in code 1000.
The whole reason for this is to splice different fibres to different cables, here is an example of it:
We have 2 cables eg: A & B.
Cable A consists of 4 fibres and cable B has 12
I'm trying to write a lisp that will then ask you, which fibre of cable A would you like to splice cable B?
To do this the fibres needs to be linked to their parent cable.
Does my code make sense?
(defun c:cableconv (/ n LastFiber FibreData newlayer color newlist ltype CableID Fiber Cable ctr len rep LayerType cableSel ptlist ss )
(setq ss (ssget "X" '((0 . "LWPOLYLINE")(8 . "2F Aerial,4F Aerial,12F Aerial,18F Aerial,36F Aerial,48F Aerial,72F Aerial,96F Aerial,144F Aerial,12F,24F,36F,48F,72F,96F,144F"))))
(setq ctr 0);Sets list counter
(setq len (sslength ss));Sets list length
(while (/= ctr len)
(setq cableSel (ssname ss ctr));Selects entity name
(setq Cable (entget cableSel))
(cond ;This will be used to determine the repeat length later
((= "144F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "144"))
((= "96F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "96"))
((= "72F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "72"))
((= "48F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "48"))
((= "36F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "36"))
((= "24F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "24"))
((= "12F" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "12"))
((= "144F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "144"))
((= "96F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "96"))
((= "72F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "72"))
((= "48F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "48"))
((= "36F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "36"))
((= "18F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "18"))
((= "12F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "12"))
((= "4F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "4"))
((= "2F Aerial" (cdr (assoc 2 (tblsearch "layer" (cdr (assoc 8 Cable)))))) (setq LayerType "2"))
(t (alert "error at Condtions"));Error trap
);cond
(and
(foreach itm
(setq ptlist
(mapcar 'cdr
(vl-remove-if-not '(lambda (x) (= (car x) 10)) Cable)
)
);setq
(print itm)
);foreach
);and
(setq CableID (cdr (assoc 5 Cable))); This sets the Parent cable ID
(setq n 1)
(setq rep (atoi LayerType))
(repeat rep
(setq Fiber (strcat "F" (itoa (- (atoi(rtos (1+ n) 2 0)) 1))))
(setq newlayer (strcat Fiber " ")); Uses text to set variable
(setq ltype "continuous"); linetype
(setq color "red"); color
(command "layer" "m" newlayer "lt" ltype "" "c" color "" "")
(entmakex
(append
(list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
;(cons 8 newlayer);Layer
(cons 90 (length ptlist)) '(70 . 0))
(mapcar (function (lambda (p) (cons 10 p))) ptlist)
);append
)
(regapp CableID)
(setq LastFiber (entget (car (list (entlast)))))
(setq FibreData (list (list -3 (list CableID (cons 1000 CableID) (cons 1000 Fiber) ))))
(setq newlist (append LastFiber FibreData))
(entmod newlist)
;(setq elist (entget (entlast) (list CableID))) <- Was a test to see if the APP name registered
(setq n (1+ n))
)
(setq ctr (1+ ctr))
)
(alert "this worked")
(princ)
)