Marcin O Posted July 6, 2021 Posted July 6, 2021 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. LS2.dwg Quote
confutatis Posted July 7, 2021 Posted July 7, 2021 (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 July 13, 2021 by confutatis Quote
confutatis Posted July 7, 2021 Posted July 7, 2021 (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 July 13, 2021 by confutatis Quote
BIGAL Posted July 7, 2021 Posted July 7, 2021 (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 July 7, 2021 by BIGAL Quote
confutatis Posted July 8, 2021 Posted July 8, 2021 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. Quote
Marcin O Posted July 8, 2021 Author Posted July 8, 2021 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! Quote
BIGAL Posted July 13, 2021 Posted July 13, 2021 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. Quote
confutatis Posted July 13, 2021 Posted July 13, 2021 (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 July 13, 2021 by confutatis Quote
Marcin O Posted July 13, 2021 Author Posted July 13, 2021 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 Quote
confutatis Posted July 13, 2021 Posted July 13, 2021 (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 July 13, 2021 by confutatis Quote
tuantrinhdp Posted July 15, 2021 Posted July 15, 2021 Excuse me, who have lisp export block attribute include: coord X,Y, Tag and Value to CSV or TXT or XLS? Quote
BIGAL Posted July 16, 2021 Posted July 16, 2021 Admin please move last post by tauntrindp to a new post. Has PM me. Plenty of solutions out there. Quote
Recommended Posts
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.