Jump to content

Recommended Posts

Posted (edited)

115.jpgHi have this mission to sum the total length of lines between two others automatically , probably it has to be broken at intersection first, in the end i need the sum of lines between the two.

maybe the routine should transfer the lines to another layer first, or something similar that will make the difference

 

Thanks

Edited by danielk
Posted
maybe the routine should transfer the lines to another layer first
You answered your own question, there is lots of total line length stuff out there it may need a extra bit of code say window and layer when filtering the selection set. Maybe start with www.Lee-mac.com routines pretty sure he has a total length lisp. I am sure he will help with a bit of recode to make it more explicit.

 

yep

;; Displays the total length of selected objects at the ;;

;; command line. ;;

;;--------------------=={ Total Length }==--------------------;;

;; ;;

;;------------------------------------------------------------;;

;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;

Posted

Thanks for the recommendation BIGAL :thumbsup:

 

@danielk, the following program should provide the lengths that you require:

 

([color=BLUE]defun[/color] c:intlen ( [color=BLUE]/[/color] app ent idx int lst obj rtn sel tmp )
   ([color=BLUE]while[/color]
       ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect polyline: "[/color])))
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
               )
               (   ([color=BLUE]null[/color] ent) [color=BLUE]nil[/color])
               (   ([color=BLUE]/=[/color] [color=MAROON]"LWPOLYLINE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ent))))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object is not a polyline."[/color])
               )
           )
       )
   )
   ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] ent))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] lst ([color=BLUE]mapcar[/color] '[color=BLUE]cdr[/color] ([color=BLUE]vl-remove-if-not[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]=[/color] 10 ([color=BLUE]car[/color] x))) ([color=BLUE]entget[/color] ent)))
                 lst ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] x lst))) '([color=BLUE]max[/color] [color=BLUE]min[/color]))
                 obj ([color=BLUE]vlax-ename->vla-object[/color] ent)
                 app ([color=BLUE]vlax-get-acad-object[/color])
           )
           ([color=BLUE]apply[/color] '[color=BLUE]vla-zoomwindow[/color] ([color=BLUE]cons[/color] app ([color=BLUE]mapcar[/color] '[color=BLUE]vlax-3D-point[/color] ([color=BLUE]reverse[/color] lst))))
           ([color=BLUE]if[/color]
               ([color=BLUE]setq[/color] sel
                   ([color=BLUE]apply[/color] '[color=BLUE]ssget[/color]
                       ([color=BLUE]cons[/color] [color=MAROON]"_C"[/color]
                           ([color=BLUE]append[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( p ) ([color=BLUE]trans[/color] p 0 1)) lst)
                              '(
                                   (
                                       (0 . [color=MAROON]"ARC,CIRCLE,ELLIPSE,*LINE"[/color])
                                       (-4 . [color=MAROON]"<NOT"[/color])
                                           (-4 . [color=MAROON]"<AND"[/color])
                                               (0 . [color=MAROON]"POLYLINE"[/color]) (-4 . [color=MAROON]"&"[/color]) (70 . 80)
                                           (-4 . [color=MAROON]"AND>"[/color])
                                       (-4 . [color=MAROON]"NOT>"[/color])
                                   )
                               )
                           )
                       )
                   )
               )
               ([color=BLUE]progn[/color]
                   ([color=BLUE]ssdel[/color] ent sel)
                   ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] idx ([color=BLUE]sslength[/color] sel))
                       ([color=BLUE]setq[/color] tmp
                           ([color=BLUE]append[/color]
                               ([color=BLUE]vlax-invoke[/color] obj 'intersectwith
                                   ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] idx ([color=BLUE]1-[/color] idx))))
                                   [color=BLUE]acextendnone[/color]
                               )
                               tmp
                           )
                       )
                   )
               )
           )
           ([color=BLUE]vla-zoomprevious[/color] app)
           ([color=BLUE]repeat[/color] ([color=BLUE]/[/color] ([color=BLUE]length[/color] tmp) 3)
               ([color=BLUE]setq[/color] int ([color=BLUE]cons[/color] ([color=BLUE]vlax-curve-getclosestpointto[/color] ent ([color=BLUE]list[/color] ([color=BLUE]car[/color] tmp) ([color=BLUE]cadr[/color] tmp) ([color=BLUE]caddr[/color] tmp))) int)
                     tmp ([color=BLUE]cdddr[/color] tmp)
               )
           )
           ([color=BLUE]setq[/color] int  ([color=BLUE]vl-list*[/color] ([color=BLUE]vlax-curve-getstartpoint[/color] ent) ([color=BLUE]vlax-curve-getendpoint[/color] ent) int)
                 rtn '([color=BLUE]nil[/color] [color=BLUE]nil[/color])
           )
           ([color=BLUE]mapcar[/color]
               ([color=BLUE]function[/color]
                   ([color=BLUE]lambda[/color] ( a b )
                       ([color=BLUE]setq[/color] rtn ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] ([color=BLUE]-[/color] b a) ([color=BLUE]cadr[/color] rtn)) ([color=BLUE]cdr[/color] ([color=BLUE]reverse[/color] rtn))))
                   )
               )
               ([color=BLUE]setq[/color] int ([color=BLUE]vl-sort[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]vlax-curve-getdistatpoint[/color] ent x)) int) '[color=BLUE]<[/color]))
               ([color=BLUE]cdr[/color]  int)
           )
           ([color=BLUE]apply[/color]
              '([color=BLUE]lambda[/color] ( a b )
                   ([color=BLUE]alert[/color]
                       ([color=BLUE]strcat[/color]
                             [color=MAROON]"Length 1: "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]apply[/color] '[color=BLUE]+[/color] a))
                           [color=MAROON]"\nLength 2: "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]apply[/color] '[color=BLUE]+[/color] b))
                       )
                   )
               )
               rtn
           )
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Posted
Thanks for the recommendation BIGAL :thumbsup:

 

