;=============================================================================
; Application	: AutoCAD 10 DOS  AutoLisp
; Title    	: REVCLOUD.LSP 
; Function 	: Draws a revisioncloud
; Start    	: (load "REVCLOUD") Command:Cloud
; Werkwijze	: Draws a revisioncloud in layer Cloud.
;
;=============================================================================

(defun Pcloud (/ Startp Nextp f g h)

; This function draws a polyline.
; Startp: Start point
; Nextp : Next point (recursive)
; f     : Next point (temp)
; g     : Stored start point (used to determine last segment angle) 
; h     : Stored next point (used to determine last segment angle)

; Prompt for first point of Cloud.
; A null response will effectively terminate command
  (command "LAYER" "M" "CLOUD" "")
  (if (setq Startp (getpoint "\nStart point of Cloud: ")) 
      (progn
       (setq Nextp(getpoint Startp "\nNext counterclockwise point: ")
             g Startp
             h Nextp
       );setq

; Construct first segment
       (if Nextp(command "PLINE" Startp               ; First point
                                 "W" 0.1 0.1          ; Set width to 0.1
                                 Nextp                ; End of first segment
                );command
       );if
      );progn
  );if

; Add extra segments to the polyline until a null response
  (while Nextp
     (if (setq f (getpoint Nextp "\nNext counterclockwise point: "))
         (progn
          (setq h f g Nextp Nextp h)
          (command h)
         );progn
         (setq Nextp nil)
     );if
  );while

; Exit polyline command and return angle of last segment
  (if (and g h) 
;      (progn
  (command "c")
;      );progn Else return nil
;      nil
  );if
  (princ)
);cloud

; DXF takes an integer dxf code and an entity data list.It returns the data
; element of the association pair.
(defun dxf (code elist)
  (cdr (assoc code elist))   ;finds the association pair, strips 1st element
);defun

;test subroutines   
(if (not dxf)                                 
  (prompt "\nError; Requires DXF function. Load aborted. ")     
  (progn                                                ;else load OK

(defun C:CLOUD ( / head hdata bulge en ed)
  (pcloud)                                     ;draw polyline
  (if (and                                     ;get head data list
       (setq en (ENTLAST))                     ;get last entity
        (= (dxf 0 (setq hdata (entget en))) "POLYLINE") ;is it polyline?
      );and
      (progn                                         ;OK, proceed
        (entmod (subst '(70 . 1) '(70 . 0) hdata))   ;if open pline, close it
        (setq bulge (list (cons 42 0.5)))      ;make the bulge association list
        (setq en (dxf -1 hdata))               ;get first subentity - vertex
        (while (and (setq en (entnext en))     ;loop through each vertex
                    (setq ed (entget en))      ;get vertex data
                    (/= "SEQEND" (dxf 0 ed))   ;if seqend, we're done
               );and
               (setq ed (append ed bulge))     ;tack on the bulge association list
               (entmod ed)                     ;modify the subentity
        );while
        (entupd en)                            ;update the entire polyline
      );progn
      (PROMPT "\nError; Draw first a counterclockwise Polyline")
  );if
  (princ)
);defun
);progn
);if; test subroutines

