TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: amc.dicsac on February 24, 2017, 04:40:34 PM

Title: Change Value Attributes
Post by: amc.dicsac 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
Title: Re: Change Value Attributes
Post by: ronjonp on February 24, 2017, 04:53:02 PM
There are hundreds of examples (https://www.google.com/search?q=getattribute+site%3Atheswampt.org&oq=getattribute+site%3Atheswampt.org&aqs=chrome..69i57.18151j0j7&sourceid=chrome&ie=UTF-8#q=getattribute+site:theswamp.org&*) here.
Title: Re: Change Value Attributes
Post by: amc.dicsac 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 (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.   )
Title: Re: Change Value Attributes
Post by: Grrr1337 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
Title: Re: Change Value Attributes
Post by: T.Willey on February 24, 2017, 05:38:19 PM
Do you want to select the attributes themselves?  If so, take the code from here. (https://www.theswamp.org/index.php?topic=19886.msg488544#msg488544)
Title: Re: Change Value Attributes
Post by: amc.dicsac 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.
Title: Re: Change Value Attributes
Post by: T.Willey 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.
Title: Re: Change Value Attributes
Post by: amc.dicsac 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
Title: Re: Change Value Attributes
Post by: Lee Mac 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)))
Title: Re: Change Value Attributes
Post by: amc.dicsac 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
Title: Re: Change Value Attributes
Post by: Lee Mac 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))
Title: Re: Change Value Attributes
Post by: amc.dicsac 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
Title: Re: Change Value Attributes
Post by: T.Willey 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))
Title: Re: Change Value Attributes
Post by: amc.dicsac 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


Title: Re: Change Value Attributes
Post by: amc.dicsac 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!:
Title: Re: Change Value Attributes
Post by: T.Willey on March 02, 2017, 03:04:22 AM
That is good to hear.  You're welcome.

Maybe you can post the working code, so others can see how you solved the issue.