TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: psutter14 on December 16, 2008, 03:04:27 PM

Title: Changing Attribute Mode with LISP
Post by: psutter14 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
Title: Re: Changing Attribute Mode with LISP
Post by: ronjonp 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)
)
Title: Re: Changing Attribute Mode with LISP
Post by: T.Willey 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.   ;-)
Title: Re: Changing Attribute Mode with LISP
Post by: ronjonp 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
Title: Re: Changing Attribute Mode with LISP
Post by: T.Willey 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!
Title: Re: Changing Attribute Mode with LISP
Post by: M-dub 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 :)
Title: Re: Changing Attribute Mode with LISP
Post by: ronjonp 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)
Title: Re: Changing Attribute Mode with LISP
Post by: psutter14 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
Title: Re: Changing Attribute Mode with LISP
Post by: Kerry on December 16, 2008, 11:27:54 PM

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

Title: Re: Changing Attribute Mode with LISP
Post by: Kerry 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

??
Title: Re: Changing Attribute Mode with LISP
Post by: ronjonp 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 :?
Title: Re: Changing Attribute Mode with LISP
Post by: psutter14 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
Title: Re: Changing Attribute Mode with LISP
Post by: ronjonp 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 :)
Title: Re: Changing Attribute Mode with LISP
Post by: M-dub on December 17, 2008, 10:54:43 AM
Ron to the rescue again!  :-D
Title: Re: Changing Attribute Mode with LISP
Post by: chauny274 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...
Title: Re: Changing Attribute Mode with LISP
Post by: Beekee on November 26, 2014, 12:22:51 PM
Hello, I found this old thread with code almost good for me. Could anyone be so kind and add some line to change just 1 attribute specified by its tag? Thx