Code Red > AutoLISP (Vanilla / Visual)

Setvar variable not automatically setting layer active

(1/3) > >>

Cuddles:
Hello All,

Been a while since I've been here. Hope everyone's 2017 is off to a good start.

I'm currently having a small issue regarding the use of some old code of mine.
This program essentially allows the user to set active the layer of a user picked entity - pretty damn simple!
However, once the user has picked the desired object/entity, the program does not immediately update the layer control toolbar, only doing so once the user regenerates the drawing. This has been happening since the installation of AutoCAD 2017 on my work PC. No other versions of CAD have had this issue.

I find this behavior strange and something that has never happened before. I can only assume no issue with the code but perhaps a setting in AutoCAD itself. I have tested this code on another users PC using AutoCAD 2017 with no issues whatsoever.

Code is attached for testing.

Any thoughts, fixes, comments are welcome.

Thanks,
Bevan

Marc'Antonio Alessi:
Have you tried:
(vla-put-ActiveLayer VlaDoc LyrObj)
Or
(command "_.LAYER" "_S" lay "")

Instead of:
(setvar 'clayer lay)

Cuddles:
Hello Marc,

I have tried both options as you mentioned.

"Command" - no problems. However, i generally like to avoid using this.
Tried the vla approach - obtained the same result as per my original post. Had to regenerate the drawing for it to show. This was another person's vla code and not my own I tested with. I don't know visual lisp very well. Link here: http://autolispgs.blogspot.co.nz/2013/02/set-current-layer.html

I still find it odd that my original code worked on another users machine (AutoCAD 2017) without having to regenerate the drawing.

irneb:
You know of course ... there's a standard command for what you're doing here? I think it used to form part of the Express Tools, but it's definitely now part of base AutoCAD. The command is LAYMCUR.


There are others which may also be quite useful: http://www.cad-notes.com/10-autocad-layer-tools-you-might-forgotten/


These are very similar to stuff I was using in the late 80s through early 90s in ACad R9 through R12 as Lisp addons.

Marc'Antonio Alessi:

--- Quote from: irneb on February 21, 2017, 02:59:51 AM ---You know of course ... there's a standard command for what you're doing here? I think it used to form part of the Express Tools, but it's definitely now part of base AutoCAD. The command is LAYMCUR.
...
--- End quote ---
LAYMCUR (ex: ai_molc) use setvar:

--- Code: ---;;;=== Make Object's Layer Current =============================
;; Makes the layer of the selected object current.  If there is one
;; object in the pickfirst set, it's layer is made current without
;; prompting for an object.  Else a prompt is issued.
(defun c:ai_molc(/ old_error end_undo old_cmdecho set1 ent undo_control)
 ...
  ;; Make object's layer current.
  (setvar "clayer" (cdr (assoc '8 ent)))
 ...
)
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version