-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: svg export only works in the XY plane #13652
base: main
Are you sure you want to change the base?
Conversation
The export() method in Mod/Draft/importSVG.py assumes it is looking down from Z onto the XY plane. This works fine to export shapes parallel to that plan. For flat or mostly flat objects that are aligned to the XZ or YZ plane, this exports only a thin line, as it looks sideways on the object. A general solution to this problem would e.g. use the draft WorkingPlane (or the current viewing direction). This PR implements a minimalistic solution that works very well for exporting sketches oriented in one of the main three planes. We simply check which edge of the bounding box is shortest and construct a temporary working plane normal to that direction. My usecase is 2D Designs for plotting or lasercutting. For this, the simple solution is just perfect, as I do not need to bother about the plan that a certain sketch was started at all.
f09e28f
to
43c1aaf
Compare
Your code makes assumptions that need not apply. A sketch can have any rotation, your code only works for sketches aligned with 3 standard planes. |
That is true. I was striving for a simple solution that gets there 99%. In the usecase of "someone draws a sketch to export it as SVG" it is almost always in one of the three orientations. the general usecase of 'any rotation' is more complex.
Before I submit a complex PR involving more advanced logic/heuristics, I'd rather try with a simple one to get some feedback, maybe that is acceptable too. :-) |
I understand what you are saying, but the proposed solution has some obvious limitations. I don't think it is a 99% solution at all. For example a sketch created on the bottom face of a box would result in a mirrored SVG. Which may work if you are cutting (uncoated) sheet metal, but not if you are engraving a name plate. IMO it also makes sense to look at how the C++ DXF exporter handles multiple sketches. I think it just combines them (which does not necessarily make sense BTW). |
There is code in the c++ dxf exporter to get the normal of the sketch and project along that. |
@jnweiger Will you incorporate Wandererfan's suggestion and allow the export to use the sketch normal? Otherwise, this looks good. |
Being able to export the sketches from the 3 base planes instead of 1 is nice but support for an arbitrary sketch location and orientation would be ideal. I assume that's what WandererFan's suggestion would allow? |
One very simple way to solve this issue (for sketches only) is to create a realigned new object for each sketch in a temporary document and export that. This would leave the rest of the original code intact. Other objects would still be processed in the 'old' way. Which matched the C++ DXF solution. It's a bit of a hack perhaps: 😉 tmp = []
hidden_doc = FreeCAD.newDocument(name="hidden", hidden=True, temp=True)
for obj in exportList:
if obj.isDerivedFrom("Sketcher::SketchObject"):
new = hidden_doc.addObject("Part::Part2DObjectPython")
shp = obj.Shape.copy()
shp.transformShape(obj.Placement.inverse().toMatrix())
new.Shape = shp
tmp.append(new)
else:
tmp.append(obj)
exportList = tmp |
The export() method in Mod/Draft/importSVG.py assumes it is looking down from Z onto the XY plane. This works fine to export shapes parallel to that plan.
For flat or mostly flat objects that are aligned to the XZ or YZ plane, this exports only a thin line, as it looks sideways on the object. A general solution to this problem would e.g. use the draft WorkingPlane (or the current viewing direction).
This PR implements a minimalistic solution that works very well for exporting sketches oriented in one of the main three planes. We simply check which edge of the bounding box is shortest and construct a temporary working plane normal to that direction.
My usecase is 2D Designs for plotting or lasercutting. For this, the simple solution is just perfect, as I do not need to bother about the plan that a certain sketch was started at all.