Autolisp using an attribue name as a variable

Autolisp using an attribue name as a variable

Anonymous
Not applicable
427 Views
4 Replies
Message 1 of 5

Autolisp using an attribue name as a variable

Anonymous
Not applicable

I have a block with 25 and growing attributes and corresponding global variables.

 

 

(defun attdraw (atthandle / ) ; draw out all attributes of the insert, turn them into global variables and fill them with

(setq ent (handent atthandle) ; their corresponding data. attribute name = global variable name.

     ed (entget ent)

     );setq

(while

   (/= "SEQEND" (dxf 0 ed))     ;while tag value /= SEQEND

     (if (= "ATTRIB" (dxf 0 ed))       ;make sure its an attribute

       (set (read (dxf 2 ed)) (dxf 1 ed))

     );if

     (setq ent (entnext ent)     ;move to the next tag

   ed (entget ent)       ;and get entity data

   );setq

);while

);defun

 

 

 

i update the variables in a dialog box.

 

exiting the dialog box i update the global variables

 

 

i would like to then insert the values back into the attributes using something similar.

 

 

is there a way to use the attribute names as variable names and also use the values associated with them to push them back into the attributes.

0 Likes
428 Views
4 Replies
Replies (4)
Message 2 of 5

dgorsman
Consultant
Consultant

Possible.  But ignores a number of LISP basics as well as creates a number of problems - like cleaning up those "floating" variables.  Look into lists and dotted pairs, and looping through a list.

 

Also, head to the Customization board - *much* more LISP coverage down there, including multiple threads involving the above topics.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for your reply,


i have considered list's and dotted pairs. thinking of somehow finding all #pcad_??????? symbols in Atoms-family and using the symbol names or just find the insert again and i have all the names.

how do i take a symbol name from a dotted pair, a list or string and use it as a symbol to retrieve the data that was saved in the symbol with the same name earlier? (+ #pcad_length 4.0)


these variables are used over and over again during a session but setting them to nil wouldn't be a problem.


i have resorted to

 

<snippet of attdraw> draw data out of attributes.


(while
    (/= "SEQEND" (dxf 0 ed))     ;while tag value /=
      (if (= "ATTRIB" (dxf 0 ed))       ;make sure its an attribute
        (set (read (dxf 2 ed)) (dxf 1 ed))  ;This saves data in the attribute to the attribute name
      );if
     (princ (strcat (dxf 2 ed)  ">>>>> attdraw\n")) ;for testing
    (setq ent (entnext ent)      ;move to the next tag
   ed (entget ent)        ;and get entity data
    );setq
  );while


now i want to draw it out in a similar fashion. it would help if i am constantly updating the number of attributes in my insert. 44 right now


i have resorted to using this.  case line for every attribute

 

<snippet of attpush> push to data back to attributes.


  (while (/= (dxf 0 (setq ed (entget ent))) "SEQEND")
    (princ (strcat "\n" (dxf 2 ed) " Attpush"))
    (cond
      ((= (strcase (dxf 2 ed)) (strcase "#PCAD_ITEM_ATT_HANDLE"))
      (upd ed ent #pcad_item_att_handle)
      );
      ((= (strcase (dxf 2 ed)) (strcase "#PCAD_PRIM_ENT"))
      (upd ed ent #pcad_prim_ent)
      );
      ((= (strcase (dxf 2 ed)) (strcase "#PCAD_INTERIOR_ENT"))
      (upd ed ent #pcad_interior_ent)
      );

     -

     -

     -

(defun upd (ed ent nval / el)
  (setq el (subst (cons 1 nval) (assoc 1 ed) ed))
  (entmod el)
);defun

 

 

0 Likes
Message 4 of 5

dgorsman
Consultant
Consultant

List of dotted pairs *instead of* creating unique symbols for everything.  Consider:

 

(list
   '("ATTRIB_1" . "Some text")
   '("ATTRIB_2" . "Other text")
   '("ATTRIB_3" . "Even more text")
)

 

You can pull indexed information out of that list using (assoc ...).  The construction can implement whatever nested list structure suits you - handles, entity names, GUID values, strings, integers, whatever.  It's your list, you define how it operates.  Use various methods to manipulate, add, and remove contents.  If the list is global in scope, you can access it anytime in the document through whatever that list is assigned to.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 5 of 5

Anonymous
Not applicable
So, for all intensive purposes, use 1 list to represent all my vars in the insert, create it looping through the insert, then pulling data with assoc as my dxf routine does (dxf index list)=find the associated data of index in list. create tools to pull and change data as required.
I will consider this for my current project but am pretty deep into my it now. I will definatly use this concept in future projects.

Thank you
0 Likes