Woodworking - getDimensions

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Woodworking - getDimensions

Post by onekk »

zohozer wrote: Wed Jan 26, 2022 8:48 am

You misunderstood the request. And yes, it is necessary because otherwise you can't determinate the grain direction of the
PART. Nobody asks to add a property for vertexes, lines, etc. but one property/part that indicates the grain direction like described in this pictures. And since other CAD softwares have this feature I think it is useful and practical to have such an information. This information is compliant with the IFC specifications so maybe mr. Yorik can take a look into this?
It will not suffice a simple Annotation.

@Yorik has introduced something similar for Arch WB.

You will Find it in Draft.

Sadly something is not correct with my Linux install about Qt default fonts, so it is not immediate to show the results.

But if I set it "manually" with a Script:

Code: Select all

obj = Part.makeBox(100, 100, 100)
Part.show(obj, "cube")

obj = DOC.findObjects(Label="cube")[0]

colorlist = []
for face in obj.Shape.Faces:
    colorlist.append((0.33, 0.25, 0.10))

fr_fc = obj.Shape.Faces[1]

fc2_cen= fr_fc.CenterOfMass

colorlist[1] = (0.68, 0.95, 0.95)

obj.ViewObject.DiffuseColor = colorlist

o_l = Draft.make_text(["Description", "Grain Direction"], fc2_cen)
o_l.ViewObject.Justification = "Center"
o_l.ViewObject.DisplayMode = u"2D text"
o_l.ViewObject.FontSize = 10

print(fr_fc.tangentAt(0.5,0.5))

symbol = (
    (fc2_cen.x, fc2_cen.y - 20, fc2_cen.z + 10),
    (fc2_cen.x, fc2_cen.y + 20, fc2_cen.z + 10),
    (fc2_cen.x, fc2_cen.y - 20, fc2_cen.z - 10),
    (fc2_cen.x, fc2_cen.y + 20, fc2_cen.z - 10)
)

grain_s = Part.makePolygon(symbol)

Part.show(grain_s, "symbol")

obj_s = DOC.findObjects(Label="symbol")[0]

obj_s.ViewObject.LineColor = (0.95, 0.0, 0.0)


Maybe not the best solution, but it is very near the scope.

Some assumptions could be done using the fr_fc.tangentAt(0.5,0.5) to obtain the face orientation and make the symbol alligned with the face in a more elegant way.

It is all managed by standard constructs, no exotic things.

It simple a "symbol made using lines" line placed at the center of the face, you could obtain the face normal or tangent (I've used simple values, if face is planar there are no problem, if not some math could maybe involved, but I'm not an expert of vector math)
annot_text.png
annot_text.png (5.14 KiB) Viewed 1249 times

EDIT: see https://forum.freecadweb.org/viewtopic. ... 26#p565426, maybe it will lead to something interesting.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Woodworking - getDimensions

Post by heron »

Hello dproyects,
I was drilling holes in tables with woodworking wb tools and noticed something weird.
When using magicDrilles on a face parallel to the YZ plane, for example, Hole PartDesign features are created on the face, so far so good. But then, when making the Holes sketches visible, the circles can be seen to have the wrong orientation.
#
Captura1.PNG
Captura1.PNG (36.44 KiB) Viewed 997 times
#
It doesn't seem to affect the functionality, but it's a bit annoying and it seems to me that it could become future inconveniences so it would be better in its correct orientation.
I was digging into the wb code and found the cause and a simple fix for this bit issue. I sent a PR to woodworking master branch in github, hope it works for you.
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Woodworking - getDimensions

Post by dprojects »

heron wrote: Sun Dec 18, 2022 3:12 pm when making the Holes sketches visible, the circles can be seen to have the wrong orientation.
They have good orientation for the Hole feature, and even for Pocket feature. The Sketches are moved there via global placement for simplification. The sketches could be moved via attachment but it is not needed, and even not desired.

phpBB [video]

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Woodworking - getDimensions

Post by heron »

dprojects wrote: Sun Dec 18, 2022 3:33 pm They have good orientation for the Hole feature, and even for Pocket feature. The Sketches are moved there via global placement for simplification. The sketches could be moved via attachment but it is not needed, and even not desired.
The Placement of the Sketch is ok.
The circle Geom of the Sketch's Shape orientation is wrong.
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Woodworking - getDimensions

Post by dprojects »

heron wrote: Sun Dec 18, 2022 3:55 pm The Placement of the Sketch is ok.
The circle Geom of the Sketch's Shape orientation is wrong.
The Sketch don't have Support set, because this is not needed. It is better to not have Support set at Sketch.
However if you want to fix it, you should rather replace:

Code: Select all

setPlacement(holeSketch, x, y, z, r)
with

Code: Select all

plane = getFacePlane(iFace)

if plane == "XY":
	holeSketch.Support = (body.Origin.OriginFeatures[3])
if plane == "XZ":
	holeSketch.Support = (body.Origin.OriginFeatures[4])
if plane == "YZ":
	holeSketch.Support = (body.Origin.OriginFeatures[5])

setSketchPlacement(holeSketch, x, y, z, r, "attach")
Here is how it works:

Image

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Woodworking - getDimensions

Post by heron »

dprojects wrote: Sun Dec 18, 2022 6:54 pm The Sketch don't have Support set, because this is not needed. It is better to not have Support set at Sketch.
I don't want to have support, I didn't say anything in this regard.
dprojects wrote: Sun Dec 18, 2022 6:54 pm However if you want to fix it, you should rather replace:
In my branch is fixed. There is no problem with Placement or Attachment of the Sketch. The problem is in the Geometry that you pass to the sketch:

Code: Select all

circleGeo = Part.Circle(FreeCAD.Vector(0, 0, 0), axis, o.Radius)
where axis is the direction of drill bit.

Code: Select all

axis = o.Placement.Rotation.Axis
and this doesn't make sense, because the direction of the geometric circle must be equal to the direction of the sketch, which in this case is always (0, 0, 1).

In your animated Gif you make holes in a face parallel to the XY plane, and this problem occurs in the XZ and YZ planes, sorry for not being clear.
In the XY plane, the direction of the geometric circle is the same as the direction of the sketch (0, 0, 1), everything is fine.
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Woodworking - getDimensions

Post by dprojects »

heron wrote: Sun Dec 18, 2022 8:00 pm

Code: Select all

axis = o.Placement.Rotation.Axis
To be honest, I get radius from drill bit so this was probably copied in-the-flow ;-)

heron wrote: Sun Dec 18, 2022 8:00 pm and this doesn't make sense, because the direction of the geometric circle must be equal to the direction of the sketch, which in this case is always (0, 0, 1).
But even if you change it, and you drill pocket holes, or rotate drill bit, the sketch will not be aligned with the hole. The sketch is not needed for hole feature. But what you exactly want to achieve? why you want to have sketch aligned?

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
heron
Posts: 307
Joined: Mon Apr 20, 2020 5:32 pm

Re: Woodworking - getDimensions

Post by heron »

dprojects wrote: Sun Dec 18, 2022 8:59 pm But even if you change it, and you drill pocket holes, or rotate drill bit, the sketch will not be aligned with the hole.
If you change:

Code: Select all

axis = o.Placement.Rotation.Axis
for

Code: Select all

axis = FreeCAD.Vector(0, 0, 1)
(which is the unique change of the PR) then the sketch will be perfectly aligned with the hole in any plane. Did you try it?
I don't know if I'm clear enough, I have a lot of difficulties with English and google translator.
dprojects wrote: Sun Dec 18, 2022 8:59 pm The sketch is not needed for hole feature.
Really? I assume you mean for the woodworker in the real world. Because for the partdesign hole feature in FreeCAD is essential, it depends on the sketch, as far as I know.
dprojects wrote: Sun Dec 18, 2022 8:59 pm But what you exactly want to achieve? why you want to have sketch aligned?
I'm just learning python and github and all this stuff and I took this bug as a challenge to see if I could figure out where it was.
I thought you might like to fix this, but it's your workbench, if you don't mind or just don't accept any PR, in my side there is no problem.
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Woodworking - getDimensions

Post by dprojects »

heron wrote: Mon Dec 19, 2022 8:18 am then the sketch will be perfectly aligned with the hole in any plane. Did you try it?
yes, I tested this, and I can confirm it works for flat plane, but not for pocket holes and rotated drill bits.

heron wrote: Mon Dec 19, 2022 8:18 am Because for the partdesign hole feature in FreeCAD is essential, it depends on the sketch, as far as I know.
No, FreeCAD Hole feature gets only position, circle center point from Sketch, watch the movie I posted several posts above. The Radius is not used by FreeCAD Hole feature. For FreeCAD Pocket yes, but not for Hole. That's the difference.

Personally I don't care about geometry, I usually copy this from macro record, this time I probably copied from drill bit because the drill bit make the hole. I think FreeCAD should add geometry automatically, from Sketch...

However, I understand that in some cases this might be useful to have good aligned Sketch, for example if you would like to create dowels, Pads by reusing the Sketches. So this is why was my question about your goal, purpose. Maybe there is better solution for your needs. Because this fix would not be working if you drill pocket holes, using rotated drill bits. I think there should be attachment + exact rotation...

heron wrote: Mon Dec 19, 2022 8:18 am I thought you might like to fix this
Even small fix or change need to be carefully tested, if you think about stable and reliable software. I am currently trying to adjust workbench to work with containers. I will look into that. But there are more instances like this, for countersinks, for counterbores and maybe other, so all the instances need to be changed and tested, if so.

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
User avatar
dprojects
Posts: 721
Joined: Mon Mar 06, 2017 6:02 pm
Location: Poland
Contact:

Re: Woodworking - getDimensions

Post by dprojects »

I redirect further discussion to this topic, because this issue is not related to getDimensions:
https://forum.freecadweb.org/viewtopic. ... 28#p648528

Note: For getDimensions tool you can use d - report-type but the Sketches should be described manually.... other way to have hole dimensions at the report is to use magicMeasure at holes.

Image

Thanks
Darek
github.com/dprojects

workbench for woodworking is available at: github.com/dprojects/Woodworking
Post Reply