📄 gpmain.lsp
字号:
;; from the function.
(list
(cons 10 StartPt)
(cons 11 EndPt)
(cons 40 (* HalfWidth 2.0))
(cons 50 (angle StartPt EndPt))
(cons 41 (distance StartPt EndPt))
) ;_ end of list
) ;_ end of if
) ;_ end of if
) ;_ end of if
) ;_ end of defun
;;; In lesson 4, the following function is moved to gp-io.lsp ;
;;;--------------------------------------------------------------------;
;;; Function: gp:getDialogInput ;
;;;--------------------------------------------------------------------;
;;; Description: This function will ask the user to determine the ;
;;; following path parameters: ;
;;; Tile size, Tile spacing ;
;;; Boundary polyline type ;
;;; Entity creation method ;
;;;--------------------------------------------------------------------;
(defun gp:getDialogInput ()
(alert
"Function gp:getDialogInput will get user choices via a dialog"
) ;_ end of alert
;; For now, return T, as if every task in the function worked correctly
T
) ;_ end of defun
;;; In lesson 4, the following function is moved to gpdraw.lsp ;
;;;--------------------------------------------------------------------;
;;; Function: gp:drawOutline ;
;;;--------------------------------------------------------------------;
;;; Description: This function will draw the outline of the garden ;
;;; path. ;
;;;--------------------------------------------------------------------;
;;; Note: no error checking or validation is performed on the ;
;;; BoundaryData parameter. The sequence of items within this ;
;;; parameter do not matter, but it is assumed that all sublists ;
;;; are present, and contain valid data. ;
;;;--------------------------------------------------------------------;
;;; Note: This function uses Activex as a means to produce the garden ;
;;; path boundary. The reason for this will become apparent during ;
;;; future lessons. But here is a hint: certain entity creation ;
;;; methods will not work from within a reactor-triggered function ;
;;;--------------------------------------------------------------------;
(defun gp:drawOutline (BoundaryData / VLADataPts PathAngle
Width HalfWidth StartPt PathLength
angm90 angp90 p1 p2
p3 p4 polypoints pline
)
;; extract the values from the list BoundaryData
(setq PathAngle (cdr (assoc 50 BoundaryData))
Width (cdr (assoc 40 BoundaryData))
HalfWidth (/ Width 2.00)
StartPt (cdr (assoc 10 BoundaryData))
PathLength (cdr (assoc 41 BoundaryData))
angp90 (+ PathAngle (Degrees->Radians 90))
angm90 (- PathAngle (Degrees->Radians 90))
p1 (polar StartPt angm90 HalfWidth)
p2 (polar p1 PathAngle PathLength)
p3 (polar p2 angp90 Width)
p4 (polar p3 (+ PathAngle (Degrees->Radians 180)) PathLength)
polypoints (apply 'append
(mapcar '3dPoint->2dPoint (list p1 p2 p3 p4))
)
)
;; ***** data conversion *****
;; Notice, polypoints is in AutoLISP format, consisting of a list of the
;; 4 corner points for the garden path.
;; The variable needs to be converted to a form of input parameter
;; acceptable to ActiveX calls.
(setq VLADataPts (gp:list->variantArray polypoints))
;; Add polyline to the model space using ActiveX automation.
(setq pline (vla-addLightweightPolyline
*ModelSpace* ; Global Definition for Model Space
VLADataPts
) ;_ end of vla-addLightweightPolyline
) ;_ end of setq
(vla-put-closed pline T)
;; Return the ActiveX object name for the outline polyline
;; The return value should look something like this:
;; #<VLA-OBJECT IAcadLWPolyline 02351a34>
pline
) ;_ end of defun
;;;********************************************************************;
;;; Function: C:GPath The Main Garden Path Function ;
;;;--------------------------------------------------------------------;
;;; Description: This is the main garden path function. It is a C: ;
;;; function, meaning that it is turned into an AutoCAD ;
;;; command called GPATH. This function determines the ;
;;; overall flow of the Garden Path program ;
;;;********************************************************************;
;;; The gp_PathData variable is an association list of the form: ;
;;; (10 . Starting Point) -- A list of 3 reals (a point) denotes ;
;;; the starting point of the garden path ;
;;; (11 . Ending Point) -- A list of 3 reals (a point) denotes ;
;;; the ending point of the garden path ;
;;; (40 . Width) -- A real number denoting boundary width ;
;;; (41 . Length) -- A real number denoting boundary length ;
;;; (50 . Path Angle) -- A real number denoting the angle of the ;
;;; path, in radians ;
;;; (42 . Tile Size) -- A real number denoting the size ;
;;; (radius) of the garden path tiles ;
;;; (43 . Tile Offset) -- Spacing of tiles, border to border ;
;;; ( 3 . Object Creation Style) ;
;;; -- The object creation style indicates how ;
;;; the tiles are to be drawn. The ;
;;; expected value is a string and one ;
;;; one of three values (string case is :
;;; unimportant): ;
;;; "ActiveX" ;
;;; "Entmake" ;
;;; "Command" ;
;;; ( 4 . Polyline Border Style) ;
;;; -- The polyline border style determines ;
;;; the polyline type to be used for the ;
;;; path boundary. The expected value ;
;;; one of two values (string case is :
;;; unimportant): ;
;;; "Pline" ;
;;; "Light" ;
;;;********************************************************************;
(defun C:GPath (/ gp_PathData PolylineName)
;; Ask the user for input: first for path location and
;; direction, then for path parameters. Continue only if you have
;; valid input. Store the data in gp_PathData
(if (setq gp_PathData (gp:getPointInput))
(if (gp:getDialogInput)
(progn
;; At this point, you have valid input from the user.
;; Draw the outline, storing the resulting polyline "pointer"
;; in the variable called PolylineName
(setq PolylineName (gp:drawOutline gp_PathData))
(princ "\nThe gp:drawOutline function returned <")
(princ PolylineName)
(princ ">")
(Alert "Congratulations - your program is complete!")
) ;_ end of progn
(princ "\nFunction cancelled.")
) ;_ end of if
(princ "\nIncomplete information to draw a boundary.")
) ;_ end of if
(princ) ; exit quietly
) ;_ end of defun
;;; Display a message to let the user know the command name
(princ "\nType GPATH to draw a garden path.")
(princ)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -