我有这个代码用于向 Autocad 发送命令。它工作正常。
{
GetAcad() ;Creates global variable ACAD where Application Object is stored
CADdoc:= ACAD.activedocument
Layer:= "0"
CADdoc.SendCommand("_-LAYER _SET " %Layer% " `n`n") ;;Uses COM
CADdoc.SendCommand("_CHPROP _LA " %Layer% " `n`n") ;;Uses COM
sleep, 50
send, {Escape}
sleep, 50
send, {Escape}
return
}
尝试使用 Layer 参数创建函数
ACADChangeLayer("Layer_Name") ;This is how is the function called
ACADChangeLayer(Layer)
{
GetAcad()
global ACAD ;because I global variable has given value outside this function
ACAD.activedocument.SendCommand("_-LAYER _SET " %Layer% " `n`n")
ACAD.activedocument.SendCommand("_CHPROP _LA " %Layer% " `n`n")
sleep, 50
send, {Escape}
sleep, 50
send, {Escape}
}
没有按预期工作,尝试找出原因...
ACADChangeLayer(Layer)
{
GetAcad()
global ACAD
msgbox, % acad.activedocument.name
msgbox, %Layer%
CommandSetActiveLayer:= ("_-LAYER _SET " %Layer% " `n`n")
msgbox, %CommandSetActiveLayer%
...
}
第一个 MsgBox 显示正确的 DocumentName (
drawing1.dwg
)第二个 MsgBoxu 显示正确的 LayerName(
Layer_Name
- 请参见上面的第二个代码块)第三个 MsgBox 只显示变量 (
"_-LAYER _SET "
)之前的部分为什么?
谢谢你的建议。