Jump to content

Set Attribute Value by Angle (list of values, list of angles)


Recommended Posts

Posted

Hi,

 

I would like to set attribute value according to the angle parameter of dynamic block (there is a list of angles and value for each angle)

 

Inside my block there are:

- two parameters Angle1 and Angle2 which are defined by list of angles (190.6 , 220.5 , 250.4 , 300.1)

- two attributes ST and EN which needs to be defined by values list (16:00 , 12:20, 10:44 , 8:00)

 

As I move the grip by mouse I would like to set the value of ST or EN according to the list of values above. Behaviour would be similar as if I would use Block Propereties Table but in this case both values ST and EN needs to be separated from each other. Dynamic block does not allow me to create two Block Properties Tables. List of Angles and list of values will be much larger in the future so I will change them for every new project (I plan to do it manually from Excel)

 

Is it possible to get some help with simple LISP definition to set attribute value by angle according to the list of values? DWG attached. Thanks a lot for any feedback.

 

obraz.thumb.png.d723a5f0f81255aef6e7194ea9d11e67.png

LS2.dwg

Posted (edited)
(vl-load-com)
(setvar "CMDECHO" 0)
(vlr-command-reactor nil '((:vlr-commandEnded . EditLS)))
(princ "\nReactor edit LS block...")(princ)

(defun EditLS (reactor commandlist / newsset attr bloc)
 (cond
  ((equal (car commandlist) "GRIP_STRETCH")
   (setq newsset (ssget "_I" (list (cons 0 "INSERT")(cons 2 "`*U*"))))
  )
 )

 (if newsset
  (progn
   (setq bloc (car (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex newsset))))))
   
   (if (equal (strcase (vla-get-EffectiveName bloc)) "LS")
    (progn
     (setq attr	(safearray-value (variant-value (vla-GetAttributes bloc))))
     (mapcar '(lambda (elem)
	       (if (= "ANGLE1" (strcase (vla-get-propertyname elem)))
		(cond
		 ((equal (variant-value (vla-Get-Value elem)) 5.23773 0.0001) (vla-put-Textstring (car attr) "8:00"))
		 ((equal (variant-value (vla-Get-Value elem)) 4.3703 0.0001) (vla-put-Textstring (car attr) "10:40"))
		 ((equal (variant-value (vla-Get-Value elem)) 3.84845 0.0001) (vla-put-Textstring (car attr) "12:20"))
		 ((equal (variant-value (vla-Get-Value elem)) 3.3266 0.0001) (vla-put-Textstring (car attr) "16:00"))
		)
	       )
	       (if (= "ANGLE2" (strcase (vla-get-propertyname elem)))
		(cond
		 ((equal (variant-value (vla-Get-Value elem)) 5.23773 0.0001) (vla-put-Textstring (cadr attr) "8:00"))
		 ((equal (variant-value (vla-Get-Value elem)) 4.3703 0.0001) (vla-put-Textstring (cadr attr) "10:40"))
		 ((equal (variant-value (vla-Get-Value elem)) 3.84845 0.0001) (vla-put-Textstring (cadr attr) "12:20"))
		 ((equal (variant-value (vla-Get-Value elem)) 3.3266 0.0001) (vla-put-Textstring (cadr attr) "16:00"))
		)
	       )
	      )
	     (safearray-value (variant-value (vla-GetDynamicBlockProperties bloc)))
     )
    )
   )

  )
 ) 

 (princ)
)

 

This is solved with a reactor, loaded at the beginning of the AutoCAD session. At each change of angle, the corresponding attribute is updated.

Edited by confutatis
Posted (edited)

I apologize, I realized I made some mistakes, when I operated with other entities, it gave me an error message. Now it should go, the previous post has been corrected.

Edited by confutatis
Posted (edited)

You can edit your code in a previous post so its better to correct mistakes and just add a new post pointint out code updated in previous post it can get confusing which version to run.

 

eg correct typo pointint to pointing

Edited by BIGAL
Posted
4 hours ago, BIGAL said:

You can edit your code in a previous post so its better to correct mistakes and just add a new post pointint out code updated in previous post it can get confusing which version to run.

 

eg correct typo pointint to pointing

 

You're right, but unfortunately I have too limited time for editing, if I notice some mistake.

Posted

Hello @confutatis,

 

thank You for the quick responce and briliant script. I've managed to set all my values list in radians with the proper desription (in Excel)

Unfortunatelly, I don't know how the script inserts ANGLE1 value into ST attribute and ANGLE2 value into EN attribute. It seems that it works randomly.

 

Is there a way to set that values from ANGLE1 goes always to ST attribute and ANGLE2 to EN attribute?

 

Again many thanks for the code!

Posted

Confutatis

 

"You're right, but unfortunately I have too limited time for editing"

 

Some of us may remember that we dont have time to answer a request.

Posted (edited)

Bigal,

 

you are absolutely right, I apologise, it seemed to me that the post could only be edited for a few minutes, as is the case in other forums. In fact, I realised why edit was disappearing: I still had to save the post! 😊

Edited by confutatis
Posted
On 7/8/2021 at 8:54 PM, Marcin O said:

Is there a way to set that values from ANGLE1 goes always to ST attribute and ANGLE2 to EN attribute?

 

Hello @confutatis I would like to again thank You for quick responce and code. After a while I understood my misteake. I didn't notice that there are two different functions used for attribute assignment - CAR and CADR. Now I see what's the diferrence :)

Posted (edited)

Car, cadr and caddr, the first, second and third elements of a list, are normally used to extract x,y and z co-ordinates. To extract the elements from the fourth upwards, combinations of car and cdr (caar, cdar, cddr, caaar, caadr, cadar, caddr, cdaar, etc.) are used or, more simply, the nth function.

 

Syntax:
(nth n lst)

 

Arguments:
n - the number of the element to return from the list (zero is the first element).
lst - the list

 

Return Values:
The nth element of lst. If n is greater than the highest element number of lst, nth returns nil.

 

I could also write:
(nth 0 attr) and (nth 1 attr)

Edited by confutatis
Posted

Excuse me, who have lisp export block attribute include: coord X,Y, Tag and Value to CSV or TXT or XLS?

Posted

Admin please move last post by tauntrindp to a new post. Has PM me. Plenty of solutions out there.

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...