;| OffsetMultiplePolylines.lsp a.k.a. OMP Offsets multiple polylines by the same amount, in the the same direction (in or out), in a single operation. Polylines can be in any UCS. by Bill Gilliss bill realerthanreal com Comments and suggestions always welcome. Notes: 1) AutoCAD's OFFSET will sometimes fail if polylines are self-crossing, depending upon the shape of the polyline and the direction of the offset. In such cases, this routine will also fail. 2) 3Dpolylines are ignored. 3) Polylines on locked layers are ignored. No warranty, either expressed or implied, is made as to the fitness of this information for any particular purpose. All materials are to be considered 'as-is' and use thereof should be considered as at your own risk. ver 1.00 Apr 03 2010 - initial public release to newsgroup request ver 1.01 Apr 04 2010 - simpler bounding box determination - works with polylines in any UCS ver 1.02 Apr 06 2010 - *actually* works with polylines in any UCS - ignores polylines on locked layers - works with both 2D polyline types Check for updates at www.realerthanreal.com/autolisp Keywords: AutoCAD AutoLISP offset multiple polylines =========================================================================== |; (defun c:OffsetMultiplePolylines (/ ss offdist direction n en ed pt LL UR MP minpoint maxpoint area1 area2 newpoly maxpt lay laystatus laydata) (command "._undo" "_begin") (prompt "Select polyline(s): ") (setq ss (ssget '((0 . "*POLYLINE")))) (initget 1) (setq offdist (getdist "Distance to offset: ")) (initget 1 "In Out") (setq direction (getkword "Direction [In or Out]: ")) (setq n 0) (repeat (sslength ss) (setq en (ssname ss n)) (setq ed (entget en)) (setq lay (cdr (assoc 8 ed))) (setq laydata (tblsearch "LAYER" lay)) (setq laystatus (cdr (assoc 70 laydata))) (if (and (= laystatus 0) (not (= 8 (logand 8 (cdr (assoc 70 ed))))) ) (progn (if (= direction "Out") (progn ;;OUT (command "._ucs" "_obj" en) (setq maxpt (list (1+ (car (getvar 'extmax))) (1+ (cadr (getvar 'extmax))) (1+ (caddr (getvar 'extmax))) ) ) (setq pt (trans maxpt 0 1)) (command "._offset" offdist en pt "") (command "._ucs" "_p") ) (progn ;;IN (command "._ucs" "_obj" en) (setq obj (vlax-ename->vla-object en)) (vla-getboundingbox obj 'minpoint 'maxpoint) (setq LL (trans (vlax-safearray->list minpoint) 0 1)) (setq UR (trans (vlax-safearray->list maxpoint) 0 1)) (setq MP (list (/ (+ (car LL) (car UR)) 2.0)(/ (+ (cadr LL) (cadr UR)) 2.0))) (command "._area" "_object" en) (setq area1 (getvar 'area)) (setq prev (entlast)) ;;MP is approximate centroid of polyline - test if in fact inside (command "._offset" offdist en MP "") (setq newpoly (entlast)) (if (not (eq prev newpoly)) ;;i.e., if new entity created (progn (command "._area" "_object" newpoly) (setq area2 (getvar 'area)) ;;if new polyline is outside the original, offset it ;;twice the original distance in the other direction (if (> area2 area1) (progn (setq pt '( 0 0)) ;1st vtx, regardless of plinetype (command "._offset" (* 2.0 offdist) newpoly pt "") (entdel newpoly) ) ) ) ) (command "._ucs" "_p") ) ) ) ) (setq n (1+ n)) );repeat (command "._undo" "_end") (princ) );;defun (defun c:omp () (c:offsetmultiplepolylines) ) (princ "\nOffsetMultiplePolylines loaded. Type OMP to run.") (princ)