Author Topic: -={ Challenge }=- Enclose lines  (Read 5728 times)

0 Members and 1 Guest are viewing this topic.

zak26

  • Newt
  • Posts: 33
-={ Challenge }=- Enclose lines
« on: June 29, 2023, 11:54:00 AM »
Hi everyone I want to propose a new challenge, although I'm not sure if it is up to your capabilities because I have seen so many excellent and great programers here and probably this is a very small task for you guys. but here it is, I want you to create a closed polyline that contains all the lines or polylines selected kind of create a boundary.

As you may know I already have my own program that solves the task, and I'll show it later on, so hope you enjoy your small challenge.

I leave a dwg file to make your own trials, here is also a gif that shows how I do it, most surely you can do it much better.

ScottMC

  • Newt
  • Posts: 191
Re: -={ Challenge }=- Enclose lines
« Reply #1 on: June 29, 2023, 12:31:27 PM »
Could see that as useful with exploded hatches..

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: -={ Challenge }=- Enclose lines
« Reply #2 on: June 29, 2023, 01:26:05 PM »
« Last Edit: November 14, 2023, 06:25:57 AM by Lee Mac »

zak26

  • Newt
  • Posts: 33
Re: -={ Challenge }=- Enclose lines
« Reply #3 on: June 29, 2023, 01:32:27 PM »
Like this? :-)
Just like that, let's hope there are more people interested. I knew it could be a simple task for you. Lee

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: -={ Challenge }=- Enclose lines
« Reply #4 on: June 30, 2023, 09:47:17 AM »
here's mine, i used python though

zak26

  • Newt
  • Posts: 33
Re: -={ Challenge }=- Enclose lines
« Reply #5 on: June 30, 2023, 10:30:30 AM »
here's mine, i used python though
Looks good, two more and I'll show my cards

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: -={ Challenge }=- Enclose lines
« Reply #6 on: June 30, 2023, 03:18:49 PM »
I got a working concept too.

EDIT: I only mocked up with lines though (I'd have to modify to get plines working).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

zak26

  • Newt
  • Posts: 33
Re: -={ Challenge }=- Enclose lines
« Reply #7 on: June 30, 2023, 03:58:25 PM »
I got a working concept too.

EDIT: I only mocked up with lines though (I'd have to modify to get plines working).
That's great John, glad you joined the Challenge, I hope at the end we can all show our way to solve it.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: -={ Challenge }=- Enclose lines
« Reply #8 on: June 30, 2023, 04:30:42 PM »
My version

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: -={ Challenge }=- Enclose lines
« Reply #9 on: June 30, 2023, 04:31:21 PM »
It was fun to play with here-and-there all day.

I hacked up a quick fix for dealing with plines so I should be ready for posting my crude solution.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

zak26

  • Newt
  • Posts: 33
Re: -={ Challenge }=- Enclose lines
« Reply #10 on: June 30, 2023, 04:44:22 PM »
My version
Good, 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.

zak26

  • Newt
  • Posts: 33
Re: -={ Challenge }=- Enclose lines
« Reply #11 on: June 30, 2023, 04:53:45 PM »
Well as promised here is my version, sometimes to find a solution we stand on the shoulders of gigants to solve our tasks, without this key masterpiece of Lee Mac, I couldn't have done it. (Or maybe yes in time a year or so.). Thanks again for participating in this small Challenge, Thanks Lee for sharing your codes with us. And everyone else here, I have learned a lot from this forums.
Code: [Select]
;;; 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)
)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: -={ Challenge }=- Enclose lines
« Reply #12 on: June 30, 2023, 05:16:38 PM »
i used a hull, so it's wrong
« Last Edit: June 30, 2023, 05:28:48 PM by El Jefe »

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: -={ Challenge }=- Enclose lines
« Reply #13 on: June 30, 2023, 05:23:29 PM »
probably this is a very small task for you guys
on the contrary
it is a very complicated task

zak26

  • Newt
  • Posts: 33
Re: -={ Challenge }=- Enclose lines
« Reply #14 on: June 30, 2023, 05:39:36 PM »
i used a hull, so it's wrong
I 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.