I have this code for sending command to Autocad. It works OK.
{
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
}Tried to create function with Layer parameter
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}
}Doesn't work as expected, tried figure out why...
ACADChangeLayer(Layer) { GetAcad() global ACAD msgbox, % acad.activedocument.name msgbox, %Layer% CommandSetActiveLayer:= ("_-LAYER _SET " %Layer% " `n`n") msgbox, %CommandSetActiveLayer% ... }First MsgBox shows proper DocumentName (
drawing1.dwg)Second MsgBoxu shows Proper LayerName (
Layer_Name- see second code block above)Third MsgBox shows only part before variable (
"_-LAYER _SET ") Why?
Thank you for advice.
31 Answer
The problem is the assignment line that should be written as one of the following:
CommandSetActiveLayer := "_-LAYER _SET " . Layer . "`n`n"
CommandSetActiveLayer := ("_-LAYER _SET " . Layer . "`n`n")
CommandSetActiveLayer = "_-LAYER _SET " %Layer% `n`nThe first two lines use the newer expression method with the concatenate operator
(dot .), while the second line uses the traditional method.
Reference : Variables and Expressions.
3