Jump to content
bah026

Search for code that generate close polyline from a list of lines

Recommended Posts

bah026

Hello,

 

I need to generate a close polylines from the end/beginning points of a line , which mean, after I'm having all lines in the drawing I need to run some loop that find the vertex of those lines and to generate a poly from those vertexes, The vertex point I already able to find by autolist code, so I only need to generate the polyline.

in the attached files I have example of the beforeDocument2.pdf and after that result I need to get

Share this post


Link to post
Share on other sites
ronjonp
Posted (edited)

Look into the boundary command.

example.dwg

Edited by ronjonp
  • Like 1

Share this post


Link to post
Share on other sites
BIGAL
Posted (edited)

Bpoly with OOPS no need for code. Look at cyan line.

 

image.thumb.png.0e4a2092fe8d86a7aeb199f47390ff29.png

Edited by BIGAL

Share this post


Link to post
Share on other sites
bah026

Thanks for the answers, The Bpoly don't do it's work, even a simples lines, it couldn't recognize the 4  closed poly, only the 2 outers (yellow and green)

Annotation 2020-06-28 124923.jpg

Annotation 2020-06-28 124923.jpg

Share this post


Link to post
Share on other sites
bah026

The option of using enclosed_polyline.lsp is not working either, it's don't create a closed poly, worst result then bpoly, it even didin't recognized the yellow poly

Share this post


Link to post
Share on other sites
Stefan BMR
4 hours ago, bah026 said:

The option of using enclosed_polyline.lsp is not working either, it's don't create a closed poly, worst result then bpoly, it even didin't recognized the yellow poly

 

Enclosed_polylines is about finding EACH closed area in a selection. If it's not what you are looking for, then you should explain better.

I'd really like to see each of the 2 samples you already posted, but with both "before" and "after" situation.

And, most important, how do you see them the same? For me, looks like 2 different tasks.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites
BIGAL

Agree with Stefan your 1st example was random lines not overlapping objects.

 

If I remember correct there is an answer using region for simple overlapping objects. This is not a new request and has been solved previously its a case of finding that solution.

 

Google is your friend.

 

A quick and dirty, draw say a circle or pline around outside of objects, then BOUNDARY with island detect on Pline option, pick point inside circle see image two plines are made. Very limited testing.

 

image.png.501b042b4fc263e2294338140b457155.png

 

Share this post


Link to post
Share on other sites
bah026

Hi Stefan, see attached drawing befor and after runnung the enclosed_polyline.lsp  

Maybe I didin't express myself, but I'm looking to get all the closed polylines contain the vertex point of the lines, in this example

 

Drawing11.dwg Drawing11-after.dwg

Share this post


Link to post
Share on other sites
Stefan BMR

Isn't PEDIT good for this?

 

Sorry, I fail to understand. Maybe somebody else will do. Good luck!!

 

Share this post


Link to post
Share on other sites
Roy_043
On 6/28/2020 at 12:03 PM, bah026 said:

Thanks for the answers, The Bpoly don't do it's work, even a simples lines, it couldn't recognize the 4  closed poly, only the 2 outers (yellow and green)

Annotation 2020-06-28 124923.jpg

Annotation 2020-06-28 124923.jpg

I would say that 6 different polylines can be derived from those lines.

Share this post


Link to post
Share on other sites
marko_ribar
Posted (edited)

I counted 8 different polylines...

;)

Edited by marko_ribar

Share this post


Link to post
Share on other sites
BIGAL
Posted (edited)

Very confusing what is required ?

 

DWG 11

erase the two lines inside box

PE Y join pick all lines top right 

oops put 2 lines back

now = what was posted DWG 11 after

NO CODE. Just like my 1st post.

Edited by BIGAL

Share this post


Link to post
Share on other sites
bah026

Bigal, It's just an example I need to run a script on complicated drawing with thousands of lines.

Share this post


Link to post
Share on other sites
BIGAL

Post a simple real example dwg with before and after very obvious. Then we will have a better idea of what you want.

Share this post


Link to post
Share on other sites
bah026

Bigal, It's just an example I need to run a script on complicated drawing with thousands of lines.

See attached example the "before" is an example drawing with 17 lines

The "after" is a drawing contains 7 polylines (with small space between them and with colors so you'll be able to see them all) that created manually, but in order to work on a large drawing I need to have some script that scans all the lines, find the vertex of the lines  and generate all the polylines from the created vertex, I hope I explain myself clear

example-after.dwg example-before.dwg

Share this post


Link to post
Share on other sites
eldon

I am not sure whether the goal posts are shifting.

 

With your first example, I used PEDIT with the multiple option and formed two separate polylines.

 

With your second example, the boundary command would do what you want.

 

So now you want a magician to write an omnipotent app to do what you want in different situations!!

Share this post


Link to post
Share on other sites
bah026

So using PEDIT wan't give you all the polylines that I have in "example-after"

Share this post


Link to post
Share on other sites
eldon

I got one polyline using all the lines in the second example.

Share this post


Link to post
Share on other sites
marko_ribar

Use REGION command and select all lines... Then use this routine on selection of all regions previously created :

 

(defun c:regs2lws ( / pea ss i reg n k m p z f )

  (vl-load-com)

  (setq pea (getvar 'peditaccept))
  (setvar 'peditaccept 1)
  (prompt "\nSelect REGIONS convertable to lwpolylines (lines+arcs) to convert them to LWPOLYLINES...")
  (while (null (setq ss (ssget "_:L" '((0 . "REGION")))))
    (prompt "\nEmpty sel. set... Try selecting again...")
  )
  (setq k 0 m 0 sss (ssadd))
  (repeat (setq i (sslength ss))
    (setq reg (ssname ss (setq i (1- i))))
    (setq n (vlax-safearray->list (vlax-variant-value (vla-get-normal (vlax-ename->vla-object reg)))))
    (vl-cmdf "_.UCS" "_W")
    (vl-cmdf "_.EXPLODE" reg)
    (while (< 0 (getvar 'cmdactive)) (vl-cmdf ""))
    (if (vl-every '(lambda ( x ) (or (eq (cdr (assoc 0 (entget x))) "LINE") (eq (cdr (assoc 0 (entget x))) "ARC")))
          (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget "_P"))))
        )
        (progn
          (setq m (1+ m) z t)
          (setq p (vlax-curve-getstartpoint (entlast)))
          (vl-cmdf "_.UCS" "_M" p)
          (vl-cmdf "_.UCS" "_ZA" "" n)
          (vl-cmdf "_.PEDIT" "_M" (ssget "_P") "" "_J")
          (while (> (getvar 'cmdactive) 0) (vl-cmdf ""))
          (ssadd (entlast) sss)
          (vl-cmdf "_.UCS" "_P")
          (vl-cmdf "_.UCS" "_P")
        )
        (progn
          (setq k (1+ k) f t)
          (vl-cmdf "_.UNDO" "1")
        )
    )
    (vl-cmdf "_.UCS" "_P")
  )
  (if z (progn (prompt "\nThere were : ") (princ m) (prompt " REGIONS - that were converted to LWPOLYLINES")))
  (if f (progn (prompt "\nThere were : ") (princ k) (prompt " REGIONS - that were impossible to be converted to LWPOLYLINES")))
  (if z
    (progn
      (prompt "\nSelection set is stored in variable : \"sss\"...")
      (sssetfirst nil sss)
    )
  )
  (setvar 'peditaccept pea)
  (princ)
)

Regards, M.R.

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...