Author Topic: tblsearch xref'd layer  (Read 4383 times)

0 Members and 1 Guest are viewing this topic.

Oak3s

  • Guest
tblsearch xref'd layer
« on: February 09, 2007, 07:16:57 PM »
Here is part of a little toggle button i was able to put together.
Code: [Select]
(setq TEST(cdr(assoc 70(tblsearch "layer" "XREF")))) ;get layer state (frozen, thawed, etc.)
(if (= TEST 5) (command "-layer" "thaw" "XREF" "")
(if (= TEST 1) (command "-layer" "thaw" "XREF" "lock" "XREF" "")
(command "-layer" "freeze" "XREF" "lock" "XREF" "")
    )
)
Now i would like to do the same with a layer that is xref'd but wildcards dont work. My idea was something like this. But as already stated...no good.
Code: [Select]
(setq TEST(cdr(assoc 70(tblsearch "layer" "*thislayer")))) ;get layer state (frozen, thawed, etc.)
(if (= TEST 5) (command "-layer" "thaw" "*thislayer" "")
(if (= TEST 1) (command "-layer" "thaw" "*thislayer" "lock" "*thislayer" "")
(command "-layer" "freeze" "*thislayer" "lock" "*thislayer" "")
    )
)
The best i can figure my problem is the wildcard. Any ideas of how accomplish the task of freezing/thawing a layer that is from an xref...based on its current state.

(I am aware that the above toggle that works could be added to)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: tblsearch xref'd layer
« Reply #1 on: February 09, 2007, 07:23:31 PM »
How are you getting the layer?  If you want to test for a certain pattern within layers, then I think you will have to step through the layer collection, and test each one.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: tblsearch xref'd layer
« Reply #2 on: February 09, 2007, 09:26:56 PM »
Perhaps start with something like this, which is self documenting  ..

Code: [Select]
    (VLAX-FOR lay
              (VLA-GET-LAYERS (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))
        (IF (WCMATCH (VLA-GET-NAME lay) "*BLOCKS")
            (PROGN
;;;                (vla-put-LayerOn lay :VLAX-FALSE )
;;;                (vla-put-Freeze lay :VLAX-TRUE )
;;;                (vla-put-LOck lay :VLAX-TRUE )
               
                   (VLA-PUT-LAYERON lay :VLAX-TRUE)
                   (VLA-PUT-FREEZE lay :VLAX-FALSE)
                   (VLA-PUT-LOCK lay :VLAX-FALSE)
                   (prompt (strcat "\n Modified layer : " (VLA-GET-NAME lay)))
            )
        )
    )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

VVA

  • Newt
  • Posts: 166
Re: tblsearch xref'd layer
« Reply #3 on: February 12, 2007, 03:31:35 AM »
One more variant
Changes a condition (frozen, locked) of layers (like "1BLOCK" "2BLOCK" ect)  on opposite
Code: [Select]
;;;================================================================================
;;;Written By Michael Puckett.
;;;(setq all_layers (tablelist "LAYER"))
(defun tablelist (s / d r)
  (while (setq d (tblnext s (null d)))
    (setq r (cons (cdr (assoc 2 d)) r))
  )
)

(vl-load-com)
(setq patt "*BLOCK"
 all_layers (vl-remove-if-not '(lambda(x)(wcmatch (strcase x)(strcase patt)))(tablelist "LAYER"))
)
(mapcar '(lambda(lay / stat ed)
             (setq stat (cdr(assoc 70(setq ed(entget (tblobjname "layer" lay))))))
             (if (/= (strcase(getvar "CLAYER"))(strcase lay))
                 (setq stat (boole 6 stat 1)) ;_Froz or Thaw
                 )
             (setq stat (boole 6 stat 4)) ;_Lock or Unlock
             (setq ed (subst (cons 70 stat)
                             (assoc 70 ed) ed))
            (cdr(assoc -1(entmod ed)))
            
        )
        all_layers
        )
