Jump to content

Select line by length


Recommended Posts

Is there a way to select lines of a certain length range.  I have an equipment background with tens of thousands of tiny lines, which I would very much like to delete from my file. 

 

For example, one piece of equipment has over 100000 objects..  I've already deleted circles and arcs.  As I don't need that much detail. 

 

Needless to say it is slowing down my files.

 

 

Link to comment

The following script will select all of the lines on the active layer that are shorter than a user entered value. All previously selected objects will be deselected. You can then see in the OIP how many objects are currently selected.

 

Procedure SelectShortLines;
{Selects all lines in the active layer shorter than a user}
{entered length.}

{Augsut 2, 2017}
{© 2017, Pat Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}
{No warranty expressed or implied. Use at your own peril.}
{Abandon hope all ye who enter here. There be dragons.}


Var H1			:Handle;
	OLength		:Real;
	

Procedure DoIt(H2:Handle);

Begin
	If HLength(H2)<=OLength then SetSelect(H2);
End;



Begin
	DSelectAll;
	OLength:=RealDialog('Enter Maximum Line Length. All lines on the active layer shorter or equal to this length will be selected', '1');
	If OLength >0 then
		Begin
			ForEachObject(DoIt,((T=LINE)));
		End
	Else AlrtDialog('Length must be greater than zero');
End;

Run(SelectShortLines);

 

  • Like 1
Link to comment
  • Marionette Maven

In addition to Pat's script, if you wanted to opt for a Marionette solution, the attached file includes a wrapper which accepts user input for the range of length of the lines you want selected (these values can be changed in the OIP).

My default example is lines greater than 1inch to lines less than 5inches. All objects on any layer that can be manipulated will be selected. (If you have Show/Snap/Modify others on, it will select lines on all layers that are not grayed or hidden.)

 

If you were feeling risky, you could swap out the Select node for a Delete node, but I wouldn't advise that unless you were sure you weren't going to delete anything you didn't want to, which is why I assume Pat didn't include deleting in his script, either.

DeleteLinesInLengthRange_MFarrell.vwx

  • Like 1
Link to comment

Hmmm.  I thought I did this right.  Pat I took your code, and copied it to a txt file.  Then I tried to import the script.  However I get an error message. 

 

Marissa, your Marionette node, however, did the trick.  I was able to select lines greater than .001" and less than .5" and then delete them.  Wound deleting tens of thousands of objects without changing the appearance of my equipment plan, reducing the file size from over 130MB to about 30MB. 
Thank you!

Link to comment
  • Marionette Maven
8 minutes ago, cberg said:

Hmmm.  I thought I did this right.  Pat I took your code, and copied it to a txt file.  Then I tried to import the script.  However I get an error message. 

 

Marissa, your Marionette node, however, did the trick.  I was able to select lines greater than .001" and less than .5" and then delete them.  Wound deleting tens of thousands of objects without changing the appearance of my equipment plan, reducing the file size from over 130MB to about 30MB. 
Thank you!

 

Fantastic!

Glad I could help :) 

  • Like 1
Link to comment
6 hours ago, Pat Stanford said:

... but I seem to remember some issues on formatting and requiring an extra blank line at the end of the text.

 

Pat,

   I believe an extra blank line at the end is only needed when you are using $INCLUDE files, and the blank line ensures adjacent files don't create a syntax error when all the text is merged together. 

 

   I pasted your code into a text file with the file terminating right after the last semicolon and it ran perfectly with menu item "Run Script..." and also with the "Text File...  CMD-5" option in the VectorScript Editor. I can only assume @cberg copied a little too much, or little too little. Hard to tell w/o the error message.

 

Raymond

Link to comment

Just wanted to give @PatStanfordand @Marissa Farrella big-up for the above. 

 

Getting your head around drawing with a CAD package can be daunting, but to be able to turn out tricks like that is (certainly for me) magic. 

 

Also shows people like me are only scratching the surface of VectorWorks' capabilities. Man, there's a massive engine under the bonnet (hood) and I'm only using it to pop down the shops...

 

Such a lot to learn....thanks guys.

Link to comment
  • 4 years later...

@Pat Stanford I am wondering how I would modify this script to do the same process of weeding out short 3d polygons? (i.e. from a huge number of 3d contours). Is this possible?

 

On 8/2/2017 at 7:43 PM, Pat Stanford said:

The following script will select all of the lines on the active layer that are shorter than a user entered value. All previously selected objects will be deselected. You can then see in the OIP how many objects are currently selected.

 

Procedure SelectShortLines;
{Selects all lines in the active layer shorter than a user}
{entered length.}

{Augsut 2, 2017}
{© 2017, Pat Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}
{No warranty expressed or implied. Use at your own peril.}
{Abandon hope all ye who enter here. There be dragons.}


Var H1			:Handle;
	OLength		:Real;
	

Procedure DoIt(H2:Handle);

Begin
	If HLength(H2)<=OLength then SetSelect(H2);
End;



Begin
	DSelectAll;
	OLength:=RealDialog('Enter Maximum Line Length. All lines on the active layer shorter or equal to this length will be selected', '1');
	If OLength >0 then
		Begin
			ForEachObject(DoIt,((T=LINE)));
		End
	Else AlrtDialog('Length must be greater than zero');
End;

Run(SelectShortLines);

 

 

Link to comment
20 hours ago, Poot said:

@Pat Stanford I am wondering how I would modify this script to do the same process of weeding out short 3d polygons? (i.e. from a huge number of 3d contours). Is this possible?

 

 

Pat seems to be indisposed at the moment. I modified his script to select 3D Polys instead of Lines. I also assumed you meant 3D Polys with two vertices. This script will not select 3D Polys with three or more vertices. That will take more code. Let me know if I assumed correctly.

 

20 hours ago, Poot said:
Procedure SelectShort3DPolys;
{ Selects all 2-vertex 3D Polygons in the active layer shorter than a user }
{ entered length. }

{Augsut (sic) 2, 2017}
{© 2017, Pat Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}
{No warranty expressed or implied. Use at your own peril.}
{Abandon hope all ye who enter here. There be dragons.}

{ 22 September 2021 - modified to select 2-vertex 3D Polys instead of Lines. - Raymond Mullin }
{ All of Pat's warnings remain in effect. }

Const 
	CR = chr(13);	{ Carriage Return char }

Var H1		:Handle;
	OLength	:Real;
	

Procedure DoIt(H2:Handle);
Var
	P0, P1 :Vector;
Begin
	if (GetVertNum(H2) = 2) then begin
		GetPolyPt3D(H2, 0, P0.x, P0.y, P0.z);
		GetPolyPt3D(H2, 1, P1.x, P1.y, P1.z);
		if (Norm(P1-P0) <= OLength) then SetSelect(H2);
	end;	{ if GetVertNum }
End;	{ DoIt }


Begin
	DSelectAll;
	OLength := RealDialog(concat('Enter Maximum 3D Poly Length.', CR, 
				'All 3D Polys on the active layer shorter or equal to this length will be selected'), '1');
	If (OLength > 0) then
		ForEachObject(DoIt, T=Poly3D)
	Else AlrtDialog('Length must be greater than zero');
End;
Run(SelectShort3DPolys);

HTH,

Raymond

Link to comment
2 hours ago, MullinRJ said:

 

 

Pat seems to be indisposed at the moment. I modified his script to select 3D Polys instead of Lines. I also assumed you meant 3D Polys with two vertices. This script will not select 3D Polys with three or more vertices. That will take more code. Let me know if I assumed correctly.

 

HTH,

Raymond


Hi Raymond, and thanks for the quick reply!


I was indeed thinking of 3d poly's with more than 3 vertices, often coming in situations where we get terrain models/contours that include many (sometimes hundreds) of very small/short 3d poly's. It's not an absolute crisis, but combining a script that removes them with simplification of the poly's makes large models much easier to work with.

image.thumb.png.6cc8fc06975efe31f96349674179f52c.png

 

Appreciate the time and help 🙂

 

 

Link to comment

@Poot,

   In my best imitation of Frank Morgan (Wizard of Oz), "Well, bust my buttons! Why didn't you say that in the first place? That's a horse of a different color!"

 

   With a custom routine, 3D Poly lengths can be measured. Here's a new version.

 

Procedure SelectShort3DPolys;
{ Selects all 2-vertex 3D Polygons in the active layer shorter than a user }
{ entered length. }

{Augsut (sic) 2, 2017}
{© 2017, Pat Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}
{No warranty expressed or implied. Use at your own peril.}
{Abandon hope all ye who enter here. There be dragons.}

{ 22 September 2021 - modified to select 2-vertex 3D Polys instead of Lines. - Raymond Mullin }
{ 23 September 2021 - modified to measure length of multi-vertex 3D Polys. - Raymond Mullin }
{ All of Pat's warnings remain in effect. }

Const 
	CR = chr(13);	{ Carriage Return char }
Var
	H1	:Handle;
	OLength	:Real;


	Function PolyLen3D (H :Handle) :Real;
	Var
		I :Integer;
		L :Real;
		P0, P1 :Vector;
	Begin
		L := 0;
		GetPolyPt3D(H, 0, P0.x, P0.y, P0.z);
		for I := 1 to GetVertNum(H)-1 do begin
			GetPolyPt3D(H, I, P1.x, P1.y, P1.z);
			L := L + Norm(P1-P0);
			P0 := P1;
		end;	{ for }

		if IsPolyClosed(H) then begin
			GetPolyPt3D(H, 0, P1.x, P1.y, P1.z);
			L := L + Norm(P1-P0);
		end;	{ if }

		PolyLen3D := L;
	End;	{ PolyLen3D }


	Procedure DoIt(H2:Handle);
	Begin
		if (PolyLen3D(H2) <= OLength) then SetSelect(H2);
	End;	{ DoIt }


Begin
	DSelectAll;
	OLength := RealDialog(concat('Enter Maximum 3D Poly Length.', CR, 
				'All 3D Polys on the active layer shorter or equal to this length will be selected'), '1');
	if (OLength > 0) then
		ForEachObject(DoIt, T=Poly3D)
	else AlrtDialog('Length must be greater than zero');
End;
Run(SelectShort3DPolys);


HTH,

Raymond

  • Like 2
Link to comment

@MullinRJ, In my best imitation of Denzel Washington (Frank Lucas)...

 

Denzel.gif.dfa532e72b9c37218f4f704d8171b1a4.gif

 

Thank you!!

 

I think that this is useful enough where it would be nice to add in the 'simplify poly' part of the menu, since it is very often you get a lot of small contour 'islands' that bulk up the file.

 

 

Edited by Poot
Link to comment

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