Skip to content

Instantly share code, notes, and snippets.

@sandorex
Last active March 28, 2025 16:38
Show Gist options
  • Save sandorex/bc2fe949b68d47a67fc6dd300467b1a8 to your computer and use it in GitHub Desktop.
Save sandorex/bc2fe949b68d47a67fc6dd300467b1a8 to your computer and use it in GitHub Desktop.
FreeCAD relabeler macro
## AUTO RELABELER (EXPERIMENTAL)
# https://gist.github.com/sandorex/bc2fe949b68d47a67fc6dd300467b1a8
# VERSION 0.1
import FreeCAD, Draft
import PySide import QtGui
from pathlib import Path
# save backup
document = App.activeDocument()
document.saveCopy(Path(document.FileName).stem + "-relabeler-backup.FCStd")
parents = FreeCAD.ActiveDocument.Objects
# rename some types for nicer names
TYPEID_NAME = {
"Sketcher::SketchObject": "Sketch",
}
def get_type_name(obj):
return TYPEID_NAME.get(obj.TypeId, type(obj).__name__)
# these types will be ignored and not renamed
TYPE_BLACKLIST = []
for parent in parents:
# ignore some types
if parent.TypeId in TYPE_BLACKLIST:
continue
# rename origin axis and planes
try:
parent.Origin.Label = parent.Label + "Origin"
for child in parent.Origin.OriginFeatures:
child.Label = parent.Label + child.Role
except AttributeError:
pass
try:
for child in parent.Group:
# ignore some types
if child.TypeId in TYPE_BLACKLIST:
continue
child.Label = parent.Label + get_type_name(child)
except AttributeError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment