Skip to content

Conversation

chopinregis
Copy link

This pull request adds the Hatch Generator, a new parametric tool for creating complex 2D hatch patterns on Part faces.

Author: @chopinregis
Source Repository: https://github.com/chopinregis/FreeCAD-Parametric-Hatch-Generator

Features:

  • Creates a fully parametric Part::FeaturePython object for hatches.
  • Includes a library of over 100 built-in patterns.
  • Supports custom objects for patterns, multiple base objects, and subtractions.
  • Provides extensive randomization and variation controls.
  • Includes a comprehensive GUI for easy creation and previewing.

Dependencies:

  • An optional dependency on scipy is required to use the "Voronoi" and "VoronoiMesh" patterns. The macro functions without it but will print a warning if a user selects those patterns.

This macro is structured as a multi-file addon with a package.xml for integration with the Addon Manager.

@chennes
Copy link
Member

chennes commented Jul 13, 2025

If you have a package.xml file you don't want to add your macro to this repo, you want to have your own repo that the Addon Manager pulls it in from. Is this work already hosted in a git host someplace?

@chennes
Copy link
Member

chennes commented Jul 13, 2025

See: FreeCAD/FreeCAD-addons#394

Copy link
Collaborator

@galou galou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only requested changes are:

  • put the macro into the ParametricObjectCreation directory
  • remove package.xml

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be ParametricObjectCreation/HatchGenerator.FCMacro.

__Communication__ = 'https://forum.freecad.org/viewtopic.php?p=806176#p806176'
# The __Files__ tag in the main macro is not strictly needed when using package.xml,
# but it's good practice to list dependencies.
__Files__ = 'Freecad_Hatch_Generator.py;HatchGenerator_Icon.svg;package.xml'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__Files__ = 'HatchGenerator.svg,hatch_generator/hatch_generator.py' (adapt if needed).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to hatch_generator/hatch_generator.py.

"""

# The name of the module to import MUST match the library filename.
import Freecad_Hatch_Generator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from hatch_generator.hatch_generator import runHatchGeneratorDialog

runHatchGeneratorDialog()

It imports the main logic from the library file and launches the GUI.
"""

# The name of the module to import MUST match the library filename.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment, this is a general Python knowledge.

return

# 2) Create a brand new parametric object
tempName = "TempHatchParamObj"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not create a temporary document for this (tmp_doc = FreeCAD.newDocument(hidden=True, temp=True) and FreeCAD.closeDocument(tmp_doc.Name))?

tempHatch.BaseObjects = selectedBaseObjs

# Pattern source:
if self.patternSourceCombo.currentIndex() == 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain the magic number 0.

# If "HatchPreview" (or HatchPreview001 etc.) already exist, remove them
preview_existing = [obj for obj in doc.Objects if obj.Name.startswith("HatchPreview")]
idx = 0
while doc.getObject(previewName):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limit idx to avoid an infinite loop.

self.doc.recompute()
FreeCAD.ActiveDocument.commitTransaction()

QtWidgets.QMessageBox.information(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A FreeCAD.Console.PrintMessage should be sufficient on success.

)

except Exception as e:
FreeCAD.ActiveDocument.abortTransaction()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are nested transactions avoided?

@chopinregis
Copy link
Author

If you have a package.xml file you don't want to add your macro to this repo, you want to have your own repo that the Addon Manager pulls it in from. Is this work already hosted in a git host someplace?

Thanks for the comment @chennes but i'm still still new to how github pull requests are made and they are still a bit quite confusing to me to properply understand all and the right order of things.

@chennes
Copy link
Member

chennes commented Jul 28, 2025

Thanks for the comment @chennes but i'm still still new to how github pull requests are made and they are still a bit quite confusing to me to properply understand all and the right order of things.

For including a macro into the FreeCAD macros listing you have three mutually-exclusive options:

  1. Submit the macro and its auxilliary files to this repo (do not include a package.xml file, you can list your aux files in the __Files__ global at the top of your macro (see this example)
  2. Add your macro to the FreeCAD wiki (see this example)
  3. Host the macro in your own git repo, with a package.xml file. See this PR to the FreeCAD-Addons repo that would do that for your macro.

No matter which option you choose, you should first address @galou 's code review comments above.

@chopinregis
Copy link
Author

No matter which option you choose, you should first address @galou 's code review comments above.

Okay thank you, let me review his comments.

@chopinregis
Copy link
Author

chopinregis commented Jul 29, 2025

So @chennes when i see a request change, that's the next step to do? i've seen the comments @galou made, quite pertinent ones indeed and i thank him for that, but i'm not so sure what to do from here, like should i open the code on my personal repo and make his suggested changes from there? or should i make the changes he suggestes on the freecadmacro repo? Snipaste_2025-07-28_20-26-05

@chennes
Copy link
Member

chennes commented Jul 29, 2025

@chopinregis because your PR has not yet been merged, what you should do is continue working on your add-hatch-generator branch. Any change that you push to that branch will be reflected as part of this PR. So if your plan is to continue with Option 1 as I listed them above, that's your process. Just keep editing this branch, committing the changes to your local copy and then pushing to the remote. Let me know if you need the actual git commands for doing those things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants