Like this? :-)Just like that, let's hope there are more people interested. I knew it could be a simple task for you. Lee
here's mine, i used python thoughLooks good, two more and I'll show my cards
I got a working concept too.That's great John, glad you joined the Challenge, I hope at the end we can all show our way to solve it.
EDIT: I only mocked up with lines though (I'd have to modify to get plines working).
My versionGood, looks like a fast one, and much better than mine, i couldn't get to do it in more than one group at a time.
;;; enl-enclose lines
;;; By Isaac A.
;;; Program to enclose lines with a polyline
(defun c:enl ( / lst oe oo ss )
(vl-load-com)
(setq oe (getvar 'cmdecho)
oo (getvar 'osmode))
(setvar 'cmdecho 0)
(setvar 'osmode 37)
(vl-cmdf "_.undo" "_begin")
(princ "\nSelect the lines to enclose: ")
(if (setq ss (ssget (list '(0 . "*LINE") )))
(progn
(foreach pline (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
(setq lst (cons (vlax-curve-getStartPoint (vlax-ename->vla-object pline)) lst))
(setq lst (cons (vlax-curve-getEndPoint (vlax-ename->vla-object pline)) lst))
)
(mkPoly lst)
)
)
(setvar 'cmdecho oe)
(setvar 'osmode oo)
(vl-cmdf "_.undo" "_end")
(princ)
)
;;; Original By Lee Mac modified by Isaac
;;; http://www.theswamp.org/index.php?topic=30434.0
;;; Makes a polyline touching all the points in a list
(defun mkPoly (lst / qsort rslt x)
(defun qsort (pt lst)
(vl-sort lst
(function (lambda (a b) (< (distance pt a) (distance pt b))))))
(setq rslt (list (car lst)))
(while (setq x (car (setq lst (qsort (car rslt) (cdr lst)))))
(setq rslt (cons x rslt))
)
(entmakex (append (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(67 . 0)
'(410 . "Model")
'(8 . "Test")
'(62 . 3)
'(100 . "AcDbPolyline")
(cons 90 (length rslt))
'(70 . 1)
)
(mapcar (function (lambda (a) (cons 10 a))) rslt)
)
)
(princ)
)
probably this is a very small task for you guyson the contrary
i used a hull, so it's wrongI don't see why is wrong, you got to the result at the end, and I'd like to know how to use python with autocad, sounds interesting.
i used a hull, so it's wrongI don't see why is wrong, you got to the result at the end, and I'd like to know how to use python with autocad, sounds interesting.
on the contraryI wouldn't think of you saying that, you have created a great program that I haven't seen replicated (IRT), And I'd like to ask you how to work with kml files, but that will be on other ocassion.
it is a very complicated task
Certainly a helpful tool zak26 and Lee Mac!Didn't know about this one, I used CAB's psimple, which is a good one too.
Exciting thing for those tough situations.
Gotta look at this pgm.
Gile put one out that would help simplify..
https://www.theswamp.org/index.php?topic=19865.msg244892#msg244892
probably this is a very small task for you guyson the contrary
it is a very complicated task
probably this is a very small task for you guyson the contrary
it is a very complicated task
wait what!? ...well, I defiantly messed up then (watch, mine probably only works on Tuesdays I bet---every other day it makes toast).
Command: (PLINE-ENCLOSURE)
Select objects: Specify opposite corner: 62 found
Select objects:
; error: too few arguments
enl doesn't like this caseI haven't even thought of that case, thanks that'll be something to fix.
I wouldn't think of you saying that
I haven't even thought of that casenow we are talking :)
wait what!? ...well, I defiantly messed up then (watch, mine probably only works on Tuesdays I bet---every other day it makes toast).this is the first time i see a program that needs a full week to be tested :)
;; NOTE: I did not implement a sort for these points so if the
;; (poly)lines are not processed "in order" this will
;; draw a wobbly outline.
Good enough for the sample dwg, hehe
Command: OUTLINE
Select objects: Specify opposite corner: 61 found
Select objects:
; error: no function definition: REMOVE
Good enough for the sample dwg, hehe
are you sure? :laugh:QuoteCommand: OUTLINE
Select objects: Specify opposite corner: 61 found
Select objects:
; error: no function definition: REMOVE
this is the first time i see a program that needs a full week to be tested :)
as for Saturdays - not working
Saturday here
Okay I fixed my code above (I had a paren misplaced). ...Hopefully I got it fixed so it could be tested on Saturday/Sunday. :)of course i fixed the misplaced paren myself before testing
enl doesn't like this caseThis didn't happened on my side, could you send me your test file to test it further?
Okay I fixed my code above (I had a paren misplaced). ...Hopefully I got it fixed so it could be tested on Saturday/Sunday. :)of course i fixed the misplaced paren myself before testing
https://imgur.com/a/0xKVC0z
But what happens if you have the items preselected before the program is called (I imagine it wouldn’t make any difference at all)?it does not make any difference
Still having this kind of problem, making it recursive did fix the mayor problems but this is still remaining on this kind of shapes (on the dwg)
Still having this kind of problem, making it recursive did fix the mayor problems but this is still remaining on this kind of shapes (on the dwg)Assuming the lines were drawn in order works well in this case.
...
the first problem is: "what is the problem?"
is this maybe ?
"given a set of lines in the XY plane,
however oriented and of any length,
determine the smallest polygon
containing them"
I think the original intent was for the lines to be parallel, or with some relaxed toleranceNot quite, What about this?
;;
;; Entity to Point List - Lee Mac
;; Returns a list of WCS points describing or approximating the supplied entity, else nil if the entity is not supported.
;; ent - [ent] Entity name to be described by point list (POINT/LINE/ARC/CIRCLE/LWPOLYLINE/POLYLINE/ELLIPSE/SPLINE)
;; acc - [num] Positive number determining the point density for non-linear objects
(defun LM:ent->pts ( ent acc / ang bul cen cls di1 di2 enx inc itm lst num ocs rad tot typ vt1 vt2 vtl )
(setq enx (entget ent)
typ (cdr (assoc 0 enx))
acc 4.0 ;; number mods circ,arc point amt
)
(cond
( (= "POINT" typ)
(list (cdr (assoc 10 enx)))
)
( (= "LINE" typ)
(mapcar '(lambda ( x ) (cdr (assoc x enx))) '(10 11))
)
( (or (= "ARC" typ) (= "CIRCLE" typ))
(if (= "ARC" typ)
(setq ang (cdr (assoc 50 enx))
tot (rem (+ pi pi (- (cdr (assoc 51 enx)) ang)) (+ pi pi))
num (fix (+ 1.0 1e-8 (* acc (/ tot (+ pi pi)))))
inc (/ tot (float num))
num (1+ num)
)
(setq ang 0.0
tot (+ pi pi)
num (fix (+ 1e-8 acc))
inc (/ tot (float num))
)
)
(setq cen (cdr (assoc 010 enx))
rad (cdr (assoc 040 enx))
ocs (cdr (assoc 210 enx))
)
(repeat num
(setq lst (cons (trans (polar cen ang rad) ocs 0) lst)
ang (+ ang inc)
)
)
(reverse lst)
)
( (or (= "LWPOLYLINE" typ)
(and (= "POLYLINE" typ) (zerop (logand (logior 16 64) (cdr (assoc 70 enx)))))
)
(if (= "LWPOLYLINE" typ)
(setq vtl (LM:ent->pts:lwpolyvertices enx))
(setq vtl (LM:ent->pts:polyvertices ent))
)
(if (setq ocs (cdr (assoc 210 enx))
cls (= 1 (logand 1 (cdr (assoc 70 enx))))
)
(setq vtl (append vtl (list (cons (caar vtl) 0.0))))
)
(while (setq itm (car vtl))
(setq vtl (cdr vtl)
vt1 (car itm)
bul (cdr itm)
lst (cons (trans vt1 ocs 0) lst)
)
(if (and (not (equal 0.0 bul 1e-8)) (setq vt2 (caar vtl)))
(progn
(setq rad (/ (* (distance vt1 vt2) (1+ (* bul bul))) 4.0 bul)
cen (polar vt1 (+ (angle vt1 vt2) (- (/ pi 2.0) (* 2.0 (atan bul)))) rad)
rad (abs rad)
tot (* 4.0 (atan bul))
num (fix (+ 1.0 1e-8 (* acc (/ (abs tot) (+ pi pi)))))
inc (/ tot (float num))
ang (+ (angle cen vt1) inc)
)
(repeat (1- num)
(setq lst (cons (trans (polar cen ang rad) ocs 0) lst)
ang (+ ang inc)
)
)
)
)
)
(reverse (if cls (cdr lst) lst))
)
( (= "ELLIPSE" typ)
(setq di1 (vlax-curve-getdistatparam ent (vlax-curve-getstartparam ent))
di2 (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent))
di2 (- di2 1e-8)
)
(while (< di1 di2)
(setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
rad (distance '(0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1)))
di1 (+ di1 (/ di2 (1+ (fix (* acc (/ di2 rad (+ pi pi)))))))
)
)
(reverse (if (vlax-curve-isclosed ent) lst (cons (vlax-curve-getendpoint ent) lst)))
)
)
)
(defun LM:ent->pts:lwpolyvertices ( enx / elv lst vtx )
(setq elv (list (cdr (assoc 38 enx))))
(while (setq vtx (assoc 10 enx))
(setq enx (cdr (member vtx enx))
lst (cons (cons (append (cdr vtx) elv) (cdr (assoc 42 enx))) lst)
)
)
(reverse lst)
)
(defun LM:ent->pts:polyvertices ( ent / lst vte vtx )
(setq vte (entnext ent)
vtx (entget vte)
)
(while (= "VERTEX" (cdr (assoc 0 vtx)))
(setq lst (cons (cons (cdr (assoc 10 vtx)) (cdr (assoc 42 vtx))) lst)
vte (entnext vte)
vtx (entget vte)
)
)
(reverse lst)
)
;;// -----------------------------------------------------------------------------------------------------------
(defun os3 ( / dist ename vobj )
(setq dist 0.0000001) ;; puts point close enough to vertex
;(setq ent (car (entsel ent))) ;; "\nSelect object to offset: ")
(setq vobj (vlax-ename->vla-object ent))
(if (vlax-method-applicable-p vobj 'Offset)
(progn
(vlax-invoke vobj 'Offset dist) ; INSIDE
;; (vlax-invoke vobj 'Offset (- dist))
)
(princ "\nCannot offset selected object type ")
)
(princ)
) ;end
;;// -----------------------------------------------------------------------------------------------------------
(defun c:p/ ( / *error* ss ent entx dvn ) ;; ent dvn
(princ " Places Points On Ends/Arcs/Quads <undo or oops to un-erase..>");; and Makes Block < *SELECT* >
(setvar 'cmdecho 0)
(setq tot 0)
(defun *error* ( msg )
(vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
(if qaf (setvar 'qaflags qaf))
(if msg (prompt msg))
(setvar 'cmdecho 1) ;; (getvar 'cmdecho)
; (setvar "nomutt" 0) ;; <--works to restore var on pre-finish esc/error..
(princ)
)
(while
(setq ss (ssget ":S" '((0 . "LINE,ARC,CIRCLE,SPLINE,LWPOLYLINE"))));;filter selection
(setq ent (ssname ss 0));;grab ename
(setq dvn 4.0) ;; default
(os3) ;; offset dist: -l 136
(setq ent (entlast))
(setq entx ent) ;; make selset with.. to erase
(command)
(foreach pnt (LM:ent->pts ent dvn) ;; 12.0 prefered
(setq ent (entmake (list '(0 . "POINT") (cons 10 pnt))))
)
(setq tot (1+ tot))
(vl-cmdf "erase" entx "")
(princ (strcat " Total: " (rtos tot)))
) ;; end of while loop -l 152
(setvar 'cmdecho 1)
;(princ "\n 'O2B' to Make Block<..anonymous>")
(princ)
)
(vl-load-com) (princ)
just needs get the points 'end' coords of all the entities
and then use "" Gile's or Lee.Mac's "" tools!
It's just putting those two together..
... it looks like you want to reconstruct the outline of an exploded hatchThe problem started just by joining the endpoints, didn't know where they came from, probably from an exploded hatch, that looks like.
"given a set of lines in the XY plane,
however oriented and of any length,
determine the smallest polygon
containing them"
What the? ...I'm out. This "challenge" can't make up its mind.It's your right to do so, thanks for your participation
This whole thread seems like it's morphing into a fishing expedition.What for?, I think there's no need for those kind of things.
and the polygon could also be concaveyep :)
it is a very complicated task
and the polygon could also be concaveyep :)
they can have a C-shape or S-shape or even an O-shapeit is a very complicated task
the first problem is: "what is the problem?"
is this maybe ?
"given a set of lines in the XY plane,
however oriented and of any length,
determine the smallest polygon
containing them"
It is worth noting that, for an arbitrary point list, the problem becomes this -You're right for arbritrary or Lbracket-Rbracket-shapes, the code I posted initially works pretty well and this includes a modified version of your solution on the link, but it just doesn't solve well the problem I had on just parallel lines, probably the other solutions posted by domenicomania or El Jefe or kasmo work much better
https://www.theswamp.org/index.php?topic=30434.0
it is a very complicated taskIt seem that you were right Vovka, because there is no code that can take into account all the possible cases.
. . . so any boundary created from the 'lines' will not replicate the original boundary.You're right the 'boundary' will follow up to the extents of the limits the lines had, so most of the time will be chamfered
Is the original surrounding geometry still available in the drawing ?No, as in the problem I had when I had to solve it (like in january of this year) there is no known boundary, just supposed. I created new ones and deleted them just for the examples. but they're all irregular shapes anyone can create.