使用LISP进行图层操作
我写了一些代码,打开两层,设置一个当前层,关闭所有其他层,在某些情况下似乎可以工作。当图层冻结时,它无法打开图层。我想我需要的是一个功能来检查我想要的图层是否冻结,如果是这样,那么我需要解冻它们。我已附上我写的东西。(defun c:DWTR ()
(command "-layer" "on" "*.*" "")
(command "-layer" "s" "SV_WTR_LIN" "")
(command "-layer" "off" "~SV_WTR_LIN" "")
(command "-layer" "on" "SV_WTR_PTS" "")
(princ)
)
你好
无论层处于何种天气,冻结层都不会显示。解冻层,然后打开它们应该可以做到这一点。
祝你过得愉快。
肖恩 The following group codes apply to LAYER symbol table entries. In addition to the group codes described here, see "Common Group Codes for Symbol Table Entries." For information about abbreviations and formatting used in this table, see "Formatting Conventions in This Reference."
LAYER group codes
Group codes Description
100 > Subclass marker (AcDbLayerTableRecord)
2 > Layer name
70 > Standard flags (bit-coded values):
1 = Layer is frozen; otherwise layer is thawed.
2 = Layer is frozen by default in new viewports.
4 = Layer is locked.
16 = If set, table entry is externally dependent on an xref.
32 = If this bit and bit 16 are both set, the externally dependent xref has been successfully resolved.
64 = If set, the table entry was referenced by at least one entity in the drawing the last time the drawing was edited. (This flag is for the benefit of AutoCAD commands. It can be ignored by most programs that read DXF files and need not be set by programs that write DXF files.)
62 > Color number (if negative, layer is off)
6 > Linetype name
290 > Plotting flag. If set to 0, do not plot this layer
370 > Lineweight enum value
390 > Hard pointer ID/handle of PlotStyleName object
Xref-dependent layers are output during SAVEAS. For these layers, the associated linetype name in the DXF file is always CONTINUOUS. 这就是我想要的:
步骤1:检查第1层或第2层是否冻结。如果第1层或第2层冻结,请解冻这些层
第2步:使第1层成为当前层
步骤3:关闭除第1层和第2层之外的所有功能
我不知道如何使用DXF代码处理属性,有人能帮我找到正确的方向吗?非常感谢您的帮助。 你好
我不知道你为什么要检查第1层和第2层是否被冻结,除非你计划在函数结束时恢复当前设置。我只会解冻它们,如果图层已经解冻或没有解冻,对layer命令无关紧要。
(command "._Layer" "Off" "*"
"On" "Layer1,Layer2"
"Thaw" "Layer1,Layer2"
"Set" "Layer1"
); command
希望这有帮助。
祝你过得愉快。
肖恩 shawn你在cad中试过这个吗?我试过你的方法,它产生了很多提示,告诉你真的想关闭XXX层,等等,命令应该不会给出提示,应该是全自动的。
(defun c:SS ()
(command "._Layer" "Off" "*"
"On" "C-SSWR,C-SSWR-SYMB"
"Thaw" "C-SSWR,C-SSWR-SYMB"
"Set" "C-SSWR"
) ; command
) 查看层是否冻结的函数
;| Input - String, Layer name
Output t if layer is frozen
nilif its thawed
|;
(defun LayerIsFrozen (<LayerName>)
(vl-load-com)
(eq
;Test is frozen
(vla-get-freeze
;Convert to Vla Object
(vlax-ename->vla-object
;Retun ename of layer
(tblobjname "LAYER" <LayerName>))
)
':vlax-true)
)
使用autolisp也可以实现同样的效果,但编码可能会更长
样本使用
(if (LayerIsFrozen "SV_WTR_LIN") (command "-layer" "thaw" "SV_WTR_LIN" ""))
当做
杰米
另一个:
(defun isFrozen (layname)
(eq 1 (logand 1 (cdr (assoc 70 (entget (tblobjname "LAYER" layname)))))))
Jammie我喜欢autolisp路线,即使我需要输入更多,我也相当了解我正在输入的内容。我的问题是如何定义分层冻结?我认为李有这个想法,但我不知道如何使它工作。如果你们有时间,可以让它为我工作,我将不胜感激,因为我正在学习在每一行代码旁边键入注释。这将帮助我理解不同的命令在做什么。 我更喜欢在VL中进行:
(defun c:test nil
(vl-load-com)
(vlax-for layer (vla-get-Layers
(vla-get-ActiveDocument
(vlax-get-acad-object)))
(if (vl-position (vla-get-name layer) '("Layer1" "Layer2"))
(progn
(vla-put-freezelayer :vlax-false)
(vla-put-layeron layer :vlax-true))
(vla-put-layeron layer :vlax-false)))
(and (tblsearch "LAYER" "Layer1")
(setvar "CLAYER" "Layer1"))
(princ))
页:
[1]
2