Ok, so I have code that is somewhat working, basically, I am trying to find a way to quickly add hatching for items that are being demolished. I had a routine that kind of worked, I now have a routine that works better. I am still getting some errors with this routine when I select both Polyline and non polyline objects and I am not sure why, it also errors out before the end undo mark gets set. Here is the code in case anyone has any ideas:
(defun c:FD (/ *thisdrawing* *ACAD_LAYERS* SS Ct Obj ObjName ObjLayer ObjData OffsetList Obj1Ent Obj2Ent Obj1End Obj2End OldPeditAccept Obj3Ent ODist Scale Obj3 NewLayer SelectionLength)
(vl-load-com)
;Supporting Functions
;;;Function: Get BuondingBox
;;;arg :
;;; ss -- Select set or a Ename
;;; onseg -- T or NIL , if T then returns the box in UCS , if NIL in WCS
;;;Support in UCS
;;;Written by Highflybird
;;;Edited by GSLS(SS), 2011-02-16
(defun draw-pl (lst)
(entmake
(append
'((0 . "LWPOLYLINE")
(100 . "AcDbEntity")
(100 . "AcDbPolyline")
)
(list (cons 90 (length (car lst))))
(mapcar (function (lambda (x) (cons 10 x))) (car lst))
(list (cons 70 1))
(cdr lst)
)
)
)
(defun ss-get-boundingbox (ss onseg / Wmat Umat i
ent obj minPt maxPt minLs maxLs
maxX maxY minX minY pts
)
(if ss
(progn
(if (eq (type ss) 'ENAME)
(setq ss (ssadd ss (ssadd)))
)
(if (and onseg (= (getvar "WORLDUCS") 0))
(setq Wmat (gc:TMatrixFromTo 1 0)
Umat (gc:TMatrixFromTo 0 1)
);_Use gile's nice function
)
(setq i 0)
(setq minPt (vlax-make-safearray vlax-vbdouble '(0 . 2)))
(setq maxPt (vlax-make-safearray vlax-vbdouble '(0 . 2)))
(repeat (sslength ss)
(setq ent (ssname ss i)
obj (vlax-ename->vla-object ent)
)
(if Wmat
(vla-TransformBy obj (vlax-tmatrix Wmat))
)
(vla-GetBoundingBox obj 'minpt 'maxpt)
(setq minPt (vlax-safearray->list minPt)
maxPt (vlax-safearray->list maxPt)
minLs (cons minPt minLs)
maxLs (cons maxPt maxLs)
)
(if Umat
(vla-TransformBy obj (vlax-tmatrix Umat))
)
(setq i (1+ i))
)
;_Is there better way to get the other coner points , if it's in 3D UCS ?
;_Perhaps it'n use 'trans' function ...
(setq minX (apply 'min (mapcar 'car minLs)))
(setq minY (apply 'min (mapcar 'cadr minLs)))
(setq maxX (apply 'max (mapcar 'car maxLs)))
(setq maxY (apply 'max (mapcar 'cadr maxLs)))
(setq pts (list (list minX minY 0)
(list maxX minY 0)
(list maxX maxY 0)
(list minX maxY 0)
)
)
(if Wmat
(mapcar (function (lambda (x)
(trans x 1 0)
)
)
pts
)
pts
)
)
)
)
;End of Supporting Functions
(setq *thisdrawing* (vla-get-activedocument (vlax-get-acad-object))
*ACAD_LAYERS* (vla-get-layers *thisdrawing*)
)
(vla-startundomark *thisdrawing*)
(while (not SS)
(princ "\rSelect objects to demolish: ")
(setq SS (ssget))
)
(setq Ct 0
SelectionLength (sslength SS)
Scale (* 1.25 (getvar "Dimscale"))
)
(while (< Ct SelectionLength)
(setq Obj (vlax-ename->vla-object (ssname SS Ct))
ObjName (vla-get-objectname Obj)
ObjLayer (vla-get-layer Obj)
ObjData (entget (ssname SS Ct))
)
(cond
((or (= ObjName "AcDbArc") (= ObjName "AcDbPolyline") (= ObjName "AcDbSpline"))
(cond
((= ObjName "AcDbPolyline")
(setq PLWidth (vla-get-constantwidth Obj)
ODist (+ 3 PLWidth)
)
)
(T
(setq ODist 3)
)
)
(vlax-invoke Obj 'Offset ODist)
(setq Obj1Ent (entlast))
(vlax-invoke Obj 'Offset (* ODist -1))
(setq Obj2Ent (entlast))
(setq Obj1 (vlax-ename->vla-object Obj1Ent)
Obj2 (vlax-ename->vla-object Obj2Ent)
Obj1End (vlax-curve-getendpoint Obj1)
Obj2End (vlax-curve-getendpoint Obj2)
)
(cond
((= ObjName "AcDbPolyline")
(vla-put-constantwidth Obj1 0)
(vla-put-constantwidth Obj2 0)
)
)
(command "._pline" Obj1End Obj2End "")
(setq Obj3Ent (entlast))
(setq OldPeditAccept (getvar "peditaccept"))
(setvar "peditaccept" 1)
(command "._pedit" "M" Obj3Ent Obj1Ent Obj2Ent "" "j" "0" "c" "")
(setvar "peditaccept" OldPeditAccept)
(command "._-bhatch" "s" Obj3Ent "" "P" "Ansi31" scale "0" "")
(command "._erase" Obj3Ent "")
(setq Obj3Ent (entlast)
Obj3 (vlax-ename->vla-object Obj3Ent)
)
(cond
((not (tblsearch "LAYER" "$DEMOHATCH"))
(setq NewLayer (vla-add *ACAD_LAYERS* "$DEMOHATCH"))
(vla-put-color NewLayer 8)
(cond
((= (getvar "pstylemode") 0)
(vla-put-plotstylename NewLayer "highlight")
)
)
)
)
(vla-put-layer Obj3 "$DEMOHATCH")
(ssdel (ssname SS Ct) SS)
(setq ct (- ct 1))
)
)
(setq Ct (+ Ct 1))
)
(cond
(SS
(draw-pl (list (ss-get-boundingbox ss NIL)));_test in UCS return the wcs box
(setq Obj3Ent (entlast)
Obj3 (vlax-ename->vla-object Obj3Ent)
)
(vlax-invoke Obj3 'Offset 3)
(command "._erase" Obj3Ent "")
(setq Obj3Ent (entlast)
Obj3 (vlax-ename->vla-object Obj3Ent)
)
(command "._-bhatch" "s" Obj3Ent "" "P" "Ansi31" scale "0" "")
(command "._erase" Obj3Ent "")
(setq Obj3Ent (entlast)
Obj3 (vlax-ename->vla-object Obj3Ent)
)
(cond
((not (tblsearch "LAYER" "$DEMOHATCH"))
(setq NewLayer (vla-add *ACAD_LAYERS* "$DEMOHATCH"))
(vla-put-color NewLayer 8)
(cond
((= (getvar "pstylemode") 0)
(vla-put-plotstylename NewLayer "highlight")
)
)
)
)
(vla-put-layer Obj3 "$DEMOHATCH")
)
)
(vla-endundomark *thisdrawing*)
(princ)
)