Page 1 of 4 1234 LastLast
Results 1 to 10 of 54

Thread: Area Between Two Polylines

Hybrid View

  1. #1
    Member
    Join Date
    2008-04
    Posts
    22

    Default Area Between Two Polylines

    Hi I am a beginner in LISP Programming. If some body can help me to write a lisp to calculate "Total Upper Area" and "Total Lower Area" between two polylines which intersects each other in many places. See attached Drawing as a reference. Many Thanks in advance
    Attached Files Attached Files

  2. #2
    I could stop if I wanted to marko_ribar's Avatar
    Join Date
    2004-06
    Location
    Belgrade, Serbia, Europe
    Posts
    414

    Default Re: Area Between Two Polylines

    To do this using lisp, it will be pretty hard job... My opinion, and I suggest you use it is to use commands : "BPOLY" for creating area islands by picking point inside area of two intersecting boundary polylines; and after that to use command "AREA" -> Add option -> Select Objects... For better precision use "UNITS" command to set decimal precision of calculated areas...

    Hope this helps for now..., M.R.
    Marko Ribar, d.i.a. (graduated engineer of architecture)

    M.R. on Youtube


  3. #3
    Member
    Join Date
    2008-04
    Posts
    22

    Default Re: Area Between Two Polylines

    Thank you Marko for your quick replay.
    This is what iam doing now. There are several drawings, may be more than 100, to do this practice and may miss some area. So i thought of making a small routine by saying in SSGET the to polylines.

    I am using the following code and iam not much happy with it. If i could do some thing to avoid the PICKING, it is not only time saving also avoid data missing.

    Code:
    (DEFUN c:cf ()
      (setvar "cmdecho" 0)
      (setq totfil 0)
      (setq totcut 0)
      (SETQ ERASESET (ssadd))
      (command "regenall")
      (while
        (setq filpt (getpoint "\nPick FILL Area internal Point"))
         (command "-boundary" "a" "o" "p" "" filpt "")
    
         (setq cfens (entlast))
         (if cfens
           (progn
    	 (setq chk (cdr (assoc 0 (entget cfens))))
    	 (if (= chk "LWPOLYLINE")
    	   (progn
    	     (setq chk1 (cdr (assoc 70 (entget cfens))))
    	     (if (= (rem chk1 2) 1)
    	       (progn
    		 (command "area" "e" cfens)
    		 (command "chprop" cfens "" "c" 7 "")
    		 (setq larea (getvar "area"))
    		 (if larea
    		   (setq totfil (+ totfil larea))
    		 ) ;_ end of if
    	       ) ;_ end of progn
    	     ) ;_ end of if
    	     (SSADD cfens ERASESET)
    	   ) ;_ end of progn
    	 ) ;_ end of if
           ) ;_ end of progn
         ) ;_ end of if
      ) ;_ end of while
      (while
        (setq cutpt (getpoint "\nPick CUT Area internal Point"))
         (command "-boundary" "a" "o" "p" "" cutpt "")
    
         (setq cfens (entlast))
         (if cfens
           (progn
    	 (setq chk (cdr (assoc 0 (entget cfens))))
    	 (if (= chk "LWPOLYLINE")
    	   (progn
    	     (setq chk1 (cdr (assoc 70 (entget cfens))))
    	     (if (= (rem chk1 2) 1)
    	       (progn
    		 (command "area" "e" cfens)
    		 (command "chprop" cfens "" "c" 2 "")
    		 (setq larea (getvar "area"))
    		 (if larea
    		   (setq totcut (+ totcut larea))
    		 ) ;_ end of if
    	       ) ;_ end of progn
    	     ) ;_ end of if
    	     (SSADD cfens ERASESET)
    	   ) ;_ end of progn
    	 ) ;_ end of if
           ) ;_ end of progn
         ) ;_ end of if
      ) ;_ end of while
      (setq fillarea (rtos totfil 2 3))
      (setq cutarea (rtos totcut 2 3))
      (if ERASESET
        (command "erase" ERASESET "")
      ) ;_ end of if
    
    ;;;I am using a Title Block with attributes
    ;;;And i need to update that with new Total areas
    
      (setq
        ssblk (ssget "x"
    		 (list (cons 0 "insert") (cons 2 "A3_Title_EW_Cont4"))
    	  ) ;_ end of ssget
      ) ;_ end of setq
      (setq ttlblk (ssname ssblk 0))
      (setq attrblock (entnext ttlblk))
      (while (/= (cdr (assoc 0 (entget attrblock))) "SEQEND")
        (setq attrent (entget attrblock))
        (if	(= (cdr (assoc 0 attrent)) "ATTRIB")
          (progn
    	(setq atvalue (assoc 1 attrent))
    	(cond
    	  ((= (cdr (assoc 2 attrent)) "CUT")
    	   (setq newattrib (cons 1 cutarea))
    	   (setq su (subst newattrib atvalue attrent))
    	   (entmod su)
    	   (entupd attrblock)
    	  )
    	  ((= (cdr (assoc 2 attrent)) "CHAINAGE")
    	   (setq ex_chainage atvalue)
    	  )
    	  ((= (cdr (assoc 2 attrent)) "FILL")
    	   (setq newattrib (cons 1 fillarea))
    	   (setq su (subst newattrib atvalue attrent))
    	   (entmod su)
    	   (entupd attrblock)
    	  )
    	) ;_ end of cond
          ) ;_ end of progn
        ) ;_ end of if
        (setq attrblock (entnext attrblock))
      ) ;_ end of while
    
    ;;;;and send this Areas to to a CSV file
    
      (setq dwgpre_plt (getvar "dwgprefix"))
      (setq fnm (strcat dwgpre_plt "Corrected Fill Vol.csv"))
      (setq opn (open fnm "a"))
      (setq txt (strcat (cdr ex_chainage) "," cutarea "," fillarea))
      (write-line txt opn)
      (setq opn (close opn))
      (princ)
    ) ;_ end of DEFUN
    Last edited by rkmcswain; 2011-06-07 at 03:32 PM. Reason: added CODE tags

  4. #4
    Member
    Join Date
    2012-01
    Posts
    4

    Default Re: Area Between Two Polylines

    Quote Originally Posted by marko_ribar View Post
    To do this using lisp, it will be pretty hard job... My opinion, and I suggest you use it is to use commands : "BPOLY" for creating area islands by picking point inside area of two intersecting boundary polylines; and after that to use command "AREA" -> Add option -> Select Objects... For better precision use "UNITS" command to set decimal precision of calculated areas...

    Hope this helps for now..., M.R.
    please will you do this using VBA it will be very use ful for me

  5. #5
    I could stop if I wanted to marko_ribar's Avatar
    Join Date
    2004-06
    Location
    Belgrade, Serbia, Europe
    Posts
    414

    Default Re: Area Between Two Polylines

    Try this... It may help you :

    Code:
    ;;=====================================
    ;;  return a list of intersect points  
    ;;=====================================
    (defun get_interpts (obj1 obj2 / iplist)
      (if (not (vl-catch-all-error-p
                 (setq iplist (vl-catch-all-apply
                                'vlax-safearray->list
                                (list
                                  (vlax-variant-value
                                    (vla-intersectwith obj1 obj2 acextendnone)
                                  ))))))
        iplist
      )
    )
    
    (defun get_iplstpts (obj1 obj2 / iplst iplstn pt iplstpts)
    (setq iplst (get_interpts obj1 obj2))
    (setq iplstn (length iplst))
    	(repeat (/ iplstn 3)
    	(setq pt (list (car iplst) (cadr iplst) (caddr iplst)) )
    		(repeat 3
    		(setq iplst (cdr iplst))
    		)
    	(setq iplstpts (cons pt iplstpts))
    	)
    (setq iplstpts (reverse iplstpts))
    )
    
    (defun c:areabtw2pl ( / oscmd fuzz ent1 obj1 obj2 obj1u obj1d ptu ptd ptlst ptlstn pt1 param1 pt2 param2 pt param ssup ssdwn ent k auu au add ad)
    (vl-load-com)
    (vl-cmdf "ucs" "w")
    (setq oscmd (getvar "osmode"))
    (setvar "luprec" 8)
    (setvar "osmode" 0)
    (setq ent1 (car (entsel "\nSelect first - border reference polyline")) )
    (setq obj1 (vlax-ename->vla-object ent1 ))
    (setq obj2 (vlax-ename->vla-object (car (entsel "\nSelect second polyline")) ))
    (setq ptu (getpoint "\nPick point that determins upper side of border polyline")) 
    (setq ptd (getpoint "\nPick point that determins lower side of border polyline")) 
    (setq fuzz (getdist "\nPick fuzz distance for checking boundaries - lower the number - better precision : "))
    
    (command "offset" fuzz ent1 ptu "")
    (setq obj1u (vlax-ename->vla-object (entlast)))
    (setq ptlst (get_iplstpts obj1u obj2))
    (setq ptlstn (length ptlst))
    	(repeat (/ ptlstn 2)
    	(setq pt1 (car ptlst))
    	(setq pt2 (cadr ptlst))
    	(setq param1 (vlax-curve-getParamAtPoint obj1u pt1))
    	(setq param2 (vlax-curve-getParamAtPoint obj1u pt2))
    	(setq param (/ (+ param1 param2) 2))
    	(setq pt (vlax-curve-getPointAtParam obj1u param))
    		(repeat 2
    		(setq ptlst (cdr ptlst))
    		)
    	(setq ptlstupper (cons pt ptlstupper))
    	)
    (setq ptlstupper (reverse ptlstupper))
    (entdel (entlast))
    
    (command "offset" fuzz ent1 ptd "")
    (setq obj1d (vlax-ename->vla-object (entlast)))
    (setq ptlst (get_iplstpts obj1d obj2))
    (setq ptlstn (length ptlst))
    	(repeat (/ ptlstn 2)
    	(setq pt1 (car ptlst))
    	(setq pt2 (cadr ptlst))
    	(setq param1 (vlax-curve-getParamAtPoint obj1d pt1))
    	(setq param2 (vlax-curve-getParamAtPoint obj1d pt2))
    	(setq param (/ (+ param1 param2) 2))
    	(setq pt (vlax-curve-getPointAtParam obj1d param))
    		(repeat 2
    		(setq ptlst (cdr ptlst))
    		)
    	(setq ptlstlower (cons pt ptlstlower))
    	)
    (setq ptlstlower (reverse ptlstlower))
    (entdel (entlast))
    
    (setq ssup (ssadd))
    	(foreach pt ptlstupper
    	(command "boundary" pt "")
    	(setq ent (entlast))
    	(ssadd ent ssup)
    	)
    
    (setq k -1)
    (setq auu 0.0000)
    	(repeat (sslength ssup)
    	(setq k (1+ k))
    	(setq ent (ssname ssup k))
    	(command "area" "o" ent "")
    	(setq au (getvar "area"))
    	(setq auu (+ au auu))
    	)
    
    (setq ssdwn (ssadd))
    	(foreach pt ptlstlower
    	(command "boundary" pt "")
    	(setq ent (entlast))
    	(ssadd ent ssdwn)
    	)
    
    (setq k -1)
    (setq add 0.0000)
    	(repeat (sslength ssdwn)
    	(setq k (1+ k))
    	(setq ent (ssname ssdwn k))
    	(command "area" "o" ent "")
    	(setq ad (getvar "area"))
    	(setq add (+ ad add))
    	)
    
    (command "erase" ssup "")
    (command "erase" ssdwn "")
    
    (prompt "\nTotal Upper Areas are : ")(princ auu)(prompt "\nTotal Lower Areas are : ")(princ add)
    (setvar "osmode" oscmd)
    
    (princ)
    )
    M.R.
    Marko Ribar, d.i.a. (graduated engineer of architecture)

    M.R. on Youtube


  6. #6
    Member
    Join Date
    2008-04
    Posts
    22

    Default Re: Area Between Two Polylines

    Thanks Marko
    Great stuff
    I will let you know the final product

  7. #7
    Member
    Join Date
    2008-04
    Posts
    22

    Default Re: Area Between Two Polylines

    Hi Marko

    I have gone through the code. There is some problem. if the fuzz value is so lower or so higher some times it wont intersect the with the new offset entity, so that it omit the point for bpoly. we will not be able to identify whether it missed or not.
    Sorry to bother you again and i really appreciate your effort you made. Is there any way to find the upper and lower vertex of two polylines from the same scenario.

  8. #8
    I could stop if I wanted to marko_ribar's Avatar
    Join Date
    2004-06
    Location
    Belgrade, Serbia, Europe
    Posts
    414

    Default Re: Area Between Two Polylines

    There is another problem you should consider...

    If polyline for calculation don't touch reference - border polyline making "V" shape near border pline and fuzz is higher than lower vertex of "V" shape, offset pline will intersect pline for calculation 4 times on that segment, and therefore, you'll have 2 points for picking executing boundary poly command. So, instead of 1 boundary pline, you will have 2 overlapping plines, both considered in calculation of areas...

    To avoid this, I suggest you make regions for all upper polylines, and use union command on all of them and then obtain area of that one region for upper areas (and the same this for lower areas).

    P.S. Maybe the best way - not to make any changes to routine you already have is to pick fuzz so small that it won't intersect shape pline on 1 segment for more than 2 times - 1 point for making bpoly, and to be enough big number for taking its bpoly points in consideration while making them (for too small number you may receive message that point touches reference - border pline, bplolys won't be generated and calculated areas will be 0.0)...

    M.R.
    Marko Ribar, d.i.a. (graduated engineer of architecture)

    M.R. on Youtube


  9. #9
    I could stop if I wanted to marko_ribar's Avatar
    Join Date
    2004-06
    Location
    Belgrade, Serbia, Europe
    Posts
    414

    Default Re: Area Between Two Polylines

    Here is modified code that creates regions (more reliable results) :

    Code:
    ;;=====================================
    ;;  return a list of intersect points  
    ;;=====================================
    (defun get_interpts (obj1 obj2 / iplist)
      (if (not (vl-catch-all-error-p
                 (setq iplist (vl-catch-all-apply
                                'vlax-safearray->list
                                (list
                                  (vlax-variant-value
                                    (vla-intersectwith obj1 obj2 acextendnone)
                                  ))))))
        iplist
      )
    )
    
    (defun get_iplstpts (obj1 obj2 / iplst iplstn pt iplstpts)
    (setq iplst (get_interpts obj1 obj2))
    (setq iplstn (length iplst))
    	(repeat (/ iplstn 3)
    	(setq pt (list (car iplst) (cadr iplst) (caddr iplst)) )
    		(repeat 3
    		(setq iplst (cdr iplst))
    		)
    	(setq iplstpts (cons pt iplstpts))
    	)
    (setq iplstpts (reverse iplstpts))
    )
    
    (defun c:areabtw2pl ( / oscmd fuzz ent1 obj1 obj2 obj1u obj1d ptu ptd ptlst ptlstn pt1 param1 pt2 param2 
    
    pt param ssup ssdwn ent k auu au add ad ptlstupper ptlstlower)
    (vl-load-com)
    (vl-cmdf "ucs" "w")
    (setq oscmd (getvar "osmode"))
    (setvar "luprec" 8)
    (setvar "osmode" 0)
    (setq ent1 (car (entsel "\nSelect first - border reference polyline")) )
    (setq obj1 (vlax-ename->vla-object ent1 ))
    (setq obj2 (vlax-ename->vla-object (car (entsel "\nSelect second polyline")) ))
    (setq ptu (getpoint "\nPick point that determins upper side of border polyline")) 
    (setq ptd (getpoint "\nPick point that determins lower side of border polyline")) 
    (setq fuzz (getdist "\nPick fuzz distance for checking boundaries - lower the number - better precision : 
    
    "))
    
    (command "offset" fuzz ent1 ptu "")
    (setq obj1u (vlax-ename->vla-object (entlast)))
    (setq ptlst (get_iplstpts obj1u obj2))
    (setq ptlstn (length ptlst))
    	(repeat (/ ptlstn 2)
    	(setq pt1 (car ptlst))
    	(setq pt2 (cadr ptlst))
    	(setq param1 (vlax-curve-getParamAtPoint obj1u pt1))
    	(setq param2 (vlax-curve-getParamAtPoint obj1u pt2))
    	(setq param (/ (+ param1 param2) 2))
    	(setq pt (vlax-curve-getPointAtParam obj1u param))
    		(repeat 2
    		(setq ptlst (cdr ptlst))
    		)
    	(setq ptlstupper (cons pt ptlstupper))
    	)
    (setq ptlstupper (reverse ptlstupper))
    (entdel (entlast))
    
    (command "offset" fuzz ent1 ptd "")
    (setq obj1d (vlax-ename->vla-object (entlast)))
    (setq ptlst (get_iplstpts obj1d obj2))
    (setq ptlstn (length ptlst))
    	(repeat (/ ptlstn 2)
    	(setq pt1 (car ptlst))
    	(setq pt2 (cadr ptlst))
    	(setq param1 (vlax-curve-getParamAtPoint obj1d pt1))
    	(setq param2 (vlax-curve-getParamAtPoint obj1d pt2))
    	(setq param (/ (+ param1 param2) 2))
    	(setq pt (vlax-curve-getPointAtParam obj1d param))
    		(repeat 2
    		(setq ptlst (cdr ptlst))
    		)
    	(setq ptlstlower (cons pt ptlstlower))
    	)
    (setq ptlstlower (reverse ptlstlower))
    (entdel (entlast))
    
    (setq ssup (ssadd))
    	(foreach pt ptlstupper
    	(command "boundary" pt "")
    	(setq ent (entlast))
    	(ssadd ent ssup)
    	)
    
    (setq k -1)
    	(repeat (sslength ssup)
    	(setq k (1+ k))
    	(setq ent (ssname ssup k))
    	(command "region" ent "")
    	(ssadd (entlast) ssup)
    	)
    (command "union" ssup "")
    (command "area" "o" (entlast) "")
    (setq auu (getvar "area"))
    (ssadd (entlast) ssup)
    
    (setq ssdwn (ssadd))
    	(foreach pt ptlstlower
    	(command "boundary" pt "")
    	(setq ent (entlast))
    	(ssadd ent ssdwn)
    	)
    
    (setq k -1)
    	(repeat (sslength ssdwn)
    	(setq k (1+ k))
    	(setq ent (ssname ssdwn k))
    	(command "region" ent "")
    	(ssadd (entlast) ssdwn)
    	)
    (command "union" ssdwn "")
    (command "area" "o" (entlast) "")
    (setq add (getvar "area"))
    (ssadd (entlast) ssdwn)
    
    (command "erase" ssup "")
    (command "erase" ssdwn "")
    
    (prompt "\nTotal Upper Areas are : ")(princ auu)(prompt "\nTotal Lower Areas are : ")(princ add)
    (setvar "osmode" oscmd)
    
    (princ)
    )
    M.R.
    Marko Ribar, d.i.a. (graduated engineer of architecture)

    M.R. on Youtube


  10. #10
    Member
    Join Date
    2008-04
    Posts
    22

    Default Re: Area Between Two Polylines

    Thanks Mrko

    Sorry still in some drawing i get unexpected Total area and in some case very accurate. i am playing with the code. i get you my findings if i could (it seems I couldnt)
    Once again thank you for your quick response and effort

    Aleem

Page 1 of 4 1234 LastLast

Similar Threads

  1. Area Between Two Polylines
    By skr.alamuri119736 in forum VBA/COM Interop
    Replies: 3
    Last Post: 2012-01-26, 02:42 PM
  2. Area of multiple polylines
    By .chad in forum ACA General
    Replies: 10
    Last Post: 2010-01-27, 07:33 PM
  3. Length of polylines within an area
    By .T. in forum AutoLISP
    Replies: 53
    Last Post: 2009-10-08, 12:47 AM
  4. LENGTH and area of many polylines
    By marijan.marsic in forum AutoLISP
    Replies: 16
    Last Post: 2008-12-02, 07:50 AM
  5. Retaining wall Area's from 3D Polylines
    By andy.manninen in forum Land Desktop - General
    Replies: 2
    Last Post: 2006-07-12, 03:56 PM

Tags for this Thread

Posting Permissions

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