OK so I tried to rework some of this in to function programs to call up instead of just running everything. This code works great for what I want it to do. The only portion i cant get to work is trimming or breaking the line that is drawn at the 3rd and 4th blocks being inserted.
What this does is:
Clock button (or run command), select what type of line (ie audio, video etc..), draw polyline (no nothing is in the z direction), trims line at the start point and end points, inserts connector block at start and end of line, inserts cable label block at 36 units from start and end point of line drawn, (this is where it doesnt work)..trim or break line at this block (block is 24 units total, 12 from mid point left and right)
(defun C:cwire (/ pt1 pt2 pt3 blklay blkname blkname2 lay1 lay2 lay3 lay4 lay5 lay6 lay7 lay8 prevlayer prevsnapmode prevortho P LN CON1 CON2 firstpoint lastpoint)
(setstuff)
(getstuff)
(dostuff)
(resetstuff)
(princ)
);defun
(progn
(defun setstuff ()
;sets block being inserted path
(setq blkname "C:/xxx/xxx/CONNECTOR.dwg")
(setq blkname2 "C:/xxx/xxx/WIRE LABEL.dwg")
;sets layer names to be recalled
(setq lay1 "1_AV_LINE-VIDEO")
(setq lay2 "1_AV_LINE-AUDIO")
;;(setq lay3 "1_AV_LINE-COMM")
;;(setq lay4 "1_AV_LINE-COAX")
(setq lay5 "1_AV_LINE-CONTROL")
(setq lay6 "1_AV_LINE-ETHERNET")
(setq lay7 "1_AV_LINE-POWER")
(setq lay8 "1_AV_LINE-FIBER")
;Sets system current settings to a variable to be recalled
(setq prevlayer (getvar "clayer"))
(setq prevsnapmode (getvar "osmode"))
(setq prevortho (getvar "orthomode"))
;sets system settings to SF requirements settings
(setvar "osmode" 0)
(setvar "orthomode" 1)
(command "SNAP" "2.0")
(princ)
)
(defun getstuff ()
;gets what line type you want to use, will auto put on correct layer
(setq P (getstring "Audio(A)/Video(V)/Control(C)/Ethernet(E)/Power(P):"))
;runs command to make layer and draw line
;starting point
(setq pt1 (getpoint "\nSelect Starting Point:"))
;sets layer drawings line
(IF (or (= P "V")(= P "v"))(command "-LAYER" "M" lay1 "C" "84" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
(IF (or (= P "A")(= P "a"))(command "-LAYER" "M" lay2 "C" "150" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
;;(IF (or (= P "CO")(= P "co"))(command "-LAYER" "M" lay3 "C" "206" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
;;(IF (or (= P "R")(= P "r"))(command "-LAYER" "M" lay4 "C" "44" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
(IF (or (= P "C")(= P "c"))(command "-LAYER" "M" lay5 "C" "14" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
(IF (or (= P "E")(= P "e"))(command "-LAYER" "M" lay6 "C" "144" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
(IF (or (= P "P")(= P "p"))(command "-LAYER" "M" lay7 "C" "200" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
(IF (or (= P "F")(= P "f"))(command "-LAYER" "M" lay8 "C" "30" "" "" "_.pline" pt1 PAUSE))(setq LN (entlast))
;set layer for block to be inserted on
(IF (or (= P "V")(= P "v"))(setq blklay "1_AV_LINE-VIDEO"))
(IF (or (= P "A")(= P "a"))(setq blklay "1_AV_LINE-AUDIO"))
;;(IF (or (= P "CO")(= P "co"))(setq blklay "1_AV_LINE-COMM"))
;;(IF (or (= P "R")(= P "r"))(setq blklay "1_AV_LINE-COAX"))
(IF (or (= P "C")(= P "c"))(setq blklay "1_AV_LINE-CONTROL"))
(IF (or (= P "E")(= P "e"))(setq blklay "1_AV_LINE-ETHERNET"))
(IF (or (= P "P")(= P "p"))(setq blklay "1_AV_LINE-POWER"))
(IF (or (= P "F")(= P "f"))(setq blklay "1_AV_LINE-FIBER"))
(while (> (getvar "CMDACTIVE") 0) (command "\\"))
(setq vertex_lst (vl-remove nil (mapcar '(lambda (x) (if (= (car x) 10) (cdr x))) (entget (entlast)))))
(setq firstpoint (nth 0 vertex_lst))
(setq lastpoint (nth (- (length vertex_lst) 1) vertex_lst))
(princ)
)
(defun dostuff ()
;;inserts 1st block at start of line: CONNECTOR
(command "attreq" "0")
(command "break" LN firstpoint "@12.0<0")
(command "_.Insert" (strcat "*" blkname) firstpoint "" "")
(setq CON1 (entlast))
(command "move" CON1 "" firstpoint "@12.0<0")
(command "_.chprop" CON1 "" "LA" blklay "")
(command "attreq" "1")
;;inserts 2nd block at end of line: CONNECTOR
(command "attreq" "0")
(command "break" LN lastpoint "@12.0<180")
(command "_.Insert" (strcat "*" blkname) lastpoint "" "")
(setq CON2 (entlast))
(command "_.chprop" CON2 "" "LA" blklay "")
(command "attreq" "1")
;;inserts 3rd block at start of line: WIRE LABEL
(command "attreq" "0")
(command "_.Insert" (strcat "*" blkname2) firstpoint "" "")
(setq LBL1 (entlast))
(command "move" LBL1 "" firstpoint "@36.0<0")
(command "_.chprop" LBL1 "" "LA" blklay "")
(command "attreq" "1")
;;inserts 4th block at end of line: WIRE LABEL
(command "attreq" "0")
(command "_.Insert" (strcat "*" blkname2) lastpoint "" "")
(setq LBL2 (entlast))
(command "move" LBL2 "" firstpoint "@36.0<180")
(command "_.chprop" LBL2 "" "LA" blklay "")
(command "attreq" "1")
(princ)
)
(defun resetstuff ()
;resets users current layer snapmode and ortho to the settings that were current prior to running command
(setvar 'clayer prevlayer)
(setvar 'osmode prevsnapmode)
(setvar 'orthomode prevortho)
(princ)
)
(princ)
);Progn
Thanks for any help in advance! You guys/gals here are the best.