在本课的前面部分,有人指出,当从反应器回调调用时,您需要强制使用 ActiveX 来创建对象。这意味着在必要时覆盖用户选择的对象创建样式(ActiveX,或)。您刚刚更新的代码在函数中包含以下对磁贴绘制例程的调用:gp:Calculate-and-Draw-Tilesentmakecommandgp:command-ended
(setq tileList (gp:Calculate-and-Draw-Tiles
;; path data list without correct tile list.
NewReactorData
;; Object creation function.
;; Within a reactor this *MUST* be ActiveX.
"ActiveX"
)
)
两个参数传递给:(原始关联列表形式的列表)和字符串(将设置对象创建样式)。但是看看当前的定义。(如果您忘记了,此函数在gpdraw.ls sp 中定义。下面是声明参数和局部变量的函数部分:gp:Calculate-and-Draw-TilesNewReactorDatagp_PathData"ActiveX"gp:Calculate-and-Draw-Tiles
(defun gp:Calculate-and-Draw-Tiles (BoundaryData /
PathLength TileSpace
TileRadius SpaceFilled
SpaceToFill RowSpacing
offsetFromCenter rowStartPoint
pathWidth pathAngle
ObjectCreationStyle TileList)
请注意,当前仅指定了一个参数,并将其标识为局部变量。查看变量的设置方式,这是函数的更远:ObjectCreationStyleObjectCreationStyle
(setq ObjectCreationStyle (strcase (cdr (assoc 3 BoundaryData))))
Theis 当前通过检索隐藏在变量(关联列表)中的值在函数内部设置。但现在您需要能够覆盖该值。ObjectCreationStyleBoundaryData
修改 gp:计算和绘制图块以接受对象创建样式参数
- 将变量添加到函数参数。ObjectCreationStyle
- 从局部变量中删除。ObjectCreationStyle
函数的语句应如下所示:defun
(defun gp:Calculate-and-Draw-Tiles (BoundaryData ObjectCreationStyle
/ PathLength TileSpace
TileRadius SpaceFilled
SpaceToFile RowSpacing
offsetFromCenter rowStartPoint
pathWidth pathAngle
TileList) ; remove ObjectCreationStyle from locals
请注意,如果将变量声明为参数(斜杠之前)和局部变量(斜杠之后),Visual LISP 将向您指出这一点。例如,如果同时对参数和变量进行分区,然后在函数上使用 Visual LISP 语法检查工具,则“生成输出”窗口中将出现以下消息:ObjectCreationStylegp:Calculate-and-Draw-Tiles
; *** WARNING: same symbol before and after / in arguments list: OBJECTCREATIONSTYLE
- 修改其中的第一个表达式,使其如下所示:setqgp:Calculate-and-Draw-Tiles
(setq
PathLength (cdr (assoc 41 BoundaryData))
TileSpace (cdr (assoc 43 BoundaryData))
TileRadius (cdr (assoc 42 BoundaryData))
SpaceToFill (- PathLength TileRadius)
RowSpacing (* (+ TileSpace (* TileRadius 2.0))
(sin (Degrees->Radians 60))
)
SpaceFilled RowSpacing
offsetFromCenter 0.0
offsetDistance (+ (* TileRadius 2.0) TileSpace) 2.0)
rowStartPoint (cdr (assoc 10 BoundaryData))
pathWidth (cdr (assoc 40 BoundaryData))
pathAngle (cdr (assoc 50 BoundaryData))
) ;_ end of setq
(if (not ObjectCreationStyle)
(setq ObjectCreationStyle (strcase (cdr (assoc 3 BoundaryData))))
)
已删除原始赋值语句。代码现在检查是否提供了值。如果未设置ifis(即值是),该函数从变量中为其分配一个值。ObjectCreationStyleObjectCreationStyleObjectCreationStylenilBoundaryData
您还需要进行一系列更改。gp:Calculate-and-Draw-Tiles
|