Jump to content

using attribute names as variables


ChrisAllison

Recommended Posts

I have a block with 25 and growing attributes and correspondingglobal variables.

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

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

ed (entget ent)

);setq

(while

(/="SEQEND" (dxf 0 ed)) ;whiletag 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 (entgetent) ;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 theattributes using something similar.

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

Link to comment
Share on other sites

You can work without attribute tag names by using the attribute creation order and then you can modify the attribute value its what is happening here (setq ent(entnext ent) ;move to the next tag, you indicate you have a dialog box so you can use order rather than tagname. As an example in VBA Attrib(3).value returns the value of the 3rd atribute.

 

have a look at this

 

; Change attribute value by created position
; Eaxmple to walk trhough a block
(vl-load-com)
(defun blkorder ( / ss1 blobj Y)
(setq y 1)
(setq ss1 (car (entsel "pick block")))
(setq blobj (vlax-ename->vla-object SS1)) 

(foreach att (vlax-invoke blobj 'getattributes)
(princ (strcat "\n attrib No " (rtos y 2 0) " " (vla-get-textstring att )))
;(vla-put-textstring att newstrblank) ;use this to change attribute value
(setq y (+ Y 1))
)
)
(blkorder)
(princ)

Link to comment
Share on other sites

How does your program find the global variables in theenvironment and associate them with the attribute name. ( i use DCL dialog boxes ifthat makes any difference).

my knowledge of vl is limited to none. old school lisper

Link to comment
Share on other sites

You have var1 = attribute value 1, say make 25 and set var1 to var25 = nil then open up block and reset the var value, only need to know how many, another way is to just create a list of the attributes, (setq lst (list 12 34 56 67 89)) var1 = (nth 0 lst) = 12 using (length lst) you always know how many variables you have. Again I do not worry about attribute TAG name but I do know order of attributes within the block. Did you try code above as an example. In VL you use a GET to do just that "get some info" and a PUT to change a value.

 

Update in dialouge and then use

 

; the newstr is returned from the DCL and you know which row
(foreach att (vlax-invoke blobj 'getattributes)
(If  (= row y)
(vla-put-textstring att newstr) 
)
(setq y (+ Y 1))
)
)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...