Author Topic: Change Value Attributes  (Read 2413 times)

0 Members and 1 Guest are viewing this topic.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Change Value Attributes
« on: February 24, 2017, 04:40:34 PM »
Hi, how are you

Is there any subfunction that allows you to select blocks with attributes and change them automatically

Thank you
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Change Value Attributes
« Reply #1 on: February 24, 2017, 04:53:02 PM »
There are hundreds of examples here.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Change Value Attributes
« Reply #2 on: February 24, 2017, 05:03:45 PM »
H Ronjonp i, how are you

This subfunction I found in this link would probably work with ssget
https://www.theswamp.org/index.php?topic=49300.msg543974#msg543974

Code - Auto/Visual Lisp: [Select]
  1. (defun _putattvalue (block tag value / att flag)
  2.     (foreach att (vlax-invoke block 'getattributes)
  3.       (if (eq (strcase tag) (strcase (vla-get-tagstring att)))
  4.                  att
  5.                  (if (= (type value) 'str)
  6.                    value
  7.                    (vl-princ-to-string value)
  8.                  )
  9.                )
  10.                (setq flag value)
  11.         )
  12.       )
  13.     )
  14.     flag
  15.   )
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Change Value Attributes
« Reply #3 on: February 24, 2017, 05:15:44 PM »
Here are numerous ways:
http://www.lee-mac.com/attributefunctions.html
When you're stuck at learning LISP always check Lee Mac's stuff (IMO hes the best learning material). :D
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change Value Attributes
« Reply #4 on: February 24, 2017, 05:38:19 PM »
Do you want to select the attributes themselves?  If so, take the code from here.
Tim

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

Please think about donating if this post helped you.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Change Value Attributes
« Reply #5 on: February 24, 2017, 05:51:27 PM »
NO, the block has two attributes the first tag1 and the other tag2, the tag1 I want to add 33 and the tag2 subtract 4, I do not want to apply entsel because I would have to select one by one that is why I asked if ssget could extract the content Of the attributes.
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change Value Attributes
« Reply #6 on: February 24, 2017, 05:57:29 PM »
Ssget, No.  ssget will select "space" entities, not nested entities.  Use ssget to select the blocks, then step through the attributes ob the selected blocks (testing the tag) and make the changes there.

The code I linked to will allow you to select the attribute entities like ssget.

So you have two options on how to get to the attributes within a block now.  Choose which way works for you.  Post code once you get stuck.
Tim

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

Please think about donating if this post helped you.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Change Value Attributes
« Reply #7 on: February 28, 2017, 09:07:01 PM »
Hi, how are you, here I have my code almost finished, since I have a problem I do not know because it sends the message

Select objects:; Error: bad argument type: fixnump: "2"

Eh analyzed every section of the code but I do not find the problem, I would appreciate the help
« Last Edit: March 22, 2017, 01:42:00 PM by amc.dicsac »
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Change Value Attributes
« Reply #8 on: March 01, 2017, 08:16:15 AM »
This:
Code: [Select]
(setq off1 (itoa TotaLam)))
Should be:
Code: [Select]
(setq off1 (atoi TotaLam)))
Similarly:
Code: [Select]
(setq off2 (itoa ContLam)))
Should be:
Code: [Select]
(setq off2 (atoi ContLam)))

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Change Value Attributes
« Reply #9 on: March 01, 2017, 10:42:06 AM »
Thanks Lee, but now every time I enter enter to keep the same value I get this message

Ingresa ToTal lamina <43>:
; Error: bad argument type: stringp 43
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Change Value Attributes
« Reply #10 on: March 01, 2017, 01:30:45 PM »
Sorry, I now see that you are already converting the default values to integers earlier in the code - in this case, change the lines to:
Code: [Select]
(setq off1 TotaLam))
Code: [Select]
(setq off2 ContLam))

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Change Value Attributes
« Reply #11 on: March 01, 2017, 04:34:47 PM »
When making that change, I no longer keep the last values entered, now the lisp has worsened
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Change Value Attributes
« Reply #12 on: March 01, 2017, 04:56:00 PM »
Somewhere you are passing a string variable where you want a number variable.  I think it has something to do with 'off3', as you can see from the code below you are assigning 'off2' to two different types of variables.
Code: [Select]
  (if (setq off2 (getint (strcat "\nIngresa inicio <" (itoa ContLam) ">: ")))
        (setenv "SaveNumberSheet\\ContLam" (itoa off2))
        (setq off2 (itoa ContLam)))

The first line is asking for an integer, but the last line is converting an Integer TO Alpha.

To help find the location of the error, define an error function with a call to '(vl-bt)'.
Code: [Select]
(defun *error* (msg) (vl-bt))
Tim

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

Please think about donating if this post helped you.

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Change Value Attributes
« Reply #13 on: March 01, 2017, 05:28:35 PM »
When I start lisp I have this code

Code - Auto/Visual Lisp: [Select]
  1.   (if (or (not (setq ContLam (getenv "SaveNumberSheet\\ContLam"))) ;;Returns "1"
  2.            (not (setq ContLam off3))) ;;Returns "nil"
  3.          (setenv "SaveNumberSheet\\ContLam" (setq ContLam "1"));;Returns "1"
  4.     )

I would like to call the code again to save the result of the sum

 
Code - Auto/Visual Lisp: [Select]
  1.  (Setq off3 (+ off3 1))

But every time I call it it recognizes at first off3 as an empty value ie nill

My problem would be to assign a value to off3 to convert it to a string then convert it to a number, execute the sum and the last value to convert it back into a string so that it is stored in off3


« Last Edit: March 01, 2017, 05:33:14 PM by amc.dicsac »
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>

amc.dicsac

  • Newt
  • Posts: 109
  • Autocad 2008
Re: Change Value Attributes
« Reply #14 on: March 01, 2017, 07:10:15 PM »
I was able to solve the problem, thank you very much for the help you have been giving me  :yay!:
<a href="http:/http://axprogramlisp.blogspot.pe" class="bbc_link" target="_blank">By Alexander Castro</a>