hokie555
30th Oct 2009, 04:12 pm
I've got a code that aligns a block with a line upon insertion, and breaks the line where the block is placed. I started with afralisp's method http://www.afralisp.net/lispa/lisp52.htm and am trying to modify this routine so that it will break a polyline OR a line, depending on which is selected. Any takers?
(defun c:DC30a ( / oldsnap clyr blyr llayer tp ip ent1 ent2 ep1 ep2 ang edata ip1 ip2)
(setq clyr (getvar "clayer"))
;get current layer
(setq oldsnap (getvar "OSMODE"))
;get the current snap
(setvar "OSMODE" 544)
;set snap to intersection and nearest
(setvar "CMDECHO" 0)
;switch command echo off
(setq ip (getpoint "\nSelect Placement Point of DC Symbol: "))
;get the insertion point
(setq ent1 (nentselp ip))
;get the line to break
(setvar "OSMODE" 0)
;switch the snap off
(setq ent2 (entget (car ent1)))
;get the entity data of the line
(setq llayer (cdr (assoc 8 ent2)))
;get the layer of the line
(setq blyr (+ (atoi llayer) 1))
(setq blyr (itoa blyr))
(setvar "clayer" blyr)
;set current layer to line layer plus one
(setq ep1 (cdr (assoc 10 ent2)))
;get the first end point
(setq ep2 (cdr (assoc 11 ent2)))
;get the second end point
(setq ang (angle ep1 ep2))
;get the angle of the line
(if (>= ang (* pi)) (setq ang (- ang pi)))
;ensures symbol is placed upright
(setq ang (/ (* ang 180.0) pi))
;convert it to degrees
(setvar "ATTDIA" 0)
;switch off the attribute dialog box
(command "Insert" "C:/DC Diagram Automation/DC Symbols/DWG/30.dwg" ip "" "" ang "" "")
;insert the block
(setq edata (entget (setq en (entlast))))
;get the block entity data
(setq edata (entget (entnext (dxf -1 edata))))
;get the attribute entity list
(setq ip1 (dxf 10 edata))
;extract the first attribute insertion point
(setq edata (entget (entnext (dxf -1 edata))))
;get the next attribute entity list
(setq ip2 (dxf 10 edata))
;extract the second attribute insertion point
(command "Break" ent1 "f" ip1 ip2)
;break the line
(setvar "OSMODE" oldsnap)
;reset snap
(setvar "CMDECHO" 1)
;switch command echo back on
(setvar "ATTDIA" 1)
;switch attribute dialog box back on
(setvar "clayer" clyr)
;switch back to original current layer
(princ)
;finish clean
);defun
(defun c:DC30a ( / oldsnap clyr blyr llayer tp ip ent1 ent2 ep1 ep2 ang edata ip1 ip2)
(setq clyr (getvar "clayer"))
;get current layer
(setq oldsnap (getvar "OSMODE"))
;get the current snap
(setvar "OSMODE" 544)
;set snap to intersection and nearest
(setvar "CMDECHO" 0)
;switch command echo off
(setq ip (getpoint "\nSelect Placement Point of DC Symbol: "))
;get the insertion point
(setq ent1 (nentselp ip))
;get the line to break
(setvar "OSMODE" 0)
;switch the snap off
(setq ent2 (entget (car ent1)))
;get the entity data of the line
(setq llayer (cdr (assoc 8 ent2)))
;get the layer of the line
(setq blyr (+ (atoi llayer) 1))
(setq blyr (itoa blyr))
(setvar "clayer" blyr)
;set current layer to line layer plus one
(setq ep1 (cdr (assoc 10 ent2)))
;get the first end point
(setq ep2 (cdr (assoc 11 ent2)))
;get the second end point
(setq ang (angle ep1 ep2))
;get the angle of the line
(if (>= ang (* pi)) (setq ang (- ang pi)))
;ensures symbol is placed upright
(setq ang (/ (* ang 180.0) pi))
;convert it to degrees
(setvar "ATTDIA" 0)
;switch off the attribute dialog box
(command "Insert" "C:/DC Diagram Automation/DC Symbols/DWG/30.dwg" ip "" "" ang "" "")
;insert the block
(setq edata (entget (setq en (entlast))))
;get the block entity data
(setq edata (entget (entnext (dxf -1 edata))))
;get the attribute entity list
(setq ip1 (dxf 10 edata))
;extract the first attribute insertion point
(setq edata (entget (entnext (dxf -1 edata))))
;get the next attribute entity list
(setq ip2 (dxf 10 edata))
;extract the second attribute insertion point
(command "Break" ent1 "f" ip1 ip2)
;break the line
(setvar "OSMODE" oldsnap)
;reset snap
(setvar "CMDECHO" 1)
;switch command echo back on
(setvar "ATTDIA" 1)
;switch attribute dialog box back on
(setvar "clayer" clyr)
;switch back to original current layer
(princ)
;finish clean
);defun