Ogopogo Posted September 18, 2023 Share Posted September 18, 2023 Hi, Is it possible in Autolisp, by clicking on a line or polyline and it will insert the line segment length into a block? The block name is "Wall-Tag-FW" and the attribute name in the block to insert the line length is "Length-Ft". Thank you Quote Link to comment Share on other sites More sharing options...
fuccaro Posted September 19, 2023 Share Posted September 19, 2023 Hello Ogopogo, and welcome! Here is a quick one, it works on LINEs only, not POLYLINEs. Sorry, I am out of my time. If this works as you expect, I will try to add the POLYLINEs tomorrow or so... (defun c:pp() (setq ent (car (entsel "select a block"))) (cond ((= (cdr (assoc 2 (entget ent))) "Wall-Tag-FW") (while (/= (cdr (assoc 2 (entget ent))) "LENGTH-FT") (setq ent (entnext ent))) (setq elist (entget ent)) (setq line (entget (car (entsel "select line")))) (setq dist (rtos (distance (cdr (assoc 10 line)) (cdr (assoc 11 line))))) (setq elist (subst (cons 1 dist) (assoc 1 elist) elist)) (entmod elist) ) ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 19, 2023 Share Posted September 19, 2023 (edited) Using Vl code much easier. (defun c:pp ( / blk atts obj att dist) (setq blk (vlax-ename->vla-object (car (entsel "select block ")))) (if (= (vlax-get blk 'name) "Wall-Tag-FW") (progn (setq atts (vlax-invoke blk 'Getattributes)) (setq obj (vlax-ename->vla-object (car (entsel "select p/line")))) (setq dist (rtos (vlax-get obj 'length) 2 2)) (foreach att atts (if (= (STRCASE (vlax-get att 'tagstring)) "LENGTH-FT") (vlax-put att 'textstring dist) ) ) ) ) (princ) ) (c:pp) To pick only a block and correct name. (setq ss (ssget "+.:S:E" '((0 . "INSERT")(2 . "Wall-Tag-FW")))) (setq blk (vlax-ename->vla-object (ssname ss 0))) Edited September 27, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 20, 2023 Author Share Posted September 20, 2023 Hi Fuccaro, Thank you for help in this. I copied your code and it works. I will wait for your code to handle polylines. Hi Bigal, Thank you for your help. I copied your codes but having problems using it. Not sure why it is not working. Quote Link to comment Share on other sites More sharing options...
fuccaro Posted September 20, 2023 Share Posted September 20, 2023 Sorry Ogopogo, I had no time today. maybe tomorrow... Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 20, 2023 Share Posted September 20, 2023 (edited) My fault changed this in code above. As I tested with one of my dwg's with different tag names. (if (= (STRCASE (vlax-get att 'tagstring)) "LENGTH-FT".") Edited September 20, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 21, 2023 Author Share Posted September 21, 2023 Hi Fuucaro, No worries, any time at your convenience. Hi Bigal, I will try it out tomorrow and let you know. Thank you both for looking into this. Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 22, 2023 Author Share Posted September 22, 2023 Hi Bigal, I think, I am not saving the your codes correctly. I'm copying your codes into WordPad and saving with the extension *.lsp. Is this correct? Or there is something more to do it? Thank you Quote Link to comment Share on other sites More sharing options...
fuccaro Posted September 22, 2023 Share Posted September 22, 2023 Use Notepad, not Wordpad! There was a thread in this forum about, but I can't find it. Probable because it was too old to survive... Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 23, 2023 Share Posted September 23, 2023 Sounds like Wordpad and Word have hidden characters in the file so the lisp will actually not run. Yes Notepad or a preferred is "Notepad ++" it has built in lisp syntax checking. Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 23, 2023 Author Share Posted September 23, 2023 Thank you Fuccaro & Bigal for advising me to use Notepad not Wordpad. I have installed Notepad ++. Starting from scratch, I have copied and pasted both codes. Fuccaro's lisp works great. However, Bigal's code isn't working. I have saved Bigal's code as "BigalPP.lsp", see "Screenshot 2023-09-23.jpg". In Autocad, I loaded the lisp file using "Appload", but receive an error message, see "Screenshot 2023-09-23-1.jpg". I wonder if it is ""LENGTH-FT".", is causing the error.? I have very limited knowledge on Autolisp programming. Once again, I thank you both for helping me. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 23, 2023 Share Posted September 23, 2023 (edited) Sorry my fault a typo did not see it crept in somehow when testing Look at your IF line 9 has a extra " and "." Should be (if (= (STRCASE (vlax-get att 'tagstring)) "LENGTH-FT") Edited September 23, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 24, 2023 Author Share Posted September 24, 2023 Hi Bigal, I have taken out the period "." by coping and pasting your code, see screen shot 2023-09-23-2. I uploaded the revised "BigalPP.lsp" by "Appload", however there is a different error message "; error: malformed list on input", see screen shot 203-09-23-03. I'm sorry for the many texts. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 24, 2023 Share Posted September 24, 2023 Sorry do apologies again I should have looked closer code updated missing a ). Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 25, 2023 Author Share Posted September 25, 2023 No worries Bigal, I'll wait for your revise code for the missing a). Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 25, 2023 Share Posted September 25, 2023 Code is updated and tested. Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 26, 2023 Author Share Posted September 26, 2023 Hi Bigal, I have copied and pasted the updated code, see below. However, I'm still getting "error: malformed list on input" when I load the lisp file. Is what I copied and pasted the correct code? My apologies, if I'm not correctly following your instructions. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 27, 2023 Share Posted September 27, 2023 (edited) When you post a request like this in future always post a dwg, a problem can be as simple as Capitals in the block name. I have to dummy up a dwg block to test code. Download code again Edited September 27, 2023 by BIGAL Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 27, 2023 Author Share Posted September 27, 2023 Hi Bigal, Big high 5! Thank you very much it works! Adding another ) above (princ) did the trick. Quote Link to comment Share on other sites More sharing options...
fuccaro Posted September 27, 2023 Share Posted September 27, 2023 (defun c:pp( / bent sel enttype attr dist) (setq bent (car (entsel "select block"))) (cond ((= (cdr (assoc 2 (entget bent))) "Wall-Tag-FW") (while (/= (cdr (assoc 2 (entget bent))) "LENGTH-FT") (setq bent (entnext bent))) (setq sel (entsel "select (p)line") enttype (cdr (assoc 0 (setq line (entget (car sel)))))) (cond ((= enttype "LINE") (setq dist (distance (cdr (assoc 10 line)) (cdr (assoc 11 line))))) ((= enttype "LWPOLYLINE") (setq dist (extract sel))) (T (princ "What did you select?!!! ")) ) (setq attr (entget bent) attr (subst (cons 1 (rtos dist)) (assoc 1 attr) attr) attr (entmod attr))) (T (princ "Wrong block!!!" )) ) (princ) ) (defun extract(sel / p0 p1 p2 el found dist) (setq p0 (osnap (cadr sel) "_nea") el (entget (car sel)) el (if (= 1 (cdr (assoc 70 el))) (append el (list (assoc 10 el))) el) p1 nil p2 nil i -1 found nil) (while (and (not found) (< (setq i (1+ i)) (length el))) (cond ((= (car (nth i el)) 10) (setq p1 p2 p2 (cdr (nth i el))))) (setq found (and p1 (equal (setq dist (distance p1 p2)) (+ (distance p1 p0)(distance p0 p2)) 1e-5))) ) (if found dist nil) ) Sorry for answering after so much time! Quote Link to comment Share on other sites More sharing options...
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.