Results 1 to 9 of 9

Thread: Get length list of line-entitys (arc)

  1. #1
    Member cadplayer's Avatar
    Join Date
    2011-08
    Posts
    30
    Login to Give a bone
    0

    Default Get length list of line-entitys (arc)

    I try to get a list of legth and radius

    Result could be:

    Totallength: 223.55 m
    Radius 1: 25m
    Radius 0.5: 10 m

    and put the data as text to line-entity.
    Here is my trial.

    Code:
    (defun c:st (/ #SS #Len)
      (vl-load-com)
      (princ "\nSelect Arc, Line, LWPolyline object(s) to calculate total length: ")
      (cond
        ((setq #SS (ssget '((0 . "ARC,LINE,LWPOLYLINE"))))
         (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
         (setq #Len 0.)
         (initget "Yes No")
           (setq AW (getkword "\nwith text [Yes/No]<No>:"))
           (cond
         ((= AW "Yes")
          (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
            (cond ((eq (vla-get-objectname x) "AcDbArc")
               (setq #Len (+ #Len (vla-get-ArcLength x)))
               (command "text" (vlax-curve-getStartPoint x) "0.375" "" (rtos(vla-get-ArcLength x)2 2))
               )
              ((vl-position (vla-get-objectname x) '("AcDbLine" "AcDbPolyline"))
               (setq #Len (+ #Len (vla-get-Length x)))
               (command "text" (vlax-curve-getStartPoint x) "0.375" "" (rtos(vla-get-Length x)2 2))
               ) 
              );cond
            ); vlax-for
          (total)
          )
         ('T
          (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
            (cond ((eq (vla-get-objectname x) "AcDbArc")
               (setq #Len (+ #Len (vla-get-ArcLength x)))
               )
              ((vl-position (vla-get-objectname x) '("AcDbLine" "AcDbPolyline"))
               (setq #Len (+ #Len (vla-get-Length x)))
               ) 
              ); cond
            ); vlax-for
          (total)
          )
         );cond
    ;;;     (vla-delete #SS)
         )
        );cond
      )
    (defun total ()
      (alert (strcat "Total Length: "(setvar 'users5 (rtos #Len))
             ) ;_ strcat
         ) ;_ alert
      (princ)
      )
    Last edited by Opie; 2012-01-25 at 02:43 PM. Reason: [code] tags maintain formatted code

  2. #2
    Member cadplayer's Avatar
    Join Date
    2011-08
    Posts
    30
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    I try it little easier: If I write
    (setq a '(1 2 3)) I get a = (1 2 3)
    Now I want to convert list a in
    a= ((1) (2) (3))
    How can I do it?

    Another question is
    I´d like to have
    string "123 Line 12.35" convert in list ((123) (Line) (12.35))
    Last edited by cadplayer; 2012-01-26 at 08:14 AM.

  3. #3
    All AUGI, all the time pbejse's Avatar
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    (mapcar 'list a)

    Code:
    (defun listme  (str)
                (mapcar '(lambda (j)
                               (list j))
                        (read (strcat "(" str ")"))
                        )
                )
    (LISTME "123 Line 12.35")
    ((123) (LINE) (12.35))

    You asking for two different results on two different forums
    Last edited by pbejse; 2012-01-26 at 12:22 PM.

  4. #4
    Member cadplayer's Avatar
    Join Date
    2011-08
    Posts
    30
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    I wrote this and can't get a list with all arc and line entyties.
    I think to can get this endresult

    Totallength: 123.00
    Lines: 25.00
    Arc 1: 85.00
    Arc 2: 13.00

    I have to collect all lines var ALIST (arc) and LLIST (lines) and than I must sort list after Lines and arc

    Column 32x 26("101" "LINE" 1.80)
    Code:
    ("102" "LINE" 49.89)      
    ("103" "ARC"  4.67 3.00)  
    ("104" "LINE" 2.00)       
    ("105" "LINE" 1.00)       
    ("106" "LINE" 28.75)      
    ("107" "LINE" 6.00)       
    ("108" "LINE" 1.25)       
    ("109" "LINE" 6.00)       
    ("110" "LINE" 27.50)      
    ("111" "LINE" 6.00)       
    ("112" "LINE" 5.38)       
    ("113" "LINE" 9.81)       
    ("114" "LINE" 56.99)      
    ("115" "LINE" 6.94)       
    ("116" "LINE" 3.75)       
    ("117" "ARC"  2.16 28.50) 
    ("118" "LINE" 35.37)      
    ("119" "ARC"  4.70 3.00)  
    ("120" "LINE" 1.55)       
    ("121" "LINE" 6.00)       
    ("122" "LINE" 27.50)      
    ("123" "LINE" 12.00)      
    ("124" "LINE" 13.69)      
    ("125" "ARC"  4.61 3.00)  
    ("126" "LINE" 6.18)       
    ("127" "ARC"  4.76 3.00)  
    ("128" "LINE" 46.56)      
    ("129" "ARC"  4.77 3.00)  
    ("130" "LINE" 48.10)      
    ("131" "ARC"  11.72 8.00) 
    ("132" "LINE" 2.25)      
    
     
    ; string convert in list
    
    (defun str-to-list (str)
      (mapcar
        (function pl:read)
        (vl-remove
          ""
          (apply (function append)
                 (mapcar (function (lambda (a) (pl:string->list a " "))) (pl:string->list str "\""))
          )
        )
      )
    )
    
    (defun pl:string->list (_str _br / _pos)
      (if (setq _pos (vl-string-search _br _str))
        (cons (substr _str 1 _pos) (pl:string->list (substr _str (+ (strlen _br) _pos 1)) _br))
        (list _str)
      )
    )
    
    (defun pl:read (str / _chk)
      (cond ((vl-string-position 45 str 1) str)
            ((= "" (setq _chk (vl-string-trim "-0123456789" str))) (atoi str))
            ((= "." _chk) (atof str))
            ((= "," _chk) (atof (vl-string-translate "," "." str)))
            (t str)
      )
    )
    
    ;Selection set of line lengths are totaled and displayed.
    ;--------------------------------------------------
    (defun GetArcLength (END_ANG START_ANG ARC_RAD / TOTAL_ANG)
      (setq TOTAL_ANG (- END_ANG START_ANG))
      (while (< TOTAL_ANG 0)
        (setq TOTAL_ANG (+ TOTAL_ANG (* 2 pi)))
        )
      (while (> TOTAL_ANG (* 2 pi))
        (setq TOTAL_ANG (- TOTAL_ANG (* 2 pi)))
        )
      (* (* 2 pi ARC_RAD) (/ TOTAL_ANG (* 2 pi)))
      )
    ;--------------------------------------------------
    ;get length of lwpolyline or polyline (no bulges)
    (defun GET_LWPL ()
      (vl-load-com)
    ;  (setq OBJ (vlax-ename->vla-object (car (entsel "Select entity: "))))
      (setq OBJ (vlax-ename->vla-object ENT))
      (if (vlax-property-available-p OBJ 'Length)
        (setq LWTLEN (vlax-get obj 'Length))
    ;    (princ "Entity has no Length property")
        (setq LWTLEN 0.0)
        )
      (setq LLEN LWTLEN TLEN (+ LLEN TLEN)
        )
      ) ;end GET_LWPL
    
    
    (defun c:ADDLINE () ;( / A B LEN TLEN LLEN )
       (prompt "Select desired LINE and/or ARC entities ->") (terpri)
       (setq SS  (ssget)
             SSZERO (ssadd)
             SSL (sslength SS)
             NUM  0
             TLEN 0
             LLEN 0      
       )
       (repeat SSL
        (setq ENT     (ssname SS NUM)
              ENTAL   (entget ENT)
              ENTTYPE (cdr (assoc 0 ENTAL))
        )
        (cond
        ((eq ENTTYPE "LINE")
             (progn
               (GET_LWPL)
               (prompt (strcat "\n" (rtos NUM 2 0) " " ENTTYPE " " (rtos LLEN 2 2)))
           (setq llist (str-to-list (strcat "\n" (rtos num 2 0) " " enttype " " (rtos llen 2 2))))
    
    ;;;       (setq LLIST (list LLIST))
    
            ))
    ;;;    ((eq ENTTYPE "POLYLINE")
    ;;;         (progn
    ;;;           (GET_LWPL)
    ;;;       (prompt (strcat "\n" (rtos NUM 2 0) " " ENTTYPE " " (rtos LLEN 2 2)))
    ;;;        ))
        ((eq ENTTYPE "ARC")
             (progn
               ; Get the Arc's dimensional data:
               (setq SA (cdr (assoc 50 ENTAL))        ;start angle
                     EA (cdr (assoc 51 ENTAL))        ;end angle
                     AR (cdr (assoc 40 ENTAL))        ;arc radius
               )
               ; Calculate the ARC's length:
               (setq AL (GetArcLength EA SA AR)        ;arc length
                     LLEN AL
                     TLEN (+ LLEN TLEN)
               )
               (if (eq LLEN 0.0) (ssadd ENT SSZERO))
           (prompt (setq ALIST (strcat "\n" (rtos NUM 2 0) " " ENTTYPE " " (rtos LLEN 2 2) " " (rtos AR 2 2))))
           (setq alist (str-to-list (strcat "\n" (rtos num 2 0) " " enttype " " (rtos llen 2 2) " " (rtos ar 2 2))))
           
            ))
    ;;;        ((eq ENTTYPE "LWPOLYLINE")
    ;;;          (progn
    ;;;           (GET_LWPL)
    ;;;           (prompt (strcat "\n" (rtos NUM 2 0) " " ENTTYPE " " (rtos LLEN 2 2)))
    ;;;        ))
            (ENTTYPE
              (progn
               (ssadd ENT SSZERO)
               (prompt (strcat "\n" (rtos NUM 2 0) " " ENTTYPE " " "Length not found."))
              )
            )
        )
        (setq NUM (1+ NUM))
       )
       (setq SHOWLEN (strcat "\nTotal length: " (rtos TLEN 2 2)
                 " and [" (rtos (sslength SSZERO) 2 0) "] object(s) ignored."
                      )
       )
       (alert SHOWLEN)
        (princ)
    )
    ;-
    Last edited by Opie; 2012-01-26 at 02:38 PM. Reason: [code] tags added for readability

  5. #5
    All AUGI, all the time pbejse's Avatar
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    What does "102" represent?

    ("102" "LINE" 49.89)

    Totallength: 123.00
    Lines: 25.00
    Arc 1: 85.00
    Arc 2: 13.00

    What is the reference for Arc1 and Arc2?

  6. #6
    Member cadplayer's Avatar
    Join Date
    2011-08
    Posts
    30
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    "102" is entity number
    Arc 1 means arc with radius 1m
    Arc 2 means arc with radius 2m

    Is it possible to get length from all 1-m-radius and 2-m-radius ?

  7. #7
    All AUGI, all the time pbejse's Avatar
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    Quote Originally Posted by cadplayer View Post
    "102" is entity number
    How would the program know what entity numebr to assign? via individual selection or random?

    Quote Originally Posted by cadplayer View Post
    Is it possible to get length from all 1-m-radius and 2-m-radius ?
    Radius 1.0 and 2.0 and no values less than 2 and more than 1?

    No value limit for Lines?

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,536
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    Quote Originally Posted by pbejse View Post
    How would the program know what entity numebr to assign? via individual selection or random?
    It looks like the OP's code iterates the initial selection set and builds the list of data lists, then wants to iterate the resultant lists to perform the tabulation.

    Perhaps this process could be simplified by iterating the selection set once, and CONDitionally filtering for entity type, and tabulating the quantities in one step.

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  9. #9
    All AUGI, all the time pbejse's Avatar
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    0

    Default Re: Get length list of line-entitys (arc)

    Quote Originally Posted by RenderMan View Post
    It looks like the OP's code iterates the initial selection set and builds the list of data lists, then wants to iterate the resultant lists to perform the tabulation.

    Perhaps this process could be simplified by iterating the selection set once, and CONDitionally filtering for entity type, and tabulating the quantities in one step.

    HTH
    Ditto

    Thats the plan Renderman. Also filtering the selection from the get-go

Similar Threads

  1. Type Line Length When Sketching Line
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 2
    Last Post: 2012-11-07, 04:56 AM
  2. Line Length to Materials List
    By surber in forum AutoCAD General
    Replies: 1
    Last Post: 2007-06-19, 01:08 PM
  3. Lisp routine to list line length and line ID
    By hlecates in forum AutoLISP
    Replies: 6
    Last Post: 2007-03-21, 04:03 PM
  4. Use LENGTHEN command to list Line length
    By dzatto in forum AutoCAD Tips & Tricks
    Replies: 2
    Last Post: 2007-01-02, 03:54 PM
  5. Replies: 8
    Last Post: 2006-12-27, 02:05 PM

Posting Permissions

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