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% ... } 
  1. First MsgBox shows proper DocumentName (drawing1.dwg)

  2. Second MsgBoxu shows Proper LayerName (Layer_Name - see second code block above)

  3. Third MsgBox shows only part before variable ("_-LAYER _SET ") Why?

Thank you for advice.

enter image description here

3

1 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`n 

The 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy