旧代码:“cmdecho”错误
你好我有一些代码,可能是这个网站上的人写的,我想稍微修改一下。然而,我遇到了麻烦。该命令运行良好,但只是在pline命令之后爆炸,并且不会重置系统变量。代码如下:
;//////////////////////////////////////////////////////////////////////////
;
; Start-Up Function
;
(defun C:ESS (/ SUCE SUOM SUSM SUAB SUAD SUCL SUCR)
(setq SUCE (getvar "cmdecho"))
(setq SUOM (getvar "orthomode"))
(setq SUSM (getvar "osmode"))
(setq SUAB (getvar "angbase"))
(setq SUAD (getvar "angdir"))
(setq SUCL (getvar "clayer"))
(setq SUCR (getvar "cecolor"))
(ESS_MF)
(princ)
)
;
;//////////////////////////////////////////////////////////////////////////
;
; Main Function
;
(defun ESS_MF (/ SIZE$ SIZE MIDPT PLEN PT01PT02 a b COLR SUCE SUOM SUSM SUAB SUAD SUCL SUCR)
(setq temperr *error*)
(setq *error* ESS_ETRAP)
(entmake
(list
(cons 0 "STYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbTextStyleTableRecord")
(cons 2 "CCC_Services")
(cons 3 "Verdana.ttf")
(cons 40 0)
(cons 70 0)
)
)
(setq S1_list '( "1500mm""1350mm" "1200mm" "1050mm" "900mm" "750mm" "675mm" "600mm" "525mm" "450mm" "375mm" "300mm" "225mm" "150mm"))
(setq dcl_id (load_dialog "ESS.dcl"))
(if
(not
(new_dialog "ESS" dcl_id)
)
(progn
(ALERT "Can not find your dcl file")
(exit)
)
)
(start_list "S1")
(mapcar 'add_list S1_list)
(end_list)
(if SIZE:DEF
(set_tile "S1" (itoa SIZE:DEF))
)
(action_tile "cancel"
"(done_dialog)(setq userclick nil)"
)
(action_tile "accept"
(strcat
"(progn
(setq S:IZE (atoi (get_tile \"S1\")) SIZE:DEF S:IZE)"
"(done_dialog)(setq userclick T))"
)
)
(start_dialog)
(unload_dialog dcl_id)
(if userclick
(ESS_VARIABLE)
)
(princ)
)
;
;//////////////////////////////////////////////////////////////////////////
;
; ESS_VARIABLE Function
;
(defun ESS_VARIABLE ()
(progn
(setq SIZE$ (fix S:IZE))
(setq SIZE$ (nth S:IZE S1_list))
(cond
((= SIZE$ "1500mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E1500")(setq LTYP "E1500"))
((= SIZE$ "1350mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E1350")(setq LTYP "E1500"))
((= SIZE$ "1200mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E1200")(setq LTYP "E1500"))
((= SIZE$ "1050mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E1050")(setq LTYP "E1500"))
((= SIZE$ "900mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E900")(setq LTYP "E1500"))
((= SIZE$ "750mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E750")(setq LTYP "E1500"))
((= SIZE$ "675mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E675")(setq LTYP "E1500"))
((= SIZE$ "600mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E600")(setq LTYP "E1500"))
((= SIZE$ "525mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E525")(setq LTYP "E1500"))
((= SIZE$ "450mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E450")(setq LTYP "E1500"))
((= SIZE$ "375mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E375")(setq LTYP "E1500"))
((= SIZE$ "300mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E300")(setq LTYP "E1500"))
((= SIZE$ "225mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E225")(setq LTYP "E1500"))
((= SIZE$ "150mm")(setq SIZE$ "Existing_Drainage_Storm_Sewer_Concrete_E150")(setq LTYP "E1500"))
)
)
(setq SIZE SIZE$)
(ESS_OUTPUT)
(princ)
)
;
;//////////////////////////////////////////////////////////////////////////
;
; ESS_OUTPUT Function
;
(defun ESS_OUTPUT ()
(setq a (strcat "CCC_DR_"LTYP)
b (strcat "CCC_SERVICES_"SIZE)
)
(if
(not
(tblsearch "LTYPE" a)
)
(command "_.-linetype" "_l" a "CCC_Drainage_Existing Storm.lin" "")
)
(command "_.-layer" "_N" b "_M" b "_L" a b "_C" "84" b "_LW" "0.3" b "" )
(command "_-color""bylayer")
(command "._-linetype""s""bylayer" "")
(setvar "angbase" 0.0000)
(setvar "cmdecho" 1)
(setvar "angdir"0)
(setvar "clayer" b)
(setvar "orthomode" 0)
(setvar "osmode" 16383)
(setvar "angbase" 0.0000)
(command "_.-layer" "_S" b "")
;(setvar "plinegen" 1)
(command "._pline")
(setvar "osmode" 16383)
(setq *error* temperr)
(setvar "cmdecho" SUCE)
(setvar "orthomode" SUOM)
(setvar "osmode" SUSM)
(setvar "angbase" SUAB)
(setvar "angdir" SUAD)
(setvar "clayer" SUCL)
(setvar "cecolor" SUCR)
(princ)
)
;
;//////////////////////////////////////////////////////////////////////////
;
; Error Trap Function
;
(defun ESS_ETRAP (errmsg)
(command nil nil nil)
(if
(not
(member errmsg '("console break" "Function Cancelled"))
)
(princ (strcat "\nError:" errmsg))
)
(setvar "cmdecho" SUCE)
(setvar "orthomode" SUOM)
(setvar "osmode" SUSM)
(setvar "angbase" SUAB)
(setvar "angdir" SUAD)
(princ "\nError, Restoring ESS_VARIABLEs.")
(terpri)
(setq *error* temperr)
(princ)
)
;
;//////////////////////////////////////////////////////////////////////////
以下是end命令的转储,其中包含错误:
Current layer:"CCC_SERVICES_Existing_Drainage_Storm_Sewer_Concrete_E1500"
Enter an option
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: _S
Enter layer name to make current or <select object>:
CCC_SERVICES_Existing_Drainage_Storm_Sewer_Concrete_E1500 Enter an option
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
Command: ._pline
Specify start point: AutoCAD variable setting rejected: "cmdecho" nil
Specify start point:
Current line-width is 0.000
Specify next point or :
Specify next point or :
Specify next point or :
Specify next point or :
如果有人能帮我解决这个错误,我将不胜感激。
谢谢 有些变量两次本地化,因此atempt无法恢复环境:
(defun ESS_MF (/ SIZE$ SIZE MIDPT PLEN PT01PT02 a b COLR SUCE SUOM SUSM SUAB SUAD SUCL SUCR)
你希望用这段代码实现什么?允许用户交互绘制多段线?
(command "._pline") 对让用户绘制多段线并在完成时重置系统变量。这是一个稍有不同的代码版本,但它在pline命令后爆炸,并且不会重置系统变量。有人能帮忙吗?
;//////////////////////////////////////////////////////////////////////////
;
; Start-Up Function
;
(defun C:PRWMDIA (/ HOLE$ SIZE$ HOLE SIZE PT01 PT02 a b lw DEGREES RADIANS)
(PRWMDIA_SAVE)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; Save User Settings Function.
;
(defun PRWMDIA_SAVE (/ SUS SUCE SUOM SUSM SUAB SUAD SUCL SUCR)
(setq SUS_LIST (list "cmdecho" "orthomode" "osmode" "blipmode" "clayer" "angbase" "angdir" "cecolor"))
(setq TERR$ *error*)
(setq *error* PRWMDIA_ETRAP)
(PRWMDIA_MF)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; Main Function
;
(defun PRWMDIA_MF ()
(setq T1_list '("Type A" "Type B"))
(setq S1_list '("300mm" "250mm" "200mm" "150mm" "100mm"))
(setq dcl_id (load_dialog "PRWMDIA.dcl"))
(if (not (new_dialog "PRWMDIA" dcl_id))
(progn (ALERT "Can not find your dcl file")
(exit)))
(start_list "T1")
(mapcar 'add_list T1_list)
(end_list)
(start_list "S1")
(mapcar 'add_list S1_list)
(end_list)
(if HOLE:DEF (set_tile "T1" (itoa HOLE:DEF)))
(if SIZE:DEF (set_tile "S1" (itoa SIZE:DEF)))
(action_tile "cancel" "(done_dialog)(setq userclick nil)")
(action_tile "accept"
(strcat
"(progn
(setq H:OLE (atoi (get_tile \"T1\")) HOLE:DEF H:OLE)"
"(setq S:IZE (atoi (get_tile \"S1\")) SIZE:DEF S:IZE)"
"(done_dialog)(setq userclick T))"))
(start_dialog)
(unload_dialog dcl_id)
(if userclick
(PRWMDIA_VARIABLE))
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; PRWMDIA_VARIABLE Function
;
(defun PRWMDIA_VARIABLE ()
(progn
(setq HOLE$ (fix H:OLE))
(setq HOLE$ (nth H:OLE T1_list))
(cond
((= HOLE$ "Type A"))
((= HOLE$ "Type B"))))
(setq HOLE HOLE$)
(progn
(setq SIZE$ (fix S:IZE))
(setq SIZE$ (nth S:IZE S1_list))
(cond
((= SIZE$"300mm")(setq SIZE$"300D"))
((= SIZE$"250mm")(setq SIZE$"250D"))
((= SIZE$"200mm")(setq SIZE$"200D"))
((= SIZE$"150mm")(setq SIZE$"150D"))
((= SIZE$"100mm")(setq SIZE$"100D"))))
(setq SIZE SIZE$)
(PRWMDIA_OUTPUT)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; PRWMDIA_OUTPUT Function
;
(defun PRWMDIA_OUTPUT ()
(if (null (tblsearch "STYLE" "CCC_Services"))
(entmake
(list
(cons 0 "STYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbTextStyleTableRecord")
(cons 2 "CCC_Services")
(cons 3 "Verdana.ttf")
(cons 40 0)
(cons 70 0))))
(setq a(strcat "CCC_WM_"SIZE"_"HOLE)
b(strcat "CCC_SERVICES_PROPOSED_Watermain_Ductile_Iron_"SIZE"_"HOLE)
lw 30)
(if (null (tblsearch "LTYPE" a))
(command "_.-linetype" "_l" a "CCC_Watermain_DI.lin" ""))
(if (null (tblsearch "LAYER" b))
(command "_.-layer" "_N" b "_M" b "_L" a b "_C" "30" b "_LW" "0.3" b "" ))
(command "_-color""bylayer")
(command "._-linetype""s""bylayer" "")
(setvar "cmdecho" 0)
(setvar "angbase" 0.0000)
(setvar "angdir"0)
(setvar "orthomode" 0)
(setvar "osmode" 16383)
(command "_.-layer" "_S" b "")
(setvar "plinegen" 1)
(command "._pline")
(PRWMDIA_RESTORE)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; Degrees to Radians Function
;
(defun PRWMDIA_DTR (DEGREES)
(* pi (/ DEGREES 180.0)))
;
;//////////////////////////////////////////////////////////////////////////
;
; Radians to Degrees Function
;
(defun PRWMDIA_RTD (RADIANS)
(* 180.0 (/ RADIANS pi)))
;
;//////////////////////////////////////////////////////////////////////////
;
; Restore User Settings Function.
;
(defun PRWMDIA_RESTORE ()
(setq *error* TERR$)
(if SUS (mapcar 'setvar SUS_LIST SUS))
(princ "\nProgram completed and will now restore the user settings and exit.")
(princ))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Error Trap Function.
;
(defun PRWMDIA_ETRAP (ERRORMSG)
(command nil nil nil)
(if (not (member ERRORMSG '("console break" "Function cancelled")))
(princ (strcat "\nError:" ERRORMSG)))
(if SUS (mapcar 'setvar SUS_LIST SUS))
(princ "\nAn *error* has occured!")
(princ "\nThe program will now restore the user settings and exit.")
(terpri)
(setq *error* TERR$)
(princ))
;
;////////////////////////////////////////////////////////////////////////// 伍德曼78,
这些条件语句是螺母,每个(第一个示例和第二个示例)只需要1行代码。
(setq SIZE$ (strcat "Existing_Drainage_Storm_Sewer_Concrete_E" (itoa(atoi SIZE$)))
LTYP "E1500")
)
(setqSIZE$ (strcat (itoa(atoi SIZE$)) "D"))
布鲁斯 在运行函数之前,似乎没有在SUS变量列表中定义系统变量值,因此没有保存任何原始系统设置。您定义了系统设置列表“SUS_list”,以更改但不更改其原始值。您应该在定义系统设置列表的同时定义SUS变量。 谢谢斯诺努特。如何定义SUS变量。 用当前函数替换现有函数。
我没有测试任何东西,只是看到了这个错误。
(defun PRWMDIA_SAVE (/SUCE SUOM SUSM SUAB SUAD SUCL SUCR)
(setq SUS_list '(cmdecho orthomode osmode blipmode clayer angbase angdir cecolor)
SUS (mapcar 'getvar SUS_list)
TERR$ *error*
*error* PRWMDIA_ETRAP
)
(PRWMDIA_MF)
(princ)
)
然后,要重置系统变量,您需要使用它。
(mapcar 'setvar SUS_list SUS)
谢谢Snownut,
我做了这些更改,但系统变量仍然没有重置:
;//////////////////////////////////////////////////////////////////////////
;
; Start-Up Function
;
(defun C:PRWMDIA (/ HOLE$ SIZE$ HOLE SIZE PT01 PT02 a b lw DEGREES RADIANS)
(PRWMDIA_SAVE)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; Save User Settings Function.
;
(defun PRWMDIA_SAVE (/ SUS SUCE SUOM SUSM SUAB SUAD SUCL SUCR)
;(setq SUS_LIST (list "cmdecho" "orthomode" "osmode" "blipmode" "clayer" "angbase" "angdir" "cecolor"))
;(setq TERR$ *error*)
;(setq *error* PRWMDIA_ETRAP)
(setq SUS_list '(cmdecho orthomode osmode blipmode clayer angbase angdir cecolor))
SUS (mapcar 'getvar SUS_list)
TERR$ *error*
*error* PRWMDIA_ETRAP
(PRWMDIA_MF)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; Main Function
;
(defun PRWMDIA_MF ()
(setq T1_list '("Type A" "Type B"))
(setq S1_list '("300mm" "250mm" "200mm" "150mm" "100mm"))
(setq dcl_id (load_dialog "PRWMDIA.dcl"))
(if (not (new_dialog "PRWMDIA" dcl_id))
(progn (ALERT "Can not find your dcl file")
(exit)))
(start_list "T1")
(mapcar 'add_list T1_list)
(end_list)
(start_list "S1")
(mapcar 'add_list S1_list)
(end_list)
(if HOLE:DEF (set_tile "T1" (itoa HOLE:DEF)))
(if SIZE:DEF (set_tile "S1" (itoa SIZE:DEF)))
(action_tile "cancel" "(done_dialog)(setq userclick nil)")
(action_tile "accept"
(strcat
"(progn
(setq H:OLE (atoi (get_tile \"T1\")) HOLE:DEF H:OLE)"
"(setq S:IZE (atoi (get_tile \"S1\")) SIZE:DEF S:IZE)"
"(done_dialog)(setq userclick T))"))
(start_dialog)
(unload_dialog dcl_id)
(if userclick
(PRWMDIA_VARIABLE))
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; PRWMDIA_VARIABLE Function
;
(defun PRWMDIA_VARIABLE ()
(progn
(setq HOLE$ (fix H:OLE))
(setq HOLE$ (nth H:OLE T1_list))
(cond
((= HOLE$ "Type A"))
((= HOLE$ "Type B"))))
(setq HOLE HOLE$)
(progn
(setq SIZE$ (fix S:IZE))
(setq SIZE$ (nth S:IZE S1_list))
(cond
((= SIZE$"300mm")(setq SIZE$"300D"))
((= SIZE$"250mm")(setq SIZE$"250D"))
((= SIZE$"200mm")(setq SIZE$"200D"))
((= SIZE$"150mm")(setq SIZE$"150D"))
((= SIZE$"100mm")(setq SIZE$"100D"))))
(setq SIZE SIZE$)
(PRWMDIA_OUTPUT)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; PRWMDIA_OUTPUT Function
;
(defun PRWMDIA_OUTPUT ()
(if (null (tblsearch "STYLE" "CCC_Services"))
(entmake
(list
(cons 0 "STYLE")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbTextStyleTableRecord")
(cons 2 "CCC_Services")
(cons 3 "Verdana.ttf")
(cons 40 0)
(cons 70 0))))
(setq a(strcat "CCC_WM_"SIZE"_"HOLE)
b(strcat "CCC_SERVICES_PROPOSED_Watermain_Ductile_Iron_"SIZE"_"HOLE)
lw 30)
(if (null (tblsearch "LTYPE" a))
(command "_.-linetype" "_l" a "CCC_Watermain_DI.lin" ""))
(if (null (tblsearch "LAYER" b))
(command "_.-layer" "_N" b "_M" b "_L" a b "_C" "30" b "_LW" "0.3" b "" ))
(command "_-color""bylayer")
(command "._-linetype""s""bylayer" "")
(setvar "cmdecho" 0)
(setvar "angbase" 0.0000)
(setvar "angdir"0)
(setvar "orthomode" 0)
(setvar "osmode" 16383)
(command "_.-layer" "_S" b "")
(setvar "plinegen" 1)
(command "._pline")
(PRWMDIA_RESTORE)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
;
; Degrees to Radians Function
;
(defun PRWMDIA_DTR (DEGREES)
(* pi (/ DEGREES 180.0)))
;
;//////////////////////////////////////////////////////////////////////////
;
; Radians to Degrees Function
;
(defun PRWMDIA_RTD (RADIANS)
(* 180.0 (/ RADIANS pi)))
;
;//////////////////////////////////////////////////////////////////////////
;
; Restore User Settings Function.
;
(defun PRWMDIA_RESTORE ()
(setq *error* TERR$)
(mapcar 'setvar SUS_LIST SUS)
(princ "\nProgram completed and will now restore the user settings and exit.")
(princ))
;
;/////////////////////////////////////////////////////////////////////////////
;
; Error Trap Function.
;
(defun PRWMDIA_ETRAP (ERRORMSG)
(command nil nil nil)
(if (not (member ERRORMSG '("console break" "Function cancelled")))
(princ (strcat "\nError:" ERRORMSG)))
(if SUS (mapcar 'setvar SUS_LIST SUS))
(princ "\nAn *error* has occured!")
(princ "\nThe program will now restore the user settings and exit.")
(terpri)
(setq *error* TERR$)
(princ))
;
;//////////////////////////////////////////////////////////////////////////
我在运行命令后查看了命令行转储,看起来程序似乎在运行pline命令之前完成。
Enter name list of layers(s) for lineweight 0.30mm
<CCC_SERVICES_PROPOSED_Watermain_Ductile_Iron_300D_Type A>:
CCC_SERVICES_PROPOSED_Watermain_Ductile_Iron_300D_Type A Enter an option
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
Command: _-color
Enter default object color <BYLAYER>: bylayer
Command: ._-linetype
Current line type:"ByLayer"
Enter an option [?/Create/Load/Set]: s
Specify linetype name or [?] <ByLayer>: bylayer
Enter an option [?/Create/Load/Set]:
Command:
Program completed and will now restore the user settings and exit.
Specify start point:
Current line-width is 0.000
Specify next point or :
Specify next point or :
Specify next point or :
Specify next point or :
再次感谢您的帮助。谢谢 如果有人能帮我,我将不胜感激! 伍德曼78,
右括号放错了地方。
应该是;
页:
[1]
2