Code Red > AutoLISP (Vanilla / Visual)

Attribute values nil

(1/2) > >>

Shade:
Why are all my attribute values returning nil in the following code?


--- Code: ---(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
);
--- End code ---

Any help is appreciated... :mrgreen:

nivuahc:
There's some really great information for attribute handling in the following thread:

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

Jeff_M:
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:
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™:
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: ---(get_attribute (car (entsel)) "NAME")

--- End code ---

The return is:


--- Quote ---NAMEwidget1
nil

--- End quote ---

I change the attribute name selecting the same block:


--- Code: ---(get_attribute (car (entsel)) "nothing")

--- End code ---


--- Quote ---NAME1111
SIZE1111
nil

--- End quote ---

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.

Navigation

[0] Message Index

[#] Next page

Go to full version