Jump to content

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


bah026

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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