TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Cuddles on February 20, 2017, 04:00:12 PM

Title: Setvar variable not automatically setting layer active
Post by: Cuddles 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
Title: Re: Setvar variable not automatically setting layer active
Post by: Marc'Antonio Alessi 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)
Title: Re: Setvar variable not automatically setting layer active
Post by: Cuddles 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.
Title: Re: Setvar variable not automatically setting layer active
Post by: 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 (https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/AutoCAD-Core/files/GUID-E44FA50E-DB98-48C4-AE6B-052ED7287497-htm.html).


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.
Title: Re: Setvar variable not automatically setting layer active
Post by: Marc'Antonio Alessi 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 (https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/AutoCAD-Core/files/GUID-E44FA50E-DB98-48C4-AE6B-052ED7287497-htm.html).
...
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)))
 ...
)
Title: Re: Setvar variable not automatically setting layer active
Post by: irneb 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.
Title: Re: Setvar variable not automatically setting layer active
Post by: ronjonp 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. )
Title: Re: Setvar variable not automatically setting layer active
Post by: Cuddles 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.
Title: Re: Setvar variable not automatically setting layer active
Post by: ChrisCarlson 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
Title: Re: Setvar variable not automatically setting layer active
Post by: ronjonp 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
Title: Re: Setvar variable not automatically setting layer active
Post by: Cuddles 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:
Title: Re: Setvar variable not automatically setting layer active
Post by: ChrisCarlson 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*