114
1万
中流砥柱
;;;================= AreaDiv.lsp =================;;;;;; FUNCTION: AD (Area Division);;;;;; Will Divide a Selected LWPolyline into;;; a specified Area and remainder.;;;;;; AUTHOR:;;; Copyright (C) 2009 Lee McDonnell;;; (Contact Lee Mac, CADTutor.net);;;;;; PLATFORMS:;;; No Restrictions, only tested on ACAD2004;;;;;; VERSION:;;; 1.0 ~ 29.03.2009;;;;;;===============================================(defun c:AD (/ *error* ovar vlst doc spc ODel Acc ACol BCol 2Area Txt tAcc tHt TCol Ent cEnt cPt cAng p@sel cLen mArea ePara Paralst rArea pArea pInc i vPt tLine iArr iLst ptLst pLst sPara vpLst vPts tPoly 2vPts 2tPoly RLst ObjArr ObjReg rCentr tBoxes mOvPt txtObj AreaLst) ; === Adjustments === (setq ODel nil) ; Delete Original LWPolyline (T = Del) (setq Acc 5.0) ; Accuracy of Area Retrieval (Tolerance) (setq ACol 3) ; Colour of Desired Region (0-255) (setq BCol 4) ; Colour of Second Region (if 2Area = T) (setq 2Area T) ; Secondary Marked Area (T or nil) (setq Txt T) ; Area Text in Regions (T or nil) (setq tAcc 2) ; Area Text Precision (if Txt = T) (setq tHt 2.5) ; Area Text Height (if Txt = T, 0.0 for Default) (setq TCol 2) ; Area Text Colour (if Txt = T) ; =================== ; === Error Prevention === (or (< 0.0 Acc) (setq Acc 10.0)) (or (and (eq 'INT (type ACol)) (<= 0 ACol 255)) (setq ACol 3)) (or (and (eq 'INT (type ACol)) (<= 0 BCol 255)) (setq BCol 4)) (or (and (eq 'INT (type tAcc)) (<= 0 tAcc)) (setq tAcc 2)) (or (and (eq 'INT (type TCol)) (<= 0 TCol 255)) (setq TCol 2)) (or (< 0.0 tHt) (setq tHt (getvar "TEXTSIZE"))) (defun *error* (msg) (if ovar (mapcar 'setvar vlst ovar)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\nError: " (strcase msg)))) (princ)) ; ======================== (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (setq vlst '("OSMODE") ovar (mapcar 'getvar vlst)) (mapcar 'setvar vlst '(0)) (if (and (setq Ent (entsel "\nSelect LWPolyline: ")) (eq "LWPOLYLINE" (cdr (assoc 0 (entget (car Ent)))))) (progn (setq cEnt (vlax-ename->vla-object (car Ent)) cPt (vlax-curve-getClosestPointto cEnt (cadr Ent) acExtendNone) cAng (angle '(0 0 0) (vlax-curve-getFirstDeriv cEnt (vlax-curve-getParamatPoint cEnt cPt))) p@sel (vlax-curve-getParamAtPoint cEnt cPt) cLen (- (vlax-curve-getDistatParam cEnt (fix p@sel)) (vlax-curve-getDistatParam cEnt (1+ (fix p@sel))))) (if (eq :vlax-false (vla-get-Closed cEnt)) (progn (initget "Yes No") (if (eq "Yes" (getkword "\nPolyline Not Closed, Close it? ")) (vla-put-Closed cEnt :vlax-true)))) (setq mArea (vla-get-Area cEnt) ePara (1+ (vlax-curve-getEndParam cEnt))) (while (not (minusp (setq ePara (1- ePara)))) (setq Paralst (cons ePara Paralst))) (if (and (not (initget 7)) (setq rArea (getreal (strcat "\nPline Area: "(rtos mArea 2 0)", Required: "))) (<= rArea mArea)) (progn (setq pArea 0.0 pInc (/ Acc 500.0) i -1.0) ; === While Loop === (while (and (not (equal rArea pArea Acc)) (setq vPt (vlax-curve-getPointatParam cEnt (* pInc (setq i (1+ i)))))) (setq tLine (vla-addLine spc (vlax-3D-Point vPt) (vlax-3D-Point (polar vPt cAng cLen))) iArr (vlax-variant-value (vla-IntersectWith tLine cEnt acExtendThisEntity))) (vla-Delete tLine) (if (> (vlax-safearray-get-u-bound iArr 1) 0) (progn (setq iLst (vlax-safearray->list iArr)) (while (not (zerop (length iLst))) (setq ptLst (cons (list (car iLst) (cadr iLst) (caddr iLst)) ptLst) iLst (cdddr iLst)))))