Ogopogo Posted September 18 Share Posted September 18 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 Share Posted September 19 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 Share Posted September 19 (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 51 minutes ago by BIGAL Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 20 Author Share Posted September 20 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 Share Posted September 20 Sorry Ogopogo, I had no time today. maybe tomorrow... Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 20 Share Posted September 20 (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 by BIGAL Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted September 21 Author Share Posted September 21 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 Friday at 12:49 AM Author Share Posted Friday at 12:49 AM 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 Friday at 04:11 AM Share Posted Friday at 04:11 AM 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 Saturday at 04:28 AM Share Posted Saturday at 04:28 AM 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 Saturday at 09:23 PM Author Share Posted Saturday at 09:23 PM 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 Saturday at 11:27 PM Share Posted Saturday at 11:27 PM (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 Saturday at 11:29 PM by BIGAL Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted Sunday at 12:55 AM Author Share Posted Sunday at 12:55 AM 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 Sunday at 11:41 PM Share Posted Sunday at 11:41 PM 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 Monday at 02:27 AM Author Share Posted Monday at 02:27 AM 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 Monday at 05:00 AM Share Posted Monday at 05:00 AM Code is updated and tested. Quote Link to comment Share on other sites More sharing options...
Ogopogo Posted yesterday at 01:33 AM Author Share Posted yesterday at 01:33 AM 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 54 minutes ago Share Posted 54 minutes ago (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 50 minutes ago by BIGAL 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.