« Last Edit: February 12, 2007, 03:33:37 AM by VVA »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: tblsearch xref'd layer
« Reply #4 on: February 12, 2007, 08:35:38 AM »
I like Kerry's version but I don't understand Oak3s logic for freezing etc
In case you are not familiar with visual lisp here is that logic in Kerry's code.
Code: [Select]
;;  If frozen and locked then thaw
;;  Else
;;    If locked then thaw and lock
;;    Else
;;      freeze and lock
;;  "On/Off" status not considered ??
(vlax-for lay (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  (if (wcmatch (strcase (vla-get-name lay)) "*BLOCKS") ; ***  Case Sensitive ***
    (progn
      (if (and (eq (vla-get-freeze lay) :vlax-true)
               (eq (vla-get-lock lay) :vlax-true)
          )
        (vla-put-freeze lay :vlax-false)
        (if (eq (vla-get-lock lay) :vlax-true)
          (progn
            (vla-put-freeze lay :vlax-false)
            (vla-put-lock lay :vlax-true)
          )
          (progn
            (vla-put-freeze lay :vlax-true)
            (vla-put-lock lay :vlax-true)
          )
        )
      )
      (prompt (strcat "\n Modified layer : " (vla-get-name lay)))
    )
  )
)
<edit: fix typo>
« Last Edit: February 12, 2007, 08:39:44 AM by CAB »
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.

Oak3s

  • Guest
Re: tblsearch xref'd layer
« Reply #5 on: February 14, 2007, 02:03:19 PM »
I havent had much time to try the above suggestions. Thank you for them. I will post my results or questions as time permits.

CAB, my logic maybe skewed ;) Please let me know what doesnt seem logical. My idea was to search and see what the state of a layer is. If its this then do this else test to see if its this...then do this. I know it doest test for on/off or just locked and such. I have some more work on my part. But if im going about this wrong let me know. Im learning as i go.

Thanks again for the suggestions.

VVA

  • Newt
  • Posts: 166
Re: tblsearch xref'd layer
« Reply #6 on: February 15, 2007, 01:53:28 AM »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: tblsearch xref'd layer
« Reply #7 on: February 15, 2007, 02:20:07 AM »
........... My idea was to search and see what the state of a layer is. If its this then do this else test to see if its this...then do this................

Don't bother testing .. If you know the condition you want just set the layer to that state.

 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: tblsearch xref'd layer
« Reply #8 on: February 15, 2007, 09:38:17 AM »
Oak3s
I did not mean to imply that your logic was wrong, just that I did not understand it.
After all if it fits your purpose it is right for you.

Here is what you have:
;;  If frozen and locked
;;     then thaw
;;  Else
;;    If locked
;;       then thaw and lock
;;    Else
;;      freeze and lock
;;  "On/Off" status not considered ??

If i were to take a stab at it this is what I would do.
Note that the logic may be wrong for you. :)

;;  Case
;;    Layer frozen 
;;       then Save current settings, thaw and lock and ON
;;    Layer locked
;;       then Save current settings,  freeze
;;    Layer Off
;;       then Save current settings, set ON
;;  End Case


Settings would be saved in a global variable

;; Restore Layer Settings Lisp
;;
;;  If global var
;;    Loop var & restore settings
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.

Oak3s

  • Guest
Re: tblsearch xref'd layer
« Reply #9 on: February 15, 2007, 05:40:24 PM »
Oak3s
I did not mean to imply that your logic was wrong, just that I did not understand it. my comment was mad as a student, not a defendant. i did not read as if you were implying i was wrong. i appreciate your clarification though.
After all if it fits your purpose it is right for you.

Here is what you have:
;;  If frozen and locked
;;     then thaw
;;  Else
;;    If locked i believe this should be frozen
;;       then thaw and lock
;;    Else
;;      freeze and lock
;;  "On/Off" status not considered ?? i addressed this in the first post, there is much that could be added ;)

my goals for the routine were, always lock the layer and then freeze or thaw accordingly. i know that if a layer is frozen it is in a sense locked.

the idea of testing is based on this routine being used in the form of a button, or toggle. i believe that requires a test. am i wrong Kerry (that is not a sarcastic remark...i hope its not read as such).

so to clarify my 'logic' ;)
if the layer is frozen (limited testing that it can only be frozen and locked or frozen), thaw it. if its not...then freeze and lock it.
my abilities limit me from saying something like:
if less than
 do
else test for greater than
 do.

anyway, i just wanted to check here real quick. it ended up taking much more time than expected. ;) thanks for the input, all of you.