LISP for:如果图层冻结
您好,我找到并修改了一个lisp例程,我想知道它是否在正确的轨道上。还要提到的是,我并不真正理解它的所有机制,但首先,我想实现以下目标:-我有一层名为“Arch-Niveau 1”
-我想进入命令提示符“a11”
-它会读到如果层被冻结或解冻,如果它被冻结,它会解冻它(?对不起,糟糕的英语),如果层被解冻,它会冻结它
就是这样!
可以添加的是:
要检查层是否存在,如果不存在,请创建它。
将对另外两个名为“Arch-Niveau 2”命令“a22”和“Arch-Niveau 3”命令“a33”的层执行相同的操作。清楚了吗?
现在,我找到并修改的lisp是:
(defun c:a11 (/ lay ldef flag)
(setq layn "Arch - Niveau 1")
(command "_.LAYER")
(if (not (tblsearch "LAYER" layn))
(command "_Make" layn)
(progn
(setq ldef (tblsearch "LAYER" layn)
flag (cdr (assoc 70 ldef)))
(and (= (logand flag1)1)
(command "_Thaw" layn))
))
(command "")
)
该lisp会查看它是否存在,如果不存在,则创建它并仅解冻该层。
我不确定我是否想理解所有的机制,因为我对“not”、“progn”、“flag”、“and”和“logand”(!!!!)
你能帮我完成Lisp程序吗?
谢谢! 嗨,Troispistols,欢迎来到CADTutor
对于您的任务,我会将创建、冻结或解冻层的操作委托给子功能,并将层名称传递给子功能,例如:
(defun c:a11 nil (FreezeThawLayer "Arch - Niveau 1"))
(defun c:a22 nil (FreezeThawLayer "Arch - Niveau 2"))
(defun c:a33 nil (FreezeThawLayer "Arch - Niveau 3"))
(defun FreezeThawLayer ( layer / dx en )
(if (null (setq en (tblobjname "LAYER" layer)))
(entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 layer)
'(70 . 0)
)
)
(setq en (entget en)
dx (assoc 70 en)
en (entmod (subst (cons 70 (boole 6 1 (cdr dx))) dx en))
)
)
(princ)
) 哇!我很高兴你的回答非常迅速有效!谢谢你抽出时间,我很高兴!
在一个有两个矩形的新图形中,它工作得很好,但在我现有的图形中,有时工作有时不工作。
现在我关闭Acad并重新打开我的绘图,重新加载lisp,当我点击“a1”时什么也没有发生(是的,我将其更改为“a1”而不是“a11”)
(defun c:a1 nil (FreezeThawLayer "Arch - Niveau 1"))
(defun c:a2 nil (FreezeThawLayer "Arch - Niveau 2"))
(defun c:a3 nil (FreezeThawLayer "Arch - Niveau 3"))
(defun FreezeThawLayer ( layer / dx en )
(if (null (setq en (tblobjname "LAYER" layer)))
(entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 layer)
'(70 . 0)
)
)
(setq en (entget en)
dx (assoc 70 en)
en (entmod (subst (cons 70 (boole 6 1 (cdr dx))) dx en))
)
)
(princ)
)
谢谢,我希望你能帮我 不客气
有关我在代码中使用的技术的信息,请参阅以下链接:
图层DXF参考
布尔异或技术
使用Entmake(x)创建层 Troispistols,请阅读代码发布指南并编辑您的帖子以格式化代码。 我编辑了最后一个答案,希望能再次得到帮助,谢谢
该程序每次对我来说都能工作,它是一个简单的代码,所以我不知道是什么导致它失败的-层是否正在冻结/解冻,但对象可能没有更新?
也许这会解决这个问题:
(defun c:a1 nil (FreezeThawLayer "Arch - Niveau 1"))
(defun c:a2 nil (FreezeThawLayer "Arch - Niveau 2"))
(defun c:a3 nil (FreezeThawLayer "Arch - Niveau 3"))
(defun FreezeThawLayer ( layer / dx en in ss )
(if (null (setq en (tblobjname "LAYER" layer)))
(entmake
(list
'(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
(cons 2 layer)
'(70 . 0)
)
)
(if
(and
(setq en (entget en)
dx (assoc 70 en)
en (entmod (subst (cons 70 (boole 6 1 (cdr dx))) dx en))
)
(setq ss (ssget "_X" (list (cons 8 layer))))
)
(repeat (setq in (sslength ss))
(entupd (ssname ss (setq in (1- in))))
)
)
)
(princ)
) 好的,谢谢。它似乎已经解决了问题。这是一个“建筑平面图”的一个区块,其中三层中的每一层都有许多层(一个区块对应一层),如果它能帮助你理解发生了什么的话。
谢谢,看起来很好!
给人印象深刻的 太好了,很高兴我的代码现在能为你工作 哦
现在,我第一次无法通过单击工具栏上的按钮打开图层管理器(设置为旧图层管理器变量),该按钮显示:
http://www.imagemoi.com/images/500/26a87bf13af9cb44c89f5660b7867395.jpg
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
at Autodesk.AutoCAD.DatabaseServices.Database.set_Clayer(ObjectId id)
at Autodesk.AutoCAD.LayerManager.LayerViewManager.set_CurrentLayer(LayerRecord value)
at Autodesk.AutoCAD.LayerManager.LayerViewManager.UpdateCurrentLayerAndView()
at Autodesk.AutoCAD.LayerManager.LayerManagerControl.LoadConfiguration(Boolean bCheckExcessFilters)
at Autodesk.AutoCAD.LayerManager.LayerManagerControl.InitializeLayerManager(Boolean bCheckExcessFilters)
at Autodesk.AutoCAD.LayerManager.LayerManagerControl.Initialize(Boolean bCheckExcessFilters)
at Autodesk.AutoCAD.LayerManager.MainForm.Initialize()
at Autodesk.AutoCAD.LayerManager.MainForm.RunForm(IntPtr owner, LayerFilter filter)
at Autodesk.AutoCAD.LayerManager.Commands.Layer()
at Autodesk.AutoCAD.LayerManager.Commands.RunLayer()
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.225 (RTMGDR.030319-2200)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
AdApplicationFrame
Assembly Version: 0.0.0.0
Win32 Version: 3.2.23.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AdApplicationFrame.DLL
----------------------------------------
Acdbmgd
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcdbMgd.DLL
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
msvcm90
Assembly Version: 9.0.30729.4940
Win32 Version: 9.00.30729.4940
CodeBase: file:///C:/Windows/WinSxS/amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_08e4299fa83d7e3c/msvcm90.dll
----------------------------------------
AdWindows
Assembly Version: 3.2.25.0
Win32 Version: 3.2.25.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AdWindows.DLL
----------------------------------------
PresentationFramework
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.dll
----------------------------------------
WindowsBase
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsBase/v4.0_4.0.0.0__31bf3856ad364e35/WindowsBase.dll
----------------------------------------
PresentationCore
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_64/PresentationCore/v4.0_4.0.0.0__31bf3856ad364e35/PresentationCore.dll
----------------------------------------
System.Xaml
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xaml/v4.0_4.0.0.0__b77a5c561934e089/System.Xaml.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
PresentationFramework.Aero
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/PresentationFramework.Aero/v4.0_4.0.0.0__31bf3856ad364e35/PresentationFramework.Aero.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Acmgd
Assembly Version: 18.2.0.0
Win32 Version: 18.2.107.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/Acmgd.DLL
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
AcWindows
Assembly Version: 18.2.0.0
Win32 Version: 18.2.107.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcWindows.DLL
----------------------------------------
AcCui
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcCui.DLL
----------------------------------------
WindowsFormsIntegration
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/WindowsFormsIntegration/v4.0_4.0.0.0__31bf3856ad364e35/WindowsFormsIntegration.dll
----------------------------------------
AcWindows.resources
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcWindows.resources.DLL
----------------------------------------
ManagedMC3
Assembly Version: 5.8.0.0
Win32 Version: 5.8.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/ManagedMC3.DLL
----------------------------------------
AcLayer
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcLayer.DLL
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
AcLayer.resources
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcLayer.resources.DLL
----------------------------------------
AcButterflyExt
Assembly Version: 1.0.0.23
Win32 Version: 1.0.0.23
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcButterflyExt.DLL
----------------------------------------
AcButterflyExt.resources
Assembly Version: 1.0.0.23
Win32 Version: 1.0.0.23
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcButterflyExt.resources.DLL
----------------------------------------
mscorlib.resources
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.resources
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.resources/v4.0_4.0.0.0_fr_b77a5c561934e089/System.resources.dll
----------------------------------------
UIAutomationProvider
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationProvider/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationProvider.dll
----------------------------------------
Accessibility
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
UIAutomationTypes
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.1 built by: RTMRel
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/UIAutomationTypes/v4.0_4.0.0.0__31bf3856ad364e35/UIAutomationTypes.dll
----------------------------------------
AcDialogToolTips
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcDialogToolTips.DLL
----------------------------------------
AcDialogToolTips.resources
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcDialogToolTips.resources.DLL
----------------------------------------
AcLayerTools
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/AcLayerTools.DLL
----------------------------------------
AcLayerTools.resources
Assembly Version: 18.2.0.0
Win32 Version: 18.2.51.0.0
CodeBase: file:///C:/Program%20Files/Autodesk/AutoCAD%202012%20-%20English/en-US/AcLayerTools.resources.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT de****** registered on the computer
rather than be handled by this dialog box.
你知道是什么原因造成的吗?怎么才能把它弄回来?
页:
[1]
2