WireFilter macro new version 0.2023.09.08b

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

WireFilter macro new version 0.2023.09.08b

Post by TheMarkster »

Latest version: 0.2023.09.08b

With the WireFilter macro you can reorder the wires in a sketch using the WireFilter object as a wrapper for the sketch. The sketch is unchanged. The WireFilter object, a feature python object based on Part::Part2DObjectPython, claims the sketch as a child in the tree. Then you use the WireFilter in place of the sketch in some operation, such as in a Part Design Loft.

The object has a number of features:

*Wire reordering
*Offsetting
*Scaling
*Wire filtering (such as removing some wires)
*Displays with a different color for each wire, making it easy to see at a glance which wire is Wire1, Wire2, etc., provided you know the color codes. The first few are easy enough to remember: RGBCMY = Red, Green, Blue, Cyan, Magenta, Yellow for Wire1, Wire2, Wire3, etc., respectively.
*Facemaking with all available FaceMaker classes, selectable via an Enumerator property.

Comparisons between WireFilter and SubShapeBinder. These are different tools, but there is some overlap in their use cases.

SubShapeBinder is integrated in FreeCAD, so if you are sharing files the other user getting the file is sure to have everything needed installed, so in that sense the SubShapeBinder has an advantage. The user can easily install WireFilter macro from Tools menu -> addon manager -> macros -> WireFilter, but it is still an extra step.

Both can do offsetting, so that is a draw.

WireFilter can do scaling, so advantage WireFilter there.

SubShapeBinder can use subshapes from multiple objects. WireFilter can only use selected edges or faces from a single object. Advantage goes to SubShapeBinder there.

Both can make faces, but WireFilter has greater flexibility in making faces. It can use all of the FaceMakers available in FreeCAD. It can also make faces from non-planer wires where SubShapeBinder will fail. Advantage to WireFilter with making faces.

WireFilter can reorder wires where SubShapeBinder cannot. Advantage to WireFilter there.

WireFilter can show wires in different colors. Advantage to WireFilter.

WireFilter can be used directly in Part Design as you would use a sketch, where with a SubShapeBinder you must select the face to use for a pad, for example. With WireFilter you can select the entire object in the tree, leaving you less prone to issues with TNP and also less likely to get cryptic error messages about "No valid subelement linked in Part::Feature". This is because WireFilter is based on Part::Part2DObjectPython and gets treated more like a sketch than does SubShapeBinder. (Workaround for that error: select face in the 3D view.) Advantage to WireFilter for better integration in many cases into Part Design.

WireFilter can reorder wires where SubShapeBinder cannot. This is the main advantage WireFilter has. I've added a new wire order editor to the macro, which makes it much easier now to properly reorder wires. I will demonstrate this next.

In the image below a loft is being attempted using Sketch003 and Sketch004, but unfortunately, the wires were not made in the same sequence when the sketches were made and now the wires are crossing and not at going towards the expected places.
Snip macro screenshot-f2b7c0.png
Snip macro screenshot-f2b7c0.png (51.65 KiB) Viewed 5586 times
Fixing this is very easy with WireFilter. First, we make a WireFilter object based on one of the sketches, in this case Sketch003. Select the sketch in the tree view, and run the macro. A new WireFilter object appears in the tree. Right click on it, and select Edit Wire Orders from the context menu. You will be asked which object to compare the WireFilter object to if there are more than 1 potential compare objects in the document. Here, we choose Sketch004 since that is the object we want to loft with.

Here is a screenshot of the new wire editor task dialog:
Snip macro screenshot-e74042.png
Snip macro screenshot-e74042.png (50.55 KiB) Viewed 5586 times
Notice how the color coding makes it easy to see which wire is which in the 3D view. Red is Wire1, Green is Wire2, and Blue is Wire3. See also in the dialog WF 1 radio button is red, WF 2 is green, and WF 3 is blue. WF 1 = WireFilter Wire1.

There are 3 push buttons in the left column in the dialog. Sketch004 1, Sketch004 2, and Sketch004 3, each button representing a wire in the sketch object we are comparing the WireFilter object to. When you click one of these buttons the associated wire for that object will flash in the 3D view for a second or so. This is to confirm which wire you are working with. If you click "Sketch004 1" button the red rectangle in the sketch flashes black, white, and gray. Those 3 colors represent selection acknowledgement. After flashing it then goes back to the red color we see in the image.

The wire we want to connect that Sketch004 Wire1 wire to is the blue circle in the WireFilter object, so we click the blue radio button labled WF 3 (for WireFilter Wire3). We need to map Wire3 of Sketch003 (the source object for the WireFilter object) to Wire1 of the WireFilter object so that it will connect properly to Wire1 of Sketch003 when we use the Loft operation again. When you click radio button WF 3 the blue circle flashes acknowledgement, and WF 3 radio button becomes the checked button for that row.

Next, we click the 2nd push button, the green one labeled Sketch004 2. This causes the green rectangle in the bottom object in the image to flash. We want that one lofting to the green circle in the other object, which is where it's already pointing, so we go on to the next button.

Next, we click the 3rd push button, the blue one labeled Sketch004 3. This causes the blue circle in the bottom object to flash. We want it to connect to the red circle in the top object, so we click the red radio button on that row, which is labeled WF 1. Then we can click Apply and see the results:
Snip macro screenshot-c2915a.png
Snip macro screenshot-c2915a.png (50.69 KiB) Viewed 5586 times
Notice how the colors are now all matching up the way we want them to. Click OK to close the dialog and do the Loft again.
Snip macro screenshot-4464c7.png
Snip macro screenshot-4464c7.png (45.57 KiB) Viewed 5586 times
Now they're all connected properly.

There is a Toggle Help button in the dialog. If you click it you get some additional help information.

https://wiki.freecad.org/Macro_WireFilter
https://github.com/mwganson/wirefilter
Attachments
loft_test_wires.FCStd
(46.43 KiB) Downloaded 38 times
Last edited by TheMarkster on Sat Sep 09, 2023 1:24 am, edited 2 times in total.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: WireFilter macro (now with colors)

Post by TheMarkster »

Screenshot showing new wire color option:
Snip macro screenshot-16fad6.png
Snip macro screenshot-16fad6.png (79.93 KiB) Viewed 10678 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: WireFilter macro (now with colors)

Post by TheMarkster »

new version: 0.2022.02.09

Now supports making filled face. FaceMaker type is "FilledFace". These faces can be made from nonplanar wires.
Snip macro screenshot-6bafb0.png
Snip macro screenshot-6bafb0.png (16.36 KiB) Viewed 9919 times
Snip macro screenshot-e2dc6b.png
Snip macro screenshot-e2dc6b.png (14.43 KiB) Viewed 9919 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: WireFilter macro new version 0.2023.09.08b

Post by TheMarkster »

Bumping this to the front page. It used to bump automatically when editing the first post title. I guess the forum software has changed.
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: WireFilter macro new version 0.2023.09.08b

Post by Chris_G »

Great. This could be very useful.
Thank you.
In my testing, I was not able to get to get an offset (file below).

I see you use a Bool property as a toggle button.
I have also been in need of such a toggle button property in the past.
Maybe it would make sense to add it directly to the core properties, instead of this hack ?
Attachments
WireFilter_test_CG.FCStd
(9.11 KiB) Downloaded 31 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: WireFilter macro new version 0.2023.09.08b

Post by TheMarkster »

Chris_G wrote: Mon Sep 11, 2023 5:33 pm Great. This could be very useful.
Thank you.
In my testing, I was not able to get to get an offset (file below).

I see you use a Bool property as a toggle button.
I have also been in need of such a toggle button property in the past.
Maybe it would make sense to add it directly to the core properties, instead of this hack ?
Thanks for reporting. It looks I inadvertently deleted the call to the offset method in execute. I'll push the latest update shortly.
Snip macro screenshot-1d9311.png
Snip macro screenshot-1d9311.png (51.09 KiB) Viewed 5391 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: WireFilter macro new version 0.2023.09.08b

Post by TheMarkster »

Newest version: 0.2023.09.11b

It seems I broke existing models with some recent updates. Sorry about that. I added in a couple checks to see if the property exists before trying to access it. If you get errors you can try deleting the WireFilter and making a new one with the latest version.
Post Reply