天河THCAD THCAD的图形设置Lisp例程
这个简单的图形设置例程可能对您有用,只需进行很少的更改即可。这是下面的注释中带有注释和详细注释的代码:
(defun c:mysetup () ;define the command line function “mysetup” (command “audit” “y”) ;audit current drawing (command "-purge" "all" "*" "n") ;purge all unused styles, etc (command "-layer" "m" "1" "c" "1" "" "") ; create layer “1” color “1” (command "-layer" "m" "2" "c" "2" "" "") (command "-layer" "m" "3" "c" "3" "" "") (command "-layer" "m" "4" "c" "4" "" "") (command "viewres" "y" "20000") ;set view resolution to maximum (command "facetres" "10") ;set facet resolution to max (setvar "filedia" 1) ;turn file dialogs on (setvar "attdia" 1) ;turn attribute dialogs on (setvar "attreq" 1) ;enable attribute editing on placement (setvar "cecolor" "bylayer") ;set current color bylayer (setvar "clayer" "0") ;set current layer to “0” (setvar "maxsort" 5000) ;set maximum layer sort to 5,000 (command "zoom" "e" "zoom" "0.95x") ;zoom extents, then out a little ) ;end the function
此图纸设置例程如何工作?
首先,您会看到此图形设置例程中的每一行都可以在THCAD的命令行中键入-今天您可能会这样做。通过将它们包装到Lisp例程中,defun(定义函数)使图形设置例程可从菜单“调用”或在THCAD命令行中键入其名称。
- 如果我们不包含defun,则在按文件名加载程序时,该程序将运行一次。使用defun并在lsp中加载此例程,可以通过键入函数名称mysetup随时使该函数可用。
接下来,查看命令字符串本身。带有前面破折号的命令(例如-layer和-purge)用于防止启动该命令的对话框。作为从其他人打开文件的第一步,我通常执行审计,然后清除以删除所有未使用的项目。
对于purge命令,我经常多次运行它以除去嵌套项目。以下是一些附加的Lisp逻辑,可以实现三连冠:
(repeat 3 (command "-purge" "all" "*" "n"))
请注意,清除是在添加新的空层之前完成的,因为如果我们之后这样做,它们将被删除!
用于设置图层的命令调用可以合并为一个命令语句,但是我认为每行单独显示时更容易阅读。Filedia是全局设置(也称为“系统变量”),因此它与绘图无关。我将这些类型的设置添加到此类例程中,以确保获得新图形中期望的行为。
马克斯什么?
我加入maxsort设置有两个原因。首先,要显示某些设置需要数字值而不是文本字符串(请注意maxsort的命令行中缺少引号)。Maxsort控制要排序的对话框条目的最大数量。第二个原因是maxsort的“出厂默认设置”为1,000。对于当今的计算机,经常发现较大的项目文件,该数字可能太低。如果您打开的图形中层名称不会按字母顺序排序,则可能是默认的maxsort值!
其他setvar “调用”包括尺寸和文本的样式设置,单位设置等…
功能更强大的Layer Maker,可用于您的绘图设置程序
我现在将通过以下示例来介绍您,该示例可以添加到您的mysetup.lsp版本中。通过使用诸如记事本之类的编辑器创建一个简单的文本文件,我们可以添加一个在例程运行时要创建的图层名称的列表。这是上面显示的硬编码过程的替代方法。通过使用findfile函数,THCAD将首先搜索当前目录,然后依次搜索定义的支持文件夹以查找layer.txt文件。众所周知,您可以将默认的图层设置文本文件放置在支持路径中,并将替代版本的放置在各个项目文件夹中。这样,您可以轻松支持多层布局。
(if (not (findfile "Layers.txt")) ;“not” = looking for no result from findfile (alert "Can't find Layers.txt!") ;No file? Yell at the user and exit! (progn ;Otherwise, do the stuff in the progn group (setq layerfile (open (findfile "Layers.txt") "r")) ;open layers.txt to "read" (while (setq layername (read-line layerfile)) ;while reading each line, store the text to layername (command "-layer" "m" layername "") ;make layer with the layername ) ;end the while loop (close layerfile) ;close the Layers.txt file ) ;end the progn ) ;end the if