View Full Version : How to check if an "boundary" is closed
stefan_ohrn
2008-07-30, 03:37 PM
Any one who have a clue or even better a lisp-file which checks if a "boundary" with lines and polylines is correct closed .
I want to retain original objects and NOT create new objects.
If its closed then print the area else print error message.
Stefan SWEDEN
alanjt
2008-08-01, 05:32 AM
bpoly, if it's not closed, it will just display an error, if it is closed, it'll just create a pline of the boundary.
irneb
2008-08-01, 02:19 PM
Something like this?;;; Command to get area of closed polyline
(vl-load-com)
(defun c:CPLArea (/ en ed eo)
(while (setq en (entsel "Pick a polyline: "))
(setq ed (entget (car en)))
(if (or
(= "LWPOLYLINE" (cdr (assoc 0 ed)))
(= "POLYLINE" (cdr (assoc 0 ed)))
) ;_ end of or
(if (> (logand (cdr (assoc 70 ed)) 1) 0)
(progn
(setq eo (vlax-ename->vla-object (car en)))
(princ "The polyline's area is ")
(princ (vla-get-Area eo))
(princ "\n")
) ;_ end of progn
(princ "The polyline's not closed ... no area.\n")
) ;_ end of if
(princ "The entity you selected is not a polyline. Please try again\n")
) ;_ end of if
) ;_ end of while
(princ)
) ;_ end of defun
kennet.sjoberg
2008-08-25, 08:37 PM
This simple one do calculate an area inside all kind of legal objects,
BUT it temporary create a region that is removed.
(defun c:ACa ( / PickPoint LastEnt ) ; AreaCalculate
(if (setq PickPoint (getpoint "Pick a point inside the area : " ) )
(progn
(setq LastEnt (entlast))
(command "._-boundary" "A" "O" "R" "" PickPoint "" )
(if (not (eq (entlast) LastEnt ))
(progn
(prompt " temporary, that is removed. " )
(princ (strcat "\nArea = " (rtos (getvar "AREA" )) "" " xxx2" ) )
(command "._erase" (entlast) "" )
)
(princ "No area to calculate. " )
)
)
(princ ". . no point picked. " )
)
(princ)
)
: ) Happy Computing !
kennet
alanjt
2008-08-26, 03:36 AM
here's what i use; i wrote this because i hate how LDD's parcel labeler uses attributed blocks. if the boundary is not closed, nothing happens. it will increment from a starting point (1 if nil, or 1+ the last number used) and it will use allow for a prefix for the lot/parcel, etc. (ie: LOT 1, PARCEL 1, CONSERVATION EASEMENT #5)
below the label, it will place the acreage "2.22 AC.±" and the acerage and square footage will be printed on the command line.
result: LOT 5
2.25 AC.±
created text is middle center justified mtext.
;get area of closed boundary
;will allow user to specify a prefix (ie: Lot, Parcel), starting number (ie: 1, 2) and pick point
;inside a closed boundary (pline not required). it will place a piece of mtext where picked with
;the prefix, number and acerage (ie: Lot 1 - next line - 0.25 Ac.±)
;the user may continue to picked closed areas and the number will increase by one
;CREATED BY: alan thompson 11.28.07
;UPDATED BY: alan thompson 12.19.07 (mtext instead of dtext, lot numbering works better, etc.)
;UPDATED BY: alan thompson 4.22.08 (added ability to enter more than 1 word for prefix)
;UPDATED BY: alan thompson 6.10.08 (rearranged code so dimzin isn't changed unless boundary can be created)
;updated by: alan thompson 6.24.08 (added title, localized variables, changed code to remember last "Number Prefix"
; and "Lot Number" used, if "Number Prefix" is nil, "LOT" is used, if "Lot Number"
; is nil, "1" is used)
(defun c:GA (/ dzin num_prefix ins lot_number ar acre txt)
(if (= *lot_number nil)
(setq *lot_number 1)
);if
(if (= *num_prefix nil)
(setq *num_prefix "LOT")
);if
(setq DZIN (getvar "dimzin"))
(setq num_prefix (getstring T (strcat "\Enter Number Prefix (Lot, Parcel, etc.) <" *num_prefix ">: ")))
(if (= num_prefix "")
(setq num_prefix *num_prefix)
(setq *num_prefix num_prefix)
);if
(setq ins 1)
(setq lot_number (getint (strcat "\Enter First Lot Number <" (rtos *lot_number) ">: ")))
(if (= lot_number nil)
(setq lot_number *lot_number)
(setq *lot_number lot_number)
);if
(while
(if (setq ins (getpoint "\nPick Number Location: "))
(progn
(command "-boundary" ins "")
(command "area" "o" "l")
(command "erase" "l" "")
(setvar 'dimzin 0)
(setq AR (getvar "area"))
(setq ACRE (strcat (rtos (/ (getvar "area") 43560) 2 2) " AC.±"))
(setq txt (strcat num_prefix " " (rtos lot_number 2 0)))
(command "mtext" ins "j" "mc" ins txt ACRE "")
(setq lot_number (1+ lot_number))
(setq *lot_number lot_number)
(setvar 'dimzin DZIN)
(princ (strcat "\n" ACRE " & " (rtos (getvar "area") 2 2) " SQ. FT."))
);progn
);if setq ins
);WHILE
(princ)
);defun
kennet.sjoberg
2008-08-27, 09:32 PM
here's what i use; i wrote this because i . . .
Great,
but if a boundary is not created ( -boundary command fail ) your program still erase last object.
For safety reason, add my security check in previous post to avoid erasing wrong "last" object.
: ) Happy Computing !
kennet
alanjt
2008-08-28, 02:40 AM
Great,
but if a boundary is not created ( -boundary command fail ) your program still erase last object.
For safety reason, add my security check in previous post to avoid erasing wrong "last" object.
: ) Happy Computing !
kennet
never been an issue for me, if the -boundary function fails, the routine exits. i just tested it, just to make sure.
this is picking inside lines that do no close:
Command: ga
Enter Number Prefix (Lot, Parcel, etc.) <LOT>:
Enter First Lot Number <1.0000>:
Pick Number Location:
Valid hatch boundary not found.
Selected object does not have an area
*Invalid selection*
Expects a point or Last
did it actually delete the incorrect last object for you, or are you just saying this from a look at the coding? if this is an issue, i'd like to know so i can remedy the issue.
kennet.sjoberg
2008-08-28, 12:49 PM
never been an issue for me. . .
But objects are deleted . . .
. . . are you just saying this from a look at the coding?
Yes, just looking at the code.
But try this : Open a new drawing and draw one circle
use your code outside the circle ( -boundary command fail ) and your last circle is poofff...
: ) Happy Computing !
kennet
kennet.sjoberg
2008-08-30, 11:51 AM
...oops, when writing direct into the forum it is easy to miss something.
This time I missed the main thing ( marked in red ) try the code again please.
(defun c:ACa ( / PickPoint LastEnt ) ; AreaCalculate
(if (setq PickPoint (getpoint "Pick a point inside the area : " ) )
(progn
(setq LastEnt (entlast))
(command "._-boundary" "A" "O" "R" "" PickPoint "" )
(if (not (eq (entlast) LastEnt ))
(progn
(prompt " temporary, that is removed. " )
(command "._area" "O" (entlast) )
(princ (strcat "\nArea = " (rtos (getvar "AREA" )) "" " xxx2" ) )
(command "._erase" (entlast) "" )
)
(princ "No area to calculate. " )
)
)
(princ ". . no point picked. " )
)
(princ)
)
: ) Happy Computing !
kennet
alanjt
2008-08-30, 04:12 PM
But objects are deleted . . .
Yes, just looking at the code.
But try this : Open a new drawing and draw one circle
use your code outside the circle ( -boundary command fail ) and your last circle is poofff...
: ) Happy Computing !
kennet
holy missed pick batman!
you were completely right. it's odd, when you pick inside a set of lines that are not closed, it will just exit with the error i showed above, i'd never tested it by just picking a point in an open space. i will definitely fix this, hopefully i'll get a chance to do it this weekend. thanks :)
kennet.sjoberg
2008-08-31, 03:24 PM
. . . you were completely right. it's odd, when you pick inside a set of lines that are not closed, it will just exit with the error i showed above. . .
when the boundary command fail, area command fails to
because the area command is still waiting for a legal object
but the code is feeding it with the erase command
and the code error out ( and there is no errorhandler to take care of it )
: ) Happy Computing !
kennet
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.