+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Forum Newbie
    Computer Details
    satydevNegi's Computer Details
    Operating System:
    Windows
    Computer:
    HP Lap Top
    RAM:
    4GB
    Discipline
    Civil
    satydevNegi's Discipline Details
    Occupation
    Civil Engineer Power Industry
    Discipline
    Civil
    Details
    Currently I am working as Site Engineer but I use to Make structural Design also using STAAD Pro
    Using
    AutoCAD 2015
    Join Date
    Sep 2017
    Location
    Noida, India
    Posts
    4

    Default Lisp for getting spot levels

    Registered forum members do not see this ad.

    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.

    Code:
    (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
    Attached Files
    Last edited by SLW210; 19th Sep 2017 at 12:30 pm. Reason: Added Code Tags

  2. #2
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,669

    Default

    Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[CODE]Your Code Here[/CODE] =
    Code:
    Your Code Here
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  3. #3
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    228

    Default

    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
    Different goal also quite often means different path...

  4. #4
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,635

    Default

    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

    [code]
    (repeat (set x (sslength ss_1))
    (setq ent1 (ssname ss_1 (setq x (- x 1))) ; auto goes down to zero
    .....
    )
    A man who never made mistakes never made anything

  5. #5
    Forum Newbie
    Computer Details
    satydevNegi's Computer Details
    Operating System:
    Windows
    Computer:
    HP Lap Top
    RAM:
    4GB
    Discipline
    Civil
    satydevNegi's Discipline Details
    Occupation
    Civil Engineer Power Industry
    Discipline
    Civil
    Details
    Currently I am working as Site Engineer but I use to Make structural Design also using STAAD Pro
    Using
    AutoCAD 2015
    Join Date
    Sep 2017
    Location
    Noida, India
    Posts
    4

    Default

    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.

  6. #6
    Super Member
    Computer Details
    tombu's Computer Details
    Operating System:
    Windows 7 64-bit
    Computer:
    Dell
    Discipline
    Civil
    tombu's Discipline Details
    Occupation
    Design Analyst
    Discipline
    Civil
    Details
    Small Street & Stormwater projects. Traffic Calming and other issues.
    Using
    Civil 3D 2018
    Join Date
    Dec 2010
    Location
    Tallahassee, FL USA
    Posts
    706

    Default

    Quote Originally Posted by satydevNegi View Post
    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.
    Layer 0 for ByBlock Block entities, everything else ByLayer. So many issues can be solved with good templates.

  7. #7
    Forum Newbie
    Computer Details
    satydevNegi's Computer Details
    Operating System:
    Windows
    Computer:
    HP Lap Top
    RAM:
    4GB
    Discipline
    Civil
    satydevNegi's Discipline Details
    Occupation
    Civil Engineer Power Industry
    Discipline
    Civil
    Details
    Currently I am working as Site Engineer but I use to Make structural Design also using STAAD Pro
    Using
    AutoCAD 2015
    Join Date
    Sep 2017
    Location
    Noida, India
    Posts
    4

    Default

    Quote Originally Posted by tombu View Post
    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.

    Code:
    ;;;;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
    Last edited by SLW210; 19th Sep 2017 at 12:29 pm. Reason: Added Code Tags

  8. #8
    Super Moderator SLW210's Avatar
    Computer Details
    SLW210's Computer Details
    Operating System:
    Windows 7 PRO 64-bit
    Computer:
    IBM Lenovo
    Motherboard:
    ACPI x64
    CPU:
    Pentium(R) i5 4570 @ 3.2GHz
    RAM:
    8 GB RAM
    Graphics:
    Nvidia Quadro 600 1GB
    Primary Storage:
    300 GB
    Secondary Storage:
    650GB
    Monitor:
    2x ThinkVision 24"
    Discipline
    Multi-disciplinary
    SLW210's Discipline Details
    Occupation
    Design Draftsman
    Discipline
    Multi-disciplinary
    Details
    Mostly do drafting related to manufacturing. From doing site layouts with proposed updates, additions and renovations to be budgeted and submitted for bid, to updating and changing existing drawings to reflect maintenance and repair/revision work done on site.
    Using
    AutoCAD 2011
    Join Date
    May 2007
    Location
    South Florida, USA
    Posts
    11,669

    Default

    This will be your last warning. Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[CODE]Your Code Here[/CODE] =
    Code:
    Your Code Here
    “A narrow mind and a fat head invariably come on the same person” Zig Zigler



  9. #9
    Forum Newbie
    Computer Details
    satydevNegi's Computer Details
    Operating System:
    Windows
    Computer:
    HP Lap Top
    RAM:
    4GB
    Discipline
    Civil
    satydevNegi's Discipline Details
    Occupation
    Civil Engineer Power Industry
    Discipline
    Civil
    Details
    Currently I am working as Site Engineer but I use to Make structural Design also using STAAD Pro
    Using
    AutoCAD 2015
    Join Date
    Sep 2017
    Location
    Noida, India
    Posts
    4

    Default

    Quote Originally Posted by SLW210 View Post
    This will be your last warning. Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[CODE]Your Code Here[/CODE] =
    Code:
    Your Code Here
    Dear Super Moderator

    I am trying to correct my mistake, expect one more chance
    Code:
    ;;;;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

  10. #10
    Senior Member Jef!'s Avatar
    Using
    AutoCAD 2008
    Join Date
    Sep 2010
    Posts
    228

    Default

    Registered forum members do not see this ad.

    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
    Different goal also quite often means different path...

Similar Threads

  1. LSP, LISP grade levels, point calculation, road levels
    By nosyparker in forum AutoLISP, Visual LISP & DCL
    Replies: 15
    Last Post: 26th Oct 2014, 09:02 am
  2. drawing points from flattened spot levels
    By stupot in forum AutoCAD General
    Replies: 14
    Last Post: 8th Mar 2012, 04:51 pm
  3. Spot levels
    By paulrfair in forum AutoCAD Drawing Management & Output
    Replies: 7
    Last Post: 23rd Feb 2012, 01:06 am
  4. Plotting contours from randoml placed spot levels
    By JamesP in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 13th Jun 2009, 02:56 pm
  5. Spot Levels
    By mdmmike in forum AutoCAD General
    Replies: 4
    Last Post: 7th Aug 2007, 04:52 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts