BLacy Posted May 12, 2010 Posted May 12, 2010 Hello, this is my first post so I am going to make it a biggy. I would like to put a challenge out to all, Here at work we use polylines to define spaces. Each polyine represents a space with a room number which is linked as a block with extended data. Each polyline overlaps an adjacent polyline. Sort of like the rooms in your house each polyline fits together like a puzzle and completing an overall picture. I would like a program to merge two or more polylines into one polyline by removing the overlapping vertices. In its simplest form, picture 2 rectangle poylines that are butting up to one another. You would then have 2 verticies of one polyline that exactly match 2 verticies of the other. I would then like to remove those overlapping verticies and create a new (one larger polyline) with just the outer boundary. I know how to capture the verticie point list of each, and I know how to identify those points that overlap. But I do not know how to capture just the outer vertices and entmake a new poly based on those remaing vertice. I unfortunately had to go a different route by truning them into regions and the using the union command and then turn them back into polyline lines. In theory it works but with irregular shaped polylines it fails. Thank you [font=Times New Roman](Defun C:Merge ()[/font] [font=Times New Roman] (vl-load-com)[/font] [font=Times New Roman] (IF (/= (GETVAR "WORLDUCS") 1)[/font] [font=Times New Roman] (setq ucsvar (getvar "ucsname"))[/font] [font=Times New Roman] )[/font] [font=Times New Roman] (vl-cmdf "DELOBJ" "1") ;If this is zero then the polylines remain if 1 they are removed[/font] [font=Times New Roman] (vl-cmdf "-layer" "s" poly-ten "") ;make polyten current so the polyline is drawn correctly[/font] [font=Times New Roman] (SETQ a (car (entsel "\nSelect First polyline to merge:")))[/font] [font=Times New Roman] (SETQ bptlst nil)[/font] [font=Times New Roman] (vl-cmdf "ucs" "")[/font] [font=Times New Roman] ;(SETQ plst (ENTGET a))[/font] [font=Times New Roman] ;(FOREACH n plst[/font] [font=Times New Roman] ; (IF (= 10 (CAR n))[/font] [font=Times New Roman] ; (SETQ bptlst (CONS (CDR n) bptlst))[/font] [font=Times New Roman] ; )[/font] [font=Times New Roman] [/font] [font=Times New Roman] ;(vl-cmdf "erase" pdim "")[/font] [font=Times New Roman] (vl-cmdf "ucs" "r" ucsvar "")[/font] [font=Times New Roman] (setq b (car (entsel "\nSelect Second polyline to Merge:")))[/font] [font=Times New Roman] ;(SETQ bptlst nil)[/font] [font=Times New Roman] (vl-cmdf "ucs" "")[/font] [font=Times New Roman] ;(SETQ plst (ENTGET b))[/font] [font=Times New Roman] ;(FOREACH n plst[/font] [font=Times New Roman] ; (IF (= 10 (CAR n))[/font] [font=Times New Roman] ; (SETQ bptlst (CONS (CDR n) bptlst))[/font] [font=Times New Roman] ; )[/font] [font=Times New Roman] [/font] [font=Times New Roman] (vl-cmdf "LAYISO" A "") ;This needs to know what layer to isolate so feed it the polyline on poly-ten[/font] [font=Times New Roman] (vl-cmdf "region" a "") ;Turn polyline a into a region[/font] [font=Times New Roman] (setq a1 (ssget "L")) ;now get region a[/font] [font=Times New Roman] (vl-cmdf "region" b "") ;turn polyline b into a region[/font] [font=Times New Roman] (setq b1 (ssget "L")) ;now get region b[/font] [font=Times New Roman] (vl-cmdf "union" a1 b1 "") ;at this point the region is one and the overlap is gone[/font] [font=Times New Roman] (setq ename (entlast)) ;now get the newly defined union[/font] [font=Times New Roman] (setq obj (vlax-ename->vla-object ename))[/font] [font=Times New Roman] ;both of these are still regions[/font] [font=Times New Roman] (setq centroid (vlax-safearray->list[/font] [font=Times New Roman] (vlax-variant-value (vla-get-centroid obj))[/font] [font=Times New Roman] )[/font] [font=Times New Roman] )[/font] [font=Times New Roman] (vl-cmdf "-boundary" centroid "") ;The boundary command asks for an internal point so give it the centroid[/font] [font=Times New Roman] (vl-cmdf "LAYUNISO") ;PUT IT BACK[/font] [font=Times New Roman] (entdel ename) ;erase the region[/font] [font=Times New Roman] (setq plst (entget (ssname (ssget "L") 0)));this is getting the region and not the poly[/font] [font=Times New Roman] (FOREACH n plst[/font] [font=Times New Roman] (IF (= 10 (CAR n))[/font] [font=Times New Roman] (SETQ bptlst (CONS (CDR n) bptlst))[/font] [font=Times New Roman] )[/font] [font=Times New Roman] )[/font] [font=Times New Roman] (setq pdim (ssget "_CP" bptlst '((0 . "text")(8 . "dim"))))[/font] [font=Times New Roman] (setq pdim (ssget "_CP" bptlst '((0 . "text")(8 . "dim")))) ;This gets the dimensions using crossing window unless the dimension is way off[/font] [font=Times New Roman] (vl-cmdf "erase" pdim "")[/font] [font=Times New Roman])[/font] Quote
BLacy Posted May 12, 2010 Author Posted May 12, 2010 Lee, that was on the Express menu right? I think we upgraded and it went away. Quote
BLacy Posted May 12, 2010 Author Posted May 12, 2010 Very nice, that did load the program. I then typed in Overkill. I will see how it does. It was my understanding that Overkill got rid of duplicate entities. I will take a look. Quote
BLacy Posted May 12, 2010 Author Posted May 12, 2010 Okay, I tried Overkill and it was not quite right. It did open a dialog box that I could check off certain aspects to include or exclude and then when I selected the two polylines it would create a partial polyline but it was not complete. I think I will persue a different route by capturing all of the vertices in a list and then create a new list excluding the duplicate vertices and then entmake a new polyline based on the newlist. Thanks again. Quote
Recommended Posts
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.