Author Topic: Setvar variable not automatically setting layer active  (Read 2378 times)

0 Members and 1 Guest are viewing this topic.

Cuddles

  • Guest
Setvar variable not automatically setting layer active
« on: February 20, 2017, 04:00:12 PM »
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

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Setvar variable not automatically setting layer active
« Reply #1 on: February 20, 2017, 04:36:50 PM »
Have you tried:
(vla-put-ActiveLayer VlaDoc LyrObj)
Or
(command "_.LAYER" "_S" lay "")

Instead of:
(setvar 'clayer lay)

Cuddles

  • Guest
Re: Setvar variable not automatically setting layer active
« Reply #2 on: February 20, 2017, 06:56:57 PM »
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

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Setvar variable not automatically setting layer active
« Reply #3 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.


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.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: Setvar variable not automatically setting layer active
« Reply #4 on: February 21, 2017, 04:42:28 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.
...
LAYMCUR (ex: ai_molc) use setvar:
Code: [Select]
;;;=== 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)))
 ...
)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Setvar variable not automatically setting layer active
« Reply #5 on: February 21, 2017, 09:19:50 AM »
LAYMCUR (ex: ai_molc) use setvar:
That's how it used to be done in the Express Tools set of LSPs. Since the Layer tools were incorporated direct into ACad that command is now an ObjectARX tool - at least 2015 through 2017 has it built in and no longer a LSP file (those are the only versions I've got installed to test here).


It updates the dropdown in the ribbon as well - so I'm guessing it uses the same API call as the Layer command does itself.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Setvar variable not automatically setting layer active
« Reply #6 on: February 21, 2017, 09:50:03 AM »
Quick test here and it refreshes fine in both 2016 & 2017 versions on the HOME>>LAYERS ribbon, but is broken using the 'Layers' toolbar on 2017.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:ls (/ e)
  2.   (if (setq e (car (entsel "\nSelect entity to set current layer: ")))
  3.     (setvar 'clayer (cdr (assoc 8 (entget e))))
  4.   )
  5.   (princ)
  6. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Cuddles

  • Guest
Re: Setvar variable not automatically setting layer active
« Reply #7 on: February 22, 2017, 02:10:39 PM »
Thanks for checking this ronjonp :-)
Pretty much the same scenario I encountered, which is probably why it worked on my colleagues machine (using Ribbons), whereas for myself not so using the classic toolbars. This is obviously an AutoCAD issue then.

Quote
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.
...

I know of this command 'LAYMCUR'. However, the command brings up an error when a user fails to select an object or right-click exits the command. Would be interesting to know other users experience this same problem.

ChrisCarlson

  • Guest
Re: Setvar variable not automatically setting layer active
« Reply #8 on: February 22, 2017, 02:50:20 PM »
Code: [Select]
Command:  LAYMCUR
Select object whose layer will become current:
*error*
Command:  LAYMCUR
Select object whose layer will become current: *Cancel*
*cancel*

Doesn't seem like anything too out of the ordinary

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Setvar variable not automatically setting layer active
« Reply #9 on: February 22, 2017, 03:42:17 PM »
Code: [Select]
Command:  LAYMCUR
Select object whose layer will become current:
*error*
Command:  LAYMCUR
Select object whose layer will become current: *Cancel*
*cancel*

Doesn't seem like anything too out of the ordinary
Except for the *error* .. ExpressFools finest  >:D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Cuddles

  • Guest
Re: Setvar variable not automatically setting layer active
« Reply #10 on: February 22, 2017, 04:01:41 PM »
This is what i get:

Code: [Select]
Command: LAYMCUR
Select object whose layer will become current: *error*
Command:
LAYMCUR
Select object whose layer will become current:
*error*

The second *error* is the right-click mouse exit, not escape to cancel  :grinwink:
« Last Edit: February 22, 2017, 05:00:34 PM by Bevan G »

ChrisCarlson

  • Guest
Re: Setvar variable not automatically setting layer active
« Reply #11 on: February 23, 2017, 02:56:54 PM »
Thought it was the other

Code: [Select]
Command: LAYMCUR
Select object whose layer will become current: *Cancel*
*cancel*