@danielk, the following program should provide the lengths that you require:

 

([color=BLUE]defun[/color] c:intlen ( [color=BLUE]/[/color] app ent idx int lst obj rtn sel tmp )
   ([color=BLUE]while[/color]
       ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]setq[/color] ent ([color=BLUE]car[/color] ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect polyline: "[/color])))
           ([color=BLUE]cond[/color]
               (   ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color])
               )
               (   ([color=BLUE]null[/color] ent) [color=BLUE]nil[/color])
               (   ([color=BLUE]/=[/color] [color=MAROON]"LWPOLYLINE"[/color] ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] 0 ([color=BLUE]entget[/color] ent))))
                   ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object is not a polyline."[/color])
               )
           )
       )
   )
   ([color=BLUE]if[/color] ([color=BLUE]=[/color] 'ename ([color=BLUE]type[/color] ent))
       ([color=BLUE]progn[/color]
           ([color=BLUE]setq[/color] lst ([color=BLUE]mapcar[/color] '[color=BLUE]cdr[/color] ([color=BLUE]vl-remove-if-not[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]=[/color] 10 ([color=BLUE]car[/color] x))) ([color=BLUE]entget[/color] ent)))
                 lst ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]apply[/color] '[color=BLUE]mapcar[/color] ([color=BLUE]cons[/color] x lst))) '([color=BLUE]max[/color] [color=BLUE]min[/color]))
                 obj ([color=BLUE]vlax-ename->vla-object[/color] ent)
                 app ([color=BLUE]vlax-get-acad-object[/color])
           )
           ([color=BLUE]apply[/color] '[color=BLUE]vla-zoomwindow[/color] ([color=BLUE]cons[/color] app ([color=BLUE]mapcar[/color] '[color=BLUE]vlax-3D-point[/color] ([color=BLUE]reverse[/color] lst))))
           ([color=BLUE]if[/color]
               ([color=BLUE]setq[/color] sel
                   ([color=BLUE]apply[/color] '[color=BLUE]ssget[/color]
                       ([color=BLUE]cons[/color] [color=MAROON]"_C"[/color]
                           ([color=BLUE]append[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( p ) ([color=BLUE]trans[/color] p 0 1)) lst)
                              '(
                                   (
                                       (0 . [color=MAROON]"ARC,CIRCLE,ELLIPSE,*LINE"[/color])
                                       (-4 . [color=MAROON]"<NOT"[/color])
                                           (-4 . [color=MAROON]"<AND"[/color])
                                               (0 . [color=MAROON]"POLYLINE"[/color]) (-4 . [color=MAROON]"&"[/color]) (70 . 80)
                                           (-4 . [color=MAROON]"AND>"[/color])
                                       (-4 . [color=MAROON]"NOT>"[/color])
                                   )
                               )
                           )
                       )
                   )
               )
               ([color=BLUE]progn[/color]
                   ([color=BLUE]ssdel[/color] ent sel)
                   ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] idx ([color=BLUE]sslength[/color] sel))
                       ([color=BLUE]setq[/color] tmp
                           ([color=BLUE]append[/color]
                               ([color=BLUE]vlax-invoke[/color] obj 'intersectwith
                                   ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] idx ([color=BLUE]1-[/color] idx))))
                                   [color=BLUE]acextendnone[/color]
                               )
                               tmp
                           )
                       )
                   )
               )
           )
           ([color=BLUE]vla-zoomprevious[/color] app)
           ([color=BLUE]repeat[/color] ([color=BLUE]/[/color] ([color=BLUE]length[/color] tmp) 3)
               ([color=BLUE]setq[/color] int ([color=BLUE]cons[/color] ([color=BLUE]vlax-curve-getclosestpointto[/color] ent ([color=BLUE]list[/color] ([color=BLUE]car[/color] tmp) ([color=BLUE]cadr[/color] tmp) ([color=BLUE]caddr[/color] tmp))) int)
                     tmp ([color=BLUE]cdddr[/color] tmp)
               )
           )
           ([color=BLUE]setq[/color] int  ([color=BLUE]vl-list*[/color] ([color=BLUE]vlax-curve-getstartpoint[/color] ent) ([color=BLUE]vlax-curve-getendpoint[/color] ent) int)
                 rtn '([color=BLUE]nil[/color] [color=BLUE]nil[/color])
           )
           ([color=BLUE]mapcar[/color]
               ([color=BLUE]function[/color]
                   ([color=BLUE]lambda[/color] ( a b )
                       ([color=BLUE]setq[/color] rtn ([color=BLUE]cons[/color] ([color=BLUE]cons[/color] ([color=BLUE]-[/color] b a) ([color=BLUE]cadr[/color] rtn)) ([color=BLUE]cdr[/color] ([color=BLUE]reverse[/color] rtn))))
                   )
               )
               ([color=BLUE]setq[/color] int ([color=BLUE]vl-sort[/color] ([color=BLUE]mapcar[/color] '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]vlax-curve-getdistatpoint[/color] ent x)) int) '[color=BLUE]<[/color]))
               ([color=BLUE]cdr[/color]  int)
           )
           ([color=BLUE]apply[/color]
              '([color=BLUE]lambda[/color] ( a b )
                   ([color=BLUE]alert[/color]
                       ([color=BLUE]strcat[/color]
                             [color=MAROON]"Length 1: "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]apply[/color] '[color=BLUE]+[/color] a))
                           [color=MAROON]"\nLength 2: "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]apply[/color] '[color=BLUE]+[/color] b))
                       )
                   )
               )
               rtn
           )
       )
   )
   ([color=BLUE]princ[/color])
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

thanks for your afford first, but i dont get length of the polyline between the two other polylines, i get two results and i dont understand forw what they refers to. i thought its the two length for each side of crossing , but if i checked it manually and its not the same results.

also the lisp doesnt prompt to check for two lines so the possibilty for more results is open. i hope you got my point..

 

Thanks

Posted
The following diagram should explain:

 

[ATTACH]49623[/ATTACH]

 

got it! :D genius as always!

Thank you so much!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...