Author Topic: attmode toggle  (Read 3100 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
attmode toggle
« on: March 04, 2009, 05:44:52 PM »
Hi

Could you please have a quick look at this short lisp and tell me what's wrong?

Code: [Select]
(defun c:ATTMODETOG (attmodetog)

(setq attmodesetting (getvar "attmode"))
(cond ((= attmodesetting 1)) (setvar "attmode" 2))
(princ "\nAttributes On."))

((= attmodesetting 2) (setvar "attmode" 0))
(princ "\nAttributes Off."))

((= attmodesetting 0) (setvar "attmode" 1))
(princ "\nAttributes Normal."))
)

(command "regenall")

    (princ)
);defun

Thanks
Patrick

ronjonp

  • Needs a day job
  • Posts: 7531
Re: attmode toggle
« Reply #1 on: March 04, 2009, 06:12:48 PM »
You're parens don't match...take a look at this (did not test):

Code: [Select]
(defun c:attmodetog (/ attmodesetting);;
  (setq attmodesetting (getvar "attmode"))
  (cond ((= attmodesetting 1) (setvar "attmode" 2) (princ "\nAttributes On."))
        ((= attmodesetting 2) (setvar "attmode" 0) (princ "\nAttributes off."))
        ((= attmodesetting 0) (setvar "attmode" 1) (princ "\nAttributes Normal."))
  )
  (command "regenall")
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Pad

  • Bull Frog
  • Posts: 342
Re: attmode toggle
« Reply #2 on: March 04, 2009, 06:19:15 PM »
ah i see, my parenthesis were all over he place. Thank you, that's fixed it.

I have been playing with invisible attributes today.
Is it not possible for invisible attributes to be gripped, when they are made visible using attmode or attdisp?

I'd like to be able to move 'visible invisible attributes' whilst drafting so I can read them in cluttered areas.

Thanks
« Last Edit: March 04, 2009, 06:23:07 PM by Pad »

Pad

  • Bull Frog
  • Posts: 342
Re: attmode toggle
« Reply #3 on: March 06, 2009, 06:49:54 AM »
Hello

I am having a terrible time with toggling invisible/visible attributes.
The attributes sometimes come out of sync with each other and I often loose the ability to use the grips (acad2004).

Anyway CAB (I think) kindly wrote this lisp which seems quite bullet proof:

Quote
(defun c:testOFF (/ ss idx ename att)
  (and
    (setq ss (ssget '((0 . "INSERT") (66 . 1))))
    (setq idx -1)
    (while (setq ename (ssname ss (setq idx (1+ idx))))
      (foreach att (vlax-invoke (vlax-ename->vla-object ename) 'getattributes)
        (if (member (vla-get-tagstring att) '("NO" "CODE"))
          (vla-put-Invisible att :vlax-true)
        )
      )
    )
  )
  (princ)
)

And I have modified it to now turn the attributes visible again (vla-put-Invisible att :vlax-false)

How can i modify this, so that instead of asking me to select objects it automatically selects all objects within model space?
I'd also like to modify it so that it toggles between the two, what variable can i use to enable this?  The attmode variable in this case doesn't change.

Thanks
Patrick

ronjonp

  • Needs a day job
  • Posts: 7531
Re: attmode toggle
« Reply #4 on: March 06, 2009, 10:33:31 AM »
Give this a try..to select all objects without user input you need to use "_x" in the ssget.  To toggle...all you have to is check the visibility of the att then do the opposite.


Code: [Select]
(defun c:testoff (/ ss idx ename att)
  (and (setq ss (ssget "_x" '((0 . "INSERT") (410 . "Model") (66 . 1))))
       (setq idx -1)
       (while (setq ename (ssname ss (setq idx (1+ idx))))
         (foreach att (vlax-invoke (vlax-ename->vla-object ename) 'getattributes)
           (if (member (vla-get-tagstring att) '("NO" "CODE"))
             (if (= (vla-get-invisible att) :vlax-true)
               (vla-put-invisible att :vlax-false)
               (vla-put-invisible att :vlax-true)
             )
           )
         )
       )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Pad

  • Bull Frog
  • Posts: 342
Re: attmode toggle
« Reply #5 on: March 06, 2009, 10:49:45 AM »
That is absolutely perfect, exactly what I was after.
Thank you so much.

_x is very handy to know

Regarding invisibility I had no idea what to do, as according to BATTMAN the invisible attribs aren't invisible.

Great stuff
Cheers!

JohnK

  • Administrator
  • Seagull
  • Posts: 10658
Re: attmode toggle
« Reply #6 on: March 06, 2009, 11:00:27 AM »
<snip>
Regarding invisibility I had no idea what to do, as according to BATTMAN the invisible attribs aren't invisible.
<snip>

That's because that invisible is not the same as the invisible in an attribute.
DXF group code 70 is what your thinking of.

70
 Attribute flags:
1 = Attribute is invisible (does not appear)
2 = This is a constant attribute
4 = Verification is required on input of this attribute
8 = Attribute is preset (no prompt during insertion)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Pad

  • Bull Frog
  • Posts: 342
Re: attmode toggle
« Reply #7 on: March 06, 2009, 11:22:05 AM »
Thanks Se7en, I thought it would be something along those lines.

This invisible seems to be a much better method than the DXF 70 code.
I'll have to look into these codes some time, but so far I only have slim grasp of lisp.

This method doesn't suffer from the same loss of grips as the attmode method, so everything is good.

Cheers
P

JohnK

  • Administrator
  • Seagull
  • Posts: 10658
Re: attmode toggle
« Reply #8 on: March 06, 2009, 11:41:25 AM »
No problem.

"vla-put-invisible" is easier code wise (well, shorter sorta) but slower (but you wouldnt be able to tell the difference).

If you want to learn, you found the right place.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org