cberg Posted August 2, 2017 Share Posted August 2, 2017 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. Quote Link to comment
Pat Stanford Posted August 2, 2017 Share Posted August 2, 2017 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); 1 Quote Link to comment
Marionette Maven Marissa Farrell Posted August 2, 2017 Marionette Maven Share Posted August 2, 2017 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 1 Quote Link to comment
Pat Stanford Posted August 2, 2017 Share Posted August 2, 2017 Exactly. I try to NEVER provide a script that does irreversible damage to a file. Far better to require an extra key click (Delete) than to programmatically delete more than should be deleted. Nice example of how Marionette can be used on already existing object Marissa. Here is to 2018 ;-) Quote Link to comment
AlanW Posted August 2, 2017 Share Posted August 2, 2017 @Marissa FarrellI see another new node in there that i did not have in your library, the "Select" you must have a treasure trove of goodies hidden away. Quote Link to comment
Marionette Maven Marissa Farrell Posted August 2, 2017 Marionette Maven Share Posted August 2, 2017 1 minute ago, Alan Woodwell said: @Marissa FarrellI see another new node in there that i did not have in your library, the "Select" you must have a treasure trove of goodies hidden away. Haha! I actually wrote that specifically for this. I have a bad habit of not saving my custom nodes. I rewrite them often. Quote Link to comment
AlanW Posted August 2, 2017 Share Posted August 2, 2017 Dont' worry if they are out there i usually keep everyones that i see. Quote Link to comment
cberg Posted August 3, 2017 Author Share Posted August 3, 2017 Thanks so much all for the help. I will check it out, and hopefully it will magically make my file work better. ha! :-) Quote Link to comment
cberg Posted August 9, 2017 Author Share Posted August 9, 2017 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! Quote Link to comment
Marionette Maven Marissa Farrell Posted August 9, 2017 Marionette Maven Share Posted August 9, 2017 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 1 Quote Link to comment
Pat Stanford Posted August 9, 2017 Share Posted August 9, 2017 The easier way to get the script would be to just copy and paste the text into a blank document in the script editor. Importing text scripts is not something I play with often, but I seem to remember some issues on formatting and requiring an extra blank line at the end of the text. Quote Link to comment
MullinRJ Posted August 10, 2017 Share Posted August 10, 2017 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 Quote Link to comment
Pat Stanford Posted August 10, 2017 Share Posted August 10, 2017 Thank you Raymond. 1 Quote Link to comment
cberg Posted August 10, 2017 Author Share Posted August 10, 2017 I probably did something wrong. I am not super experienced with scripts. I do appreciate all the help! Quote Link to comment
Gadzooks Posted August 10, 2017 Share Posted August 10, 2017 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. Quote Link to comment
Poot Posted September 22, 2021 Share Posted September 22, 2021 @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); Quote Link to comment
MullinRJ Posted September 23, 2021 Share Posted September 23, 2021 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 Quote Link to comment
Poot Posted September 23, 2021 Share Posted September 23, 2021 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. Appreciate the time and help 🙂 Quote Link to comment
Pat Stanford Posted September 24, 2021 Share Posted September 24, 2021 The Length and Perimeter functions do not work on 3D polys. At least in worksheets. It will probably take a lot more code to walk each vertex of the 3D poly and calculate the total length and then compare that to the setpoint to determine what to delete/select. Quote Link to comment
MullinRJ Posted September 24, 2021 Share Posted September 24, 2021 @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 2 Quote Link to comment
Poot Posted September 29, 2021 Share Posted September 29, 2021 (edited) @MullinRJ, In my best imitation of Denzel Washington (Frank Lucas)... 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 September 29, 2021 by Poot Quote Link to comment
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.