satydevNegi Posted September 13, 2017 Share Posted September 13, 2017 (edited) Hi This is my first post and I am untrained LISP user. I am currently using LISPfile to obtain spot levels from Auto CAD then open the file in Excel to calculate cutting and filling quantities. The coding is following. (defun c:aaaa() (setq ptu(getpoint "Enter Upper point :") ptl(getpoint "Enter Lower point :") ss_1(ssget "_C" ptu ptl) ss_1(ssget "P" '((0 . "text"))) len (sslength ss_1) cnt 0 f (open "ten04.txt" "a") ) (while (>= len cnt) (setq ent1 (ssname ss_1 cnt) ent2 (entget ent1) ent3 (assoc 1 ent2) ent3 (cdr ent3) ) (write-line ent3 f) (setq cnt (1+ cnt)) ) (close f) (princ) ) Since in this file I ave used two points so I use Excel to repeat my command to obtain data quickly the excel file codes are as follows aaaa 378102575.75,2624684164.103 378127575.75,2624709164.103 aaaa 378127575.75,2624684164.103 378152575.75,2624709164.103 aaaa 378152575.75,2624684164.103 378177575.75,2624709164.103 aaaa 378177575.75,2624684164.103 378202575.75,2624709164.103 aaaa 378202575.75,2624684164.103 378227575.75,2624709164.103 aaaa 378227575.75,2624684164.103 378252575.75,2624709164.103 please help me to modify this file forum-use.dwg Edited September 19, 2017 by SLW210 Added Code Tags Quote Link to comment Share on other sites More sharing options...
SLW210 Posted September 13, 2017 Share Posted September 13, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote Link to comment Share on other sites More sharing options...
Jef! Posted September 13, 2017 Share Posted September 13, 2017 Hi satydevNegi, welcome to the forum. If in your selection set you have 2 items (lets say A & B) the var len correspond to the qty of items in your selection set (2). When you manipulate the selection set you retrieve the items by their index number using (ssname indexnumber). The index start at 0. item A > ssname 0 item B > ssname 1 That is why the cnt is initially set at 0. After retrieving the item, you increment the counter cnt. If the while condition is (>= len cnt), when cnt is 2, same as len, since len is bigger or equal to cnt, it keeps going, trying to retrieve (ssname 2) which corresponds to the 3rd element of the selection set, and it does not exist. Your while condition should be (> len cnt). I'm not sure what exactly you were asking for, and if what I mentioned is the only thing preventing you to get the desired result. I would also strongly suggest that you localize variables... and that you enclose your code in code tags. If you need further assistance, try to be as clear as possible as what your goal is. Cheers Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 14, 2017 Share Posted September 14, 2017 An easier way and I tend do it it now this way is to use repeat rather than while and it takes into account the zero item (repeat (set x (sslength ss_1))(setq ent1 (ssname ss_1 (setq x (- x 1))) ; auto goes down to zero.....) Quote Link to comment Share on other sites More sharing options...
satydevNegi Posted September 14, 2017 Author Share Posted September 14, 2017 Hi Jef! please tell me if this is useful tool or not, I use local variables if i have to make something in auto cad, but here i have to export texts from and not sure if i can do use local variables. i feell my communication is not exactly up to mark. Quote Link to comment Share on other sites More sharing options...
tombu Posted September 14, 2017 Share Posted September 14, 2017 I use local variables if i have to make something in auto cad, but here i have to export texts from and not sure if i can do use local variables. As the texts are saved in a text file I don't see any reason to keep the values of ptu, ptl, ss_1, len, cnt, f, ent1, ent2, or ent3. I'd localize all those variables. They would all be reset if you ran the lisp again anyway. Quote Link to comment Share on other sites More sharing options...
satydevNegi Posted September 17, 2017 Author Share Posted September 17, 2017 (edited) As the texts are saved in a text file I don't see any reason to keep the values of ptu, ptl, ss_1, len, cnt, f, ent1, ent2, or ent3. I'd localize all those variables. They would all be reset if you ran the lisp again anyway. Thank you all for making me understandable about local and global variables. Here i have added modified version just addressing local variables in it . but my worry is still pending here , I want to make the selection process in a way so that we can use this route in multiple times (Looping) for multiple selection sets without typing aaaa many times. Please correct me if my communication does not reach to you. ;;;;Hi this Lisp is written for exporting texts ;;;;having values of ground levels so that ;;;;calculations of earth cutting / filling can ;;;;be obtained. For that type aaaa in Autocad ;;;;command prompt switch off osnap, ;;;;for making lisp short I skip that variable ;;;;pick lower and upper corner in autocad where ;;;;the text you need to export for the purpose ;;;;you will get a file textofspotlvl in your ;;;;working directory open that file in your ;;;;excel software and use (defun c:aaaa( / ptu ptl ss_1 len cnt f ent1 ent2 ent3);command aaaa (setq ptu(getpoint "Enter Upper point :");for making selection ptl(getpoint "Enter Lower point :");of texts ss_1(ssget "_C" ptu ptl);variable for selection set ss_1(ssget "P" '((0 . "text"))) len (sslength ss_1);number of texts cnt 0;counter starts f (open "textofspotlvl.txt" "a");making external file );close setq (while (>= len cnt);looping (setq ent1 (ssname ss_1 cnt);assitant to entget ent2 (entget ent1);for gettingg value of spot level ent3 (assoc 1 ent2); separating spot level ent3 (cdr ent3) );close setq (write-line ent3 f) ;exported (setq cnt (1+ cnt))counter for other texts );closee loop (close f);close file (princ);cleaning memory (princ);cleaning memory );close defun Edited September 19, 2017 by SLW210 Added Code Tags Quote Link to comment Share on other sites More sharing options...
SLW210 Posted September 18, 2017 Share Posted September 18, 2017 This will be your last warning. Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote Link to comment Share on other sites More sharing options...
satydevNegi Posted September 18, 2017 Author Share Posted September 18, 2017 This will be your last warning. Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE]Your Code Here[/NOPARSE] = Your Code Here Dear Super Moderator I am trying to correct my mistake, expect one more chance ;;;;Hi this Lisp is written for exporting texts ;;;;having values of ground levels so that ;;;;calculations of earth cutting / filling can ;;;;be obtained. For that type aaaa in Autocad ;;;;command prompt switch off osnap, ;;;;for making lisp short I skip that variable ;;;;pick lower and upper corner in autocad where ;;;;the text you need to export for the purpose ;;;;you will get a file textofspotlvl in your ;;;;working directory open that file in your ;;;;excel software and use (defun c:aaaa( / ptu ptl ss_1 len cnt f ent1 ent2 ent3);command aaaa (setq ptu(getpoint "Enter Upper point :");for making selection ptl(getpoint "Enter Lower point :");of texts ss_1(ssget "_C" ptu ptl);variable for selection set ss_1(ssget "P" '((0 . "text"))) len (sslength ss_1);number of texts cnt 0;counter starts f (open "textofspotlvl.txt" "a");making external file );close setq (while (>= len cnt);looping (setq ent1 (ssname ss_1 cnt);assitant to entget ent2 (entget ent1);for gettingg value of spot level ent3 (assoc 1 ent2); separating spot level ent3 (cdr ent3) );close setq (write-line ent3 f) ;exported (setq cnt (1+ cnt))counter for other texts );closee loop (close f);close file (princ);cleaning memory (princ);cleaning memory );close defun Quote Link to comment Share on other sites More sharing options...
Jef! Posted September 19, 2017 Share Posted September 19, 2017 Hi Jef! please tell me if this is useful tool or not, it might... we are not far. The thing we will have to do is put the while inside another while... BUT for that to work you need to start by fixing what I talked about in my previous post. There is absolutely no way we can make it work if you try to process more entities in the selection set then what it contains. You will end up with an error: bad argument type: lentityp nil Not only that but when you added the comments on your last edit, you forgot to add a semicolumn ";" in front of the comment "counter for other texts". Fix these 2 issues and post the code back (with code tags), and I will gladly help you with the last step. Cheers 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.