Jump to content
Developer Wiki and Function Reference Links Read more... ×
rosebud5

Script for closing polygons

Recommended Posts

Hi there, I am wishing that there was a script to take 2d polygons that are open and make them closed within a certain tolerance.  I import DWG's a lot and I always have to spend a good deal of time finding tiny little breaks and inconsistencies in order to fill the objects.  Is there any kind of script that would do an auto join if the polyine is a short distance away?

 

Thanks, 

Share this post


Link to post

rosebud5, 

   Here's a no-frills script to CLOSE all Polygons and Polylines on the Active Layer.

 

   This script does not discern if the opening is "a short distance away". It will close ALL Polys. If you need that capability, will you please define how "close" is "close enough to close", or how "open" is "too far to close".

 

PROCEDURE ClosePolys;
{ Close all Polygons and Polylines on Active Layer. }
{ This script: }
{   - will enter Groups on the Active Layer; }
{   - will NOT "show" segments that are "hidden" in the middle of a Polyline; }
{   - does not require objects to be selected, nor will it change the selection state; }
{   - will NOT work on a collection of LINES that "looks" like a Poly. }
{ 26 Sep 2018 - Raymond J Mullin }

{ DISCLAIMER: THIS SCRIPT IS OFFERED AS IS. SAVE YOUR FILE BEFORE USING THIS SCRIPT. }
{ UNDO WILL WORK, BUT ALWAYS BE SAFE. }

	function CloseIt(H :Handle) :Boolean;
	{ Closes Polygons and Polylines. Does not affect Polys that are already CLOSED. }
	Var
		OT :Integer;
	Begin
		OT := GetTypeN(H);			{ object type }
		if (OT=5) | (OT=21) then		{ Polygon or Polyline }
			SetPolyClosed(H, TRUE);		{ close the Poly }
	End;		{ CloseIt }
	
BEGIN
	ForEachObjectInLayer(CloseIt, 0, 1, 0);		{ All objects, Enter Groups, Active Layer }
	SysBeep;
END;
Run(ClosePolys);

Raymond

Share this post


Link to post

Hi Raymond, thanks so much for the speedy reply, I am attaching the file example.  A lot of times I will import a dwg from kholer or some other site and need to fill it and have to spend a lot of time finding the tiny spaces between lines. Some of the shapes I can fill with the paint bucket but others won't fill and I waste a lot of time trying to close everything.  I am including a sample file where the two side shapes are not filling. Maybe I should have said close all lines into a poly.  

 

Thanks, 

close lines sample.vwx

Share this post


Link to post

Hi rosebud5,

   I opened your file and I see your problem. The artwork you are importing was not drawn to be filled. It is line art and close is definitely good enough for the person who created it. You obviously want it to perform better than it was designed. Okay, I can appreciate that.


   When you say you are "wasting a lot of time closing the gaps", are you using the Connect/Combine Tool and/or the Join Tool to remove the gaps, or are you adjusting the Polys, Lines, and Arcs manually? If you are doing the latter, you can save a lot of time by using the right built-in tools. If you're already using those tools, then perhaps a custom script is in order.

 

   Though I haven't written one, perhaps one of the other scripters on this forum already has. I'd wait a little longer to see if someone else responds with a suitable answer. If nobody responds, you might want to pursue having a custom script written for you. Depending on how often you need to perform cleanup on these imported drawings, it might well be worth the investment. It won't be a simple script, so it won't be overly cheap; but if it saves you 10-50 hours (or more) a year it should be reasonably affordable. 

 

For now,

All the best,

Raymond

 

Share this post


Link to post

In this sample file, you're looking to close a gap between an endpoint and a line, which is much harder than closing up end points that are close but not overlapping.  This is particularly complicated if you want to connect arcs and beziers, as you would have to extrapolate the path of every open line, check if it intersects every other line or segment, find the closest intersection, and extend.

 

Using a combination of Select Connected Objects, Compose, Combine/Connect, and the inner/outer boundary modes of the polygon tool can make fairly quick work of this.

Share this post


Link to post

Thanks for the reply, I guess that I am looking for something like the smart paint tool that is in illustrator

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×