Author Topic: command argu changed when the layer is exist or not.  (Read 901 times)

0 Members and 1 Guest are viewing this topic.

haibinpro

  • Newt
  • Posts: 52
command argu changed when the layer is exist or not.
« on: December 04, 2021, 07:06:23 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun ff:makelayer-aci(#name #acicolor #linetype #printable / @clayer)
  2.   (setvar "cmdecho" 0)
  3.   (setq @clayer (getvar "clayer"))
  4.   (if (null (tblsearch "layer" #name))
  5.     (command "layer" "m" #name
  6.              "c" #acicolor #name
  7.              "l" #linetype #name
  8.              "p" #printable #name
  9.              ""
  10.     )
  11.   )
  12.   (setvar "clayer" @clayer)
  13.   (princ)
  14. )
  15. (defun ff:change2layer(#name #ss)
  16.   (setvar "cmdecho" 0)
  17.   (if (tblsearch "layer" #name)
  18.     (command "change" #ss ""
  19.              "P"
  20.              "la" #name
  21.              "c"  "bylayer"
  22.              "lt" "bylayer"
  23.              ""
  24.     )
  25.   )
  26.   (princ)
  27. )
  28. (defun ff:change2layer2(#name #ss)
  29.   (setvar "cmdecho" 0)
  30.   (if (tblsearch "layer" #name)
  31.     (command "change"
  32.              "P"
  33.              "la" #name
  34.              "c"  "bylayer"
  35.              "lt" "bylayer"
  36.              ""
  37.     )
  38.   )
  39.   (princ)
  40. )
  41. (defun ff:toggle2layer(#name #acicolor #linetype #printable / @ss)
  42.   (setvar "cmdecho" 0)
  43.  
  44.   (if (entlast)
  45.     (setq @ss (ssget "_i"))
  46.   )
  47.   (if @ss
  48.     (if (tblobjname "layer" #name)
  49.       (ff:change2layer2 #name @ss)
  50.       (progn
  51.         (ff:makelayer-aci #name #acicolor #linetype #printable)
  52.         (ff:change2layer #name @ss)
  53.       )
  54.     )
  55.     (if (tblobjname "layer" #name)
  56.       (setvar "clayer" #name)
  57.       (progn
  58.         (ff:makelayer-aci #name #acicolor #linetype #printable)
  59.         (setvar "clayer" #name)
  60.       )
  61.     )
  62.   )
  63.   (princ)
  64. )
  65.  
the reason is after use function ff:makelayer-aci,the object have choose will become unchoosed.
« Last Edit: December 04, 2021, 09:42:43 AM by haibinpro »

mhupp

  • Bull Frog
  • Posts: 250
Re: command argu changed when the layer is exist or not.
« Reply #1 on: December 05, 2021, 09:24:38 PM »
  • ff:change2layer and ff:change2layer2 do the same thing.
  • You don't need to do a table search again in ff:change2layer when the if statement that calls it has already did that check. (unless you use it somewhere else without this check add it back in)
  • no need to turn off cmdecho in the other functions because you turned it off in ff:toggle2layer you also need to turn it back on again
  • Someone correct me on this but I don't think you can pass selection set to other functions but you can call them. or you cant do it by the vairable name @ss it has to be <Selection set: 3e41e4e0>
  • Once you take all those things out you can merge it down to one function again.
Code - Auto/Visual Lisp: [Select]
  1. (defun ff:toggle2layer (#name #acicolor #linetype #printable / @ss)
  2.   (setvar "cmdecho" 0)
  3.   (if (setq @ss (ssget "_i"))
  4.     (if (tblobjname "layer" #name)
  5.       (command "_.Chprop" @ss "" "la" #name "C" "ByLayer" "LT" "ByLayer" "")
  6.       (progn
  7.         (setq @clayer (getvar "clayer"))
  8.         (command "-Layer" "M" #name "C" #acicolor #name "L" #linetype #name "Plot" #printable #name "")
  9.         (setvar "clayer" @clayer)
  10.         (command "_.Chprop" @ss "" "la" #name "C" "ByLayer" "LT" "ByLayer" "")
  11.       )
  12.     )
  13.     (if (tblobjname "layer" #name)
  14.       (setvar "clayer" #name)
  15.       (command "-Layer" "M" #name "C" #acicolor #name "L" #linetype #name "Plot" #printable #name "")
  16.     )
  17.   )
  18.   (setvar "cmdecho" 1)
  19.   (princ)
  20. )
« Last Edit: December 05, 2021, 09:49:33 PM by mhupp »