Author Topic: Looking for help with this code  (Read 2209 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
Looking for help with this code
« on: September 11, 2013, 07:45:35 PM »
Code: [Select]
(defun c:xlayer_on (/)
  (vlax-map-collection
    (vla-get-layers
      (vla-get-activedocument (vlax-get-acad-object))
    )
    '(lambda (x)
       (if (or (= (vla-get-color x 9)
       (= (vla-get-color x 8)
   )
(progn
   (vl-catch-all-error-p
     (vl-catch-all-apply 'vla-put-freeze (list x :vlax-false))
   )
   (vla-put-layeron x :vlax-true)
   (vla-put-lock x :vlax-false)
   (vla-put-plottable x :vlax-true)
)
       )
     )
  )
  (princ)
)

All I want it to do is grab the layers that are color 9 and 8 and make sure that they are completely viewable.

its not working and I am not sure why...

I think it has something to do with the

Code: [Select]
(vl-catch-all-apply 'vla-put-freeze (list x :vlax-false))
Thanks in advance for your help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Looking for help with this code
« Reply #1 on: September 11, 2013, 08:22:18 PM »
Maybe this will work for you.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:xlayer_on (/ active_layer lname)
  2.   (setq active_layer (vla-get-activelayer *doc*))
  3.   (vlax-for lname (vla-get-layers *doc*)
  4.     (if (and (vl-position (vla-get-color lname) '(8 9))
  5.              (not (equal active_layer item)))
  6.       (vl-catch-all-apply
  7.         '(lambda ()
  8.            (vla-put-freeze lname :vlax-false)
  9.            (vla-put-layeron lname :vlax-true)
  10.            (vla-put-lock lname :vlax-false)
  11.            (vla-put-plottable lname :vlax-true)
  12.          )
  13.       )
  14.     )
  15.   )
  16.   (vla-regen *doc* acactiveviewport)
  17.   (princ)
  18. )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Looking for help with this code
« Reply #2 on: September 12, 2013, 07:19:44 AM »
The issue with the code was in these expressions:

Code: [Select]
(if (or (= (vla-get-color x 9)
           (= (vla-get-color x 8))

The vla-get-* functions will only accept a single argument (the VLA-Object whose property is to be retrieved), and you are also missing some closing parentheses.

In addition to CAB's excellent suggestion, here is another variation:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:xlayer_on ( )
  2.         (if (< 7 (vla-get-color x) 10)
  3.             (progn
  4.                 (vl-catch-all-apply 'vla-put-freeze (list x :vlax-false))
  5.                 (vla-put-layeron   x :vlax-true)
  6.                 (vla-put-lock      x :vlax-false)
  7.                 (vla-put-plottable x :vlax-true)
  8.             )
  9.         )
  10.     )
  11.     (princ)
  12. )



David Bethel

  • Swamp Rat
  • Posts: 656
Re: Looking for help with this code
« Reply #3 on: September 12, 2013, 07:35:27 AM »
Or maybe:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:l89 (/ td ll)
  2.   (while (setq td (tblnext "LAYER" (not td)))
  3.          (if (member (abs (cdr (assoc 62 td))) '(8 9))
  4.              (setq ll (cons (cdr (assoc 2 td)) ll))))
  5.   (command "_.LAYER")
  6.   (foreach l ll
  7.     (command "_Unlock" l "_Thaw" l "_On" l))
  8.   (command "")
  9.   (prin1))
  10.  


Q:   In a vl call, does it strip the negative from the color number if the layer is off ?

-David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Looking for help with this code
« Reply #4 on: September 12, 2013, 08:31:10 AM »
Q:   In a vl call, does it strip the negative from the color number if the layer is off ?

The color property will always return an integer between 0-256 (0=acbyblock; 256=acbylayer).
The on/off status is determined by the layeron ActiveX property  :-)

AVCAD

  • Guest
Re: Looking for help with this code
« Reply #5 on: September 12, 2013, 09:24:22 AM »
Thanks, Works perfectly CAB! I can always count on you guy!

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Looking for help with this code
« Reply #6 on: September 12, 2013, 10:42:33 AM »
The color property will always return an integer between 0-256 (0=acbyblock; 256=acbylayer).
The on/off status is determined by the layeron ActiveX property  :-)


I think I'll stick with the TABLEs  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Looking for help with this code
« Reply #7 on: September 12, 2013, 11:56:57 AM »
I think I'll stick with the TABLEs  -David

In this case, I actually feel that the ActiveX route is more logical, i.e.:

Code: [Select]
(vla-get-color   <Layer-Object>) --> Layer Color
(vla-get-layeron <Layer-Object>) --> true = Layer is ON, false = Layer is OFF

In Vanilla, we have:
Code: [Select]
(cdr (assoc 62 <Layer-DXF-data>)) --> Absolute value = Layer Color; if negative Layer is OFF
I personally don't see the logic of a negative Layer color indicating that the Layer is OFF - these two properties are not related in any way. I would think it more logical to include the Layer ON/OFF property as an additional bit-code in DXF group 70 (along with frozen / locked).

Also, by combining the properties into a single DXF group, it necessitates the use of abs when retrieving the Layer color.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Looking for help with this code
« Reply #8 on: September 12, 2013, 12:17:54 PM »
I personally don't see the logic of a negative Layer color indicating that the Layer is OFF ...

Not to be combative, but it makes sense to me. Layers that are off do not display, but still hide -- objects are "there", they just don't appear, yet the space they occupy is recognized -- it's crazy -- it's like their color is negative or something. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Looking for help with this code
« Reply #9 on: September 12, 2013, 01:51:48 PM »
I personally don't see the logic of a negative Layer color indicating that the Layer is OFF ...

Not to be combative, but it makes sense to me. Layers that are off do not display, but still hide -- objects are "there", they just don't appear, yet the space they occupy is recognized -- it's crazy -- it's like their color is negative or something. :)

I guess that's one way of making sense of it - an interesting idea MP.
I still think the on/off status should be part of DXF Group 70; though, I'm not expecting it to change :lol: