[ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by Roy_043 »

The py files use different EOL (end of line) characters. I have updated the ZIP file in my previous post.
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by paullee »

Thanks :)
eigenwertnotfound
Posts: 14
Joined: Fri Dec 30, 2022 6:11 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by eigenwertnotfound »

Roy_043 wrote: Tue Jan 03, 2023 10:34 am Attached is a ZIP with a modified ArchWall.py file and a FCStd test file. The original ArchWall.py is included in the Org folder. The modified code works on the 4 Xed rectangles (Sketch, Binder, Shape2DView and Link). But if you edit the Sketch and change the arc to normal geometry the results are less satisfactory. :mrgreen:
How would I use the modified ArchWall.py in Freecad or replace the default one with it? Simply adding it as a macro and executing doesn't seem to do anything.
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by Roy_043 »

Backup: <installation_folder>/Mod/Arch/ArchWall.py and copy the new file in its place.
eigenwertnotfound
Posts: 14
Joined: Fri Dec 30, 2022 6:11 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by eigenwertnotfound »

please tell me if this is off topic, but I found this might be useful for anybody using the realthunder branch. When trying to use the modified python script I got following error:

Code: Select all

  File "/Users/username/Applications/FreeCAD.app/Contents/Mod/Arch/ArchWall.py", line 1451, in getExtrusionData
    face = DraftGeomUtils.bind(w1, w2, per_segment=True)
<class 'TypeError'>: bind() got an unexpected keyword argument 'per_segment'
07:20:01  9.7e-08 <App> ArchWall.py(341)|Document.cpp(4327): Failed to recompute type1_schablone#Wall: bind() got an unexpected keyword argument 'per_segment'
07:20:01  Recompute failed! Please check report view.
Checking Draft/draftgeoutils/faces.py the bind() function in the latest realthunder release does indeed not contain a per_segment argument. Using the faces.py from the latest official branch fixes the issue, archwalls.py now works as expected.

Huge thanks to Roy for the modified script :)
Attachments
Screenshot 2023-01-06 at 07.41.03.png
Screenshot 2023-01-06 at 07.41.03.png (146.9 KiB) Viewed 927 times
eigenwertnotfound
Posts: 14
Joined: Fri Dec 30, 2022 6:11 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by eigenwertnotfound »

although interestingly on this example the original archwall.py produces a better result.
original:
Screenshot 2023-01-06 at 08.09.00.png
Screenshot 2023-01-06 at 08.09.00.png (74.93 KiB) Viewed 892 times
Roy's version:
Screenshot 2023-01-06 at 08.06.36.png
Screenshot 2023-01-06 at 08.06.36.png (222.69 KiB) Viewed 892 times
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by paullee »

Thanks @eigenwertnotfound for testing, can share the model file ?
eigenwertnotfound
Posts: 14
Joined: Fri Dec 30, 2022 6:11 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by eigenwertnotfound »

Hi paullee, archwall_gridtest is the sketch I originally broke it with. I tried to provide a minimal example where it breaks and now the crossed box which worked for me originally doesn't work either (although it breaks in a different way than the original python script). Very confused right now...
Attachments
archwall_gridtest1.FCStd
(35.59 KiB) Downloaded 20 times
archwall_gridtest.FCStd
(29.77 KiB) Downloaded 19 times
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.__sortEdges__(), again

Post by paullee »

Interesting grid test. Need to avoid multiple edges with ends coincidence - though it may be natural to layout like this.

May have an idea how to tackle this.

Test result on my FC 0.21.0.31391, AppImage on Fedora 36

Screenshot from 2023-01-06 22-50-15.png
Screenshot from 2023-01-06 22-50-15.png (221.34 KiB) Viewed 793 times
Screenshot from 2023-01-06 22-51-08.png
Screenshot from 2023-01-06 22-51-08.png (188.34 KiB) Viewed 793 times
Screenshot from 2023-01-06 22-51-47.png
Screenshot from 2023-01-06 22-51-47.png (207.74 KiB) Viewed 793 times



Code: Select all

OS: Fedora Linux 36 (Workstation Edition) (GNOME/gnome)
Word size of FreeCAD: 64-bit
Version: 0.21.0.31391 (Git)
Build type: Release
Branch: master
Hash: 0ab2608a429f3a5ee9a63da9b66d13557655d7e4
Python 3.10.8, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods: 
  * dodo 1.0.0
  * DynamicData 2.46.0
  * ArchTextures
  * BOLTSFC.backup1666323893.5041647
  * BOLTSFC
  * FreeCAD-BlenderBIM.backup1666328110.015535
  * FreeCAD-BlenderBIM.backup1666737837.420096
  * FreeCAD-BlenderBIM 2022.10.20
  * BIM.backup1670731522.690569
  * BIM 2021.12.0
  * 3rd link to Paul
  * 3rd link to SketchArchPlus
paullee
Veteran
Posts: 5097
Joined: Wed May 04, 2016 3:58 pm

Re: [ ArchWall ] - Part.getSortedCluster, Part.sortEdges(), again

Post by paullee »

OK, tests to see different in behaviour in sorting edges in Sketch by :
  1. Part.getSortedCluster()
  2. Part.sortEdges() (Not Part.__sortEdges__(), which return only 1st edge)
Model file (attached, 1st screencapture)

Test 1 : Used Part.getSortedCluster()
  1. Steps - Run below codes after file opened
  2. Result - 2 shapes created (1st 5 edges with the diagonal one ('self-intersecting'), 2nd with the opposite diagonal edge)
    ( 2nd screencapture )
Test 2 : Used Part.Part.sortEdges()
  1. Steps - Codes remark out line 14, un-remark line 15; run revised codes after file opened
  2. Result - 3 shapes created ( 1st 4 edges, 2nd with the diagonal one, 3rd with the opposite diagonal edge)
    ( 3rd screencapture )
@chrisb @abdullah Any comments on the original intention of the methods, and the test results? Thanks :)

Code: Select all

obj = FreeCAD.ActiveDocument.getObject('Sketch')
skGeom = obj.GeometryFacadeList
skGeomEdges = []
skPlacement = obj.Placement  # Get Sketch's placement to restore later
basewires = []

for i in skGeom:
   if not i.Construction:
      # support Line, Arc, Circle for Sketch as Base at the moment
      if isinstance(i.Geometry, (Part.LineSegment, Part.Circle, Part.ArcOfCircle)):
         skGeomEdgesI = i.Geometry.toShape()
         skGeomEdges.append(skGeomEdgesI)

for cluster in Part.getSortedClusters(skGeomEdges):
#for cluster in Part.sortEdges(skGeomEdges):
   clusterTransformed = []
   for edge in cluster:
      edge.Placement = edge.Placement.multiply(skPlacement)  ## TODO add attribute to skip Transform...
      clusterTransformed.append(edge)
   # Only use cluster of edges rather than turning into wire
   basewires.append(clusterTransformed)

c = [App.Placement(App.Vector(6000.0,2000.0,0.0),App.Rotation(App.Vector(0.0,0.0,1.0),0.0)),  App.Placement(App.Vector(6000.0,-2000.0,0.0),App.Rotation(App.Vector(0.0,0.0,1.0),0.0)) ,  App.Placement(App.Vector(12000.0,0000.0,0.0),App.Rotation(App.Vector(0.0,0.0,1.0),0.0)) ]

print(basewires)
len(basewires)
for i in range(len(basewires)):
    w=Part.Wire(basewires[i])
    w.Placement = c[i]
    Part.show(w)
Test_ ArchWall_ 01_ r5.FCStd
(15.07 KiB) Downloaded 17 times
Screenshot from 2023-01-07 00-42-40.png
Screenshot from 2023-01-07 00-42-40.png (145.71 KiB) Viewed 746 times
Screenshot from 2023-01-07 00-41-36.png
Screenshot from 2023-01-07 00-41-36.png (145.01 KiB) Viewed 746 times
Screenshot from 2023-01-07 00-45-11.png
Screenshot from 2023-01-07 00-45-11.png (142.61 KiB) Viewed 746 times
Post Reply