Author Topic: Attribute values nil  (Read 2003 times)

0 Members and 1 Guest are viewing this topic.

Shade

  • Guest
Attribute values nil
« on: April 22, 2008, 02:14:10 PM »
Why are all my attribute values returning nil in the following code?

Code: [Select]
(Defun Get_Attribute (ENM ATT /); OBJ &ATT CNT ITM CHK VAL)
  (setq OBJ (VLAX-ENAME->VLA-OBJECT ENM)
      &ATT (vlax-invoke OBJ 'GetAttributes)
      LEN (length &ATT)
CNT 0
  );
  (while (/= CNT LEN)     
     (setq ITM (nth CNT &ATT)   
     CHK (vlax-get-property ITM "TagString")
   CNT (+ CNT 1)
     )
     (princ CHK)     
     (if (= CHK ATT)
         (setq CNT LEN
       VAL (vla-get-textstring ITM)        
     )   );setq, if
     (princ VAL)
     (prompt "\n")
  );while
);

Any help is appreciated... :mrgreen:

nivuahc

  • Guest
Re: Attribute values nil
« Reply #1 on: April 22, 2008, 02:26:12 PM »
There's some really great information for attribute handling in the following thread:

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

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Attribute values nil
« Reply #2 on: April 22, 2008, 03:11:24 PM »
Shade,
Your routine works for me. It does return a final nil, but that is normal for any lisp that doesn't have an explicit return value. Are you making sure to pass the TagString argument in all CAPS? (The TAG is always capitalized)

Shade

  • Guest
Re: Attribute values nil
« Reply #3 on: April 22, 2008, 03:52:04 PM »
When I run the program I get output to the screen which shows the attributes names and a value of nil beside them.
That is what I am stumped about.
All I am looking to do is retrieve a certain attributes value from a certain block (entity).

the code listed above is got princ to screen for debugging the problem.

Further help is needed? Thanks id advance

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Attribute values nil
« Reply #4 on: April 22, 2008, 04:13:21 PM »
I used the code exactly as shown above, remember you must pass the name of the tag in all caps, otherwise it isn't equal. Incidently, I didn't return nil on any of my attempts, even when passing a value that is obviously incorrect. I did receive the correct values though ...

I have a block with 2 attributes, NAME and SIZE and I call the routine as such:
Code: [Select]
(get_attribute (car (entsel)) "NAME")

The return is:

Quote
NAMEwidget1
nil

I change the attribute name selecting the same block:

Code: [Select]
(get_attribute (car (entsel)) "nothing")

Quote
NAME1111
SIZE1111
nil

The problem is that you are obviously passing lowercase attribute names and your variables are global .. change the vars to local and pass uppercase attribute names.

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Shade

  • Guest
Re: Attribute values nil
« Reply #5 on: April 22, 2008, 04:23:02 PM »
I noticed that the lisp with attribute values that are not Fields works, but any attribute value that is a field returns nil.
I think that is my problem. How does one retrieve the attributes value for a field?

Thanks for all the help so far...