Author Topic: Changing Attribute Mode with LISP  (Read 8041 times)

0 Members and 1 Guest are viewing this topic.

psutter14

  • Guest
Changing Attribute Mode with LISP
« on: December 16, 2008, 03:04:27 PM »
Can anybody help with my problem?

I have 1000's of block that I need to change.

Iam using a lisp routine "reptext.lsp" to change the values within my blocks, however I had checked the Constant setting to Yes on most block and now I can not change the value of my Attributes. 

Can anybody write a lisp to change the attribute mode setting, it needs to change the constant setting to unconstant.

Thanks Paul

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Attribute Mode with LISP
« Reply #1 on: December 16, 2008, 03:10:07 PM »
Try this:

Code: [Select]
(defun c:toggleconstant (/ 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 (= (vla-get-constant att) :vlax-true)
  (vla-put-constant att :vlax-false)
)
      )
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Changing Attribute Mode with LISP
« Reply #2 on: December 16, 2008, 03:19:32 PM »
Don't think that will work Ron, see quote below.

Quote
;   Constant (RO) = 0

Wouldn't you have to change the attribute within the block definition?  I'm not sure, as I don't use constant attributes.

/guess.

Edit:  It does work, but you don't get the desired results.  I'll stick with the way I say above for now.   ;-)
Tim

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

Please think about donating if this post helped you.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Attribute Mode with LISP
« Reply #3 on: December 16, 2008, 03:22:14 PM »
Don't think that will work Ron, see quote below.

Quote
;   Constant (RO) = 0

Wouldn't you have to change the attribute within the block definition?  I'm not sure, as I don't use constant attributes.

/guess.

DOH! That's what I get for cutting and pasting from another post  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Changing Attribute Mode with LISP
« Reply #4 on: December 16, 2008, 03:30:02 PM »
If the attribute is still going to be the same for all blocks, then you can change the constant attribute's value within the block definition, and it will update all the rest.

If you want them to be different per insert, then you will have to change it from constant-true to constant-false within the block definition, plus re-insert all the blocks, and erase the old ones.

What are you looking to do exacly?  How much experience do you have with writing code?

And Welcome to theSwamp Paul!
Tim

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

Please think about donating if this post helped you.

M-dub

  • Guest
Re: Changing Attribute Mode with LISP
« Reply #5 on: December 16, 2008, 03:36:56 PM »
If you want them to be different per insert, then you will have to change it from constant-true to constant-false within the block definition, plus re-insert all the blocks, and erase the old ones.

Hmm.  There might be something of interest in this recent thread! :)

http://www.theswamp.org/index.php?topic=26399.0


And Welcome to theSwamp Paul!

x 2 :)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Attribute Mode with LISP
« Reply #6 on: December 16, 2008, 04:00:10 PM »
Ok...this one works: (makes all attributes in all blocks not constant...)

Code: [Select]
(defun c:attsnotconstant (/ b n)
  (vl-load-com)
  (while (setq b (tblnext "block" (not b)))
    (setq n (cdr (assoc 2 b)))
    (vlax-for o (vla-item (vla-get-blocks
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  )
  n
)
      (if (= (vla-get-objectname o) "AcDbAttributeDefinition")
(vla-put-constant o :vlax-false)
      )
    )
    (command "attsync" "name" n)
  )
)
(c:attsnotconstant)
« Last Edit: December 17, 2008, 10:02:18 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

psutter14

  • Guest
Re: Changing Attribute Mode with LISP
« Reply #7 on: December 16, 2008, 10:27:37 PM »
Thanks ronjonp for the fast response, but Iam have a problem.  When I open a file the routine start on its own, info from the command line are as follows:

error collecting attribute data
attsync complete
attsync; error; exception occurred : 0xC0000005 (Access Voilation)

Then a dialog box with:

fatal error: commands may not be nested more than 4 deep

I'll attached a file of some blocks for you to look at.

1000 thanks for trying

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Changing Attribute Mode with LISP
« Reply #8 on: December 16, 2008, 11:27:54 PM »

Paul,
Rons code works fine for me in AC2008 on the drawing you posted.

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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Changing Attribute Mode with LISP
« Reply #9 on: December 16, 2008, 11:56:04 PM »

Time for the obvious questions ..
What version of Autocad are you using ?
I notice that the file was
Saved in an Acad 2000 format,
Created : Saturday, 2 January 1982  10:00:00
and has a Total editing time of 274 hours

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

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Attribute Mode with LISP
« Reply #10 on: December 17, 2008, 10:03:58 AM »
Worked here as well.....

I added (vl-load-com) to the code above. Maybe that had something to do with it :?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

psutter14

  • Guest
Re: Changing Attribute Mode with LISP
« Reply #11 on: December 17, 2008, 10:46:01 AM »
Thanks ronjonp and all, this is the best site I have found yet.  It does work  :lol:  I was using 2002.  I have a demo version of 2007 and loaded it and it work great, except when I open the file it starts automatically. 

You said you add (vl-load-com) will that make it start when I need it.  If so where do I put it in the code.

And thanks again

thank you
thank you
thank you :lol: :lol: :lol: :-D :-D

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Attribute Mode with LISP
« Reply #12 on: December 17, 2008, 10:52:27 AM »
(vl-load-com) loads the need Visual Lisp commands for the routine to work. Do a search around here for adding a lisp to start up..there a numerous examples.


And..you're welcome :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

M-dub

  • Guest
Re: Changing Attribute Mode with LISP
« Reply #13 on: December 17, 2008, 10:54:43 AM »
Ron to the rescue again!  :-D

chauny274

  • Guest
Re: Changing Attribute Mode with LISP
« Reply #14 on: December 29, 2008, 11:13:58 AM »
Thanks ronjonp and all, this is the best site I have found yet.  It does work  :lol:  I was using 2002.  I have a demo version of 2007 and loaded it and it work great, except when I open the file it starts automatically. 

You said you add (vl-load-com) will that make it start when I need it.  If so where do I put it in the code.

And thanks again

thank you
thank you
thank you :lol: :lol: :lol: :-D :-D

(vl-load-com) doesn't have anything to do with when the lisp starts. If you erase the last line (c:attsnotconstant) then the program will be set up to run whenever you type in attsnotconstant in the command line. You can also shorten up that name to make it easier on yourself if you're going to do that...