verb222 Posted March 23, 2019 Posted March 23, 2019 Hi! Can someone write similar lisp to existing one or edit this one (attached han.lsp) so that it do following: Click on polyline, extract it's length, put that value in existing block with attribute LEN. Continues to next pair. I attached the dwg where you can see how existing one works and what I need for new one to do. Attached LISP (han.lsp) does the following: It takes value from selected text and puts it into the block with attribute ADR. Continues to next pair. Once again "BIGTNX" to BIGAL for writing this code two years ago (TOPIC: https://www.cadtutor.net/forum/topic/60929-add-street-name-and-adress-number-to-existing-block-attributes/?tab=comments#comment-503564) I edited it so it is probably not so "neat" anymore, but works perfectly for me. Best regards! han.lsp Polyline length to block attribute.dwg Quote
dlanorh Posted March 23, 2019 Posted March 23, 2019 Try this. It will work for lines, all polylines and splines; and will alert if an XLine is selected (infinite length) (defun c:test ( / ent len b_obj) (while (/= nil (setq ent (ssname (ssget "_+.:E:S" '((0 . "*LINE"))) 0))) (cond ( (/= (cdr (assoc 0 (entget ent))) "XLINE") (setq len (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) b_obj (vlax-ename->vla-object (car (entsel "\nPick Attributed Block : "))) );end_setq (foreach att (vlax-invoke b_obj 'getattributes) (if (= "LEN" (vla-get-tagstring att)) (vla-put-textstring att (rtos len 2 3)));adjust required precision in rtos (currently 3 decimal places) );end_foreach ) ( (alert "Line has infinite length")) );end_cond );end_while (princ) );end_defun Quote
Lee Mac Posted March 23, 2019 Posted March 23, 2019 You can use this program and supply a predetermined attribute tag. Quote
verb222 Posted March 23, 2019 Author Posted March 23, 2019 To: mr. dlanorh It works exactly as I expected and wanted. Thank you very much! To: mr. LeeMac Thank you for your solution too. I tried your lisp too. For this specific purpose I prefer this simple code from dlanorh where specific block attribute is aimed in lisp so... when I click (and I have a lot of clicking) I dont need to be precise. I can click on any part of block (with lots of attributes) and only dedicated attribute will change value. Also, my length value does not change so field is not mandatory in this case. I'll be brave to ask one more effort from you... Same simple LSP with clicking... It extracts value of attribute ATT_2 from block_01 and puts it in attribute PROPERTY_1 in block 02. I attached dwg with example. Quote
Lee Mac Posted March 23, 2019 Posted March 23, 2019 12 minutes ago, verb222 said: To: mr. LeeMac Thank you for your solution too. I tried your lisp too. For this specific purpose I prefer this simple code from dlanorh where specific block attribute is aimed in lisp so... when I click (and I have a lot of clicking) I dont need to be precise. I can click on any part of block (with lots of attributes) and only dedicated attribute will change value. Also, my length value does not change so field is not mandatory in this case. As I noted in my earlier comment, you can supply a predetermined attribute tag to my program - please refer to the Custom Commands section of the program page. Quote
dlanorh Posted March 24, 2019 Posted March 24, 2019 No sample drawing attached to your last post, but try this (untested) (defun c:test2 ( / ent a_txt b_obj1 b_obj2 found) (while (/= nil (setq ent (car (entsel "\nPick First Attributed Block : ")))) (setq a_txt nil) (cond ( (= :vlax-true (vlax-get-property (setq b_obj1 (vlax-ename->vla-object ent)) 'hasattributes)) (foreach att (vlax-invoke b_obj1 'getattributes) (if (= "ATT_2" (vla-get-tagstring att)) (setq a_txt (vla-get-textstring att))) );end_foreach ) );end_cond (cond ( (not a_txt) (alert "Attribute ATT_2 NOT in selected Block")) (t (setq b_obj2 (vlax-ename->vla-object (car (entsel "\nPick Second Attributed Block : "))) found nil ) (foreach att (vlax-invoke b_obj2 'getattributes) (cond ( (= "PROPERTY_1" (vla-get-tagstring att)) (vla-put-textstring att a_txt) (setq found T) ) );end_cond );end_foreach (if (not found) (alert "Attribute PROPERTY_1 NOT in selected destination Block")) ) );end_cond );end_while (princ) );end_defun Quote
BIGAL Posted March 24, 2019 Posted March 24, 2019 dalnorh you can use nentsel you can pick an attribute get its tagname, you reverse engineer it and pick block at that point, so can pick attribute 1 block1 attribute 2 block 2 and dont need tagnames. Quote
dlanorh Posted March 24, 2019 Posted March 24, 2019 14 minutes ago, BIGAL said: dalnorh you can use nentsel you can pick an attribute get its tagname, you reverse engineer it and pick block at that point, so can pick attribute 1 block1 attribute 2 block 2 and dont need tagnames. I know, but sometimes attributed blocks have invisible attributes or visibility states with hidden attributes, and you can't pick what you can't see. 1 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.