0
1
初来乍到
使用道具 举报
15
209
121
初露锋芒
;;; ------------------------------------------------------------------------;;; CreateFlex.lsp v1.2;;;;;; Copyright © May, 2008;;; Timothy G. Spangler;;;;;; Permission to use, copy, modify, and distribute this software;;; for any purpose and without fee is hereby granted, provided;;; that the above copyright notice appears in all copies and;;; that both that copyright notice and the limited warranty and;;; restricted rights notice below appear in all supporting;;; documentation.;;;;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR;;; PURPOSE AND OF MERCHANTIBILITY ARE HEREBY DISCLAIMED BY THE;;; PROGRAMMER.;;;;;; -----------------------------------------------------------------------;;; ------------ COMMAND LINE FUNCTIONS(defun c:FLEX (/)(FLEX_START));;; ------------ MAIN FUNCTION(defun FLEX_START (/ *error* OldCmdEcho OldOrthoMode OldOsmode OldLunits OldLunits OldFillModeActiveDoc Space FlexSize FlexStart TrunkLine BlockName FlexEnd);;; Begin Error Handler -------------------------------------------------(defun *error* (MSG) (if (not (member MSG '("Function cancelled" "quit / exit abort"))) (princ (strcat "\n*** Program Error: " (strcase MSG) " ***")) (princ "\n... Program Cancelled ...") ) (while (< 0 (getvar "cmdactive")) (command) ) (FLEX_RESET_ENV));;; End Error Handler ---------------------------------------------------(FLEX_SET_ENV));;; ------------ SETUP FLEXDUCT ENVIRONMENT SUB(defun FLEX_SET_ENV (/);; Set sysetm variable(setq OldCmdEcho (getvar "CMDECHO"))(setq OldOrthoMode (getvar "ORTHOMODE"))(setq OldOsmode (getvar "OSMODE"))(setq OldLunits (getvar "LUNITS"))(setq OldLuPrec (getvar "LUPREC"))(setq OldFillMode (getvar "FILLMODE"))(setvar "CMDECHO" 0);; Set undo marker(command "undo" "Begin")(setvar "ORTHOMODE" 0)(setvar "OSMODE" 514)(setvar "LUNITS" 2)(setvar "LUPREC" 4)(setvar "FILLMODE" 0);; Load VLISP funtionality(vl-load-com);; Set Vlisp Environment variables(setq ActiveDoc (vla-get-activedocument (vlax-get-acad-object)))(setq Space (if (= (getvar "cvport") 1) (vla-get-paperspace ActiveDoc) (vla-get-modelspace ActiveDoc) )) ;; Run flex duct program(FLEX_RUN) );;; ------------ GET USER VARIABLES SUB(defun FLEX_RUN (/ FlexStart EndPoint FlexSize PlineEnt VLPlineObj VLPlineLength FlexDuct1 FlexDuct2FlexDuct1Pts FlexDuct2Pts FlexDuct3Pts FlexDuct4Pts FlexCap1 FlexCap2)(if (not (setq FlexSize (getreal "\n Enter flex size: <6"> "))) (setq FlexSize 6.0))(FLEX_BLOCK FlexSize)(setq FlexStart (getpoint "\n Define flex start point: "))(setq FlexEnd (getpoint FlexStart "\n Define flex direction: "))(setq FlexEnd (polar FlexStart (angle FlexStart FlexEnd) 3.0))(command "_pline" FlexStart "width" FlexSize FlexSize FlexEnd "arc")(while (> (getvar "cmdactive") 0) (command PAUSE)) (setq PlineEnt (entget(entlast)))(setq VLPlineObj (vlax-ename->vla-object (cdr(assoc -1 PlineEnt))))(setq VLPlineLength (fix (vlax-get VLPlineObj 'length)));; Change width to 0 (all for astetics)(vlax-put VLPlineObj 'ConstantWidth 0.0) (setvar "FILLMODE" OldFillMode);; Add "flex" to duct(command "divide" (entlast) "block" BlockName "y" VLPlineLength);; Create flex duct sides(setq FlexDuct1 (car (vlax-invoke VLPlineObj 'offset (/ FlexSize 2))))(setq FlexDuct2 (car (vlax-invoke VLPlineObj 'offset (-(/ FlexSize 2)FlexSize))));; Get the end points of the sides(setq FlexDuct1Pts (vlax-curve-getEndPoint FlexDuct1))(setq FlexDuct2Pts (vlax-curve-getEndPoint FlexDuct2))(setq FlexDuct3Pts (vlax-curve-getStartPoint FlexDuct1))(setq FlexDuct4Pts (vlax-curve-getStartPoint FlexDuct2))(setq FlexDuct5Pts (vlax-curve-getEndPoint VLPlineObj));; Create caps(setq FlexCap2 (vlax-invoke space 'addline FlexDuct3Pts FlexDuct4Pts))