69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
import importlib
|
|
import json
|
|
|
|
import FreeCAD as App
|
|
|
|
|
|
def property_metadata(obj):
|
|
properties = []
|
|
for name in obj.PropertiesList:
|
|
try:
|
|
type_id = obj.getTypeIdOfProperty(name)
|
|
except Exception:
|
|
type_id = "unknown"
|
|
try:
|
|
group = obj.getGroupOfProperty(name)
|
|
except Exception:
|
|
group = ""
|
|
try:
|
|
status = list(obj.getPropertyStatus(name))
|
|
except Exception:
|
|
status = []
|
|
properties.append({"name": name, "typeId": type_id, "group": group, "status": status})
|
|
return properties
|
|
|
|
|
|
def probe_object(document, type_id):
|
|
try:
|
|
obj = document.addObject(type_id, "Reference" + type_id.replace(":", "_"))
|
|
except Exception as error:
|
|
return {"typeId": type_id, "available": False, "error": str(error)}
|
|
return {
|
|
"typeId": type_id,
|
|
"available": True,
|
|
"runtimeTypeId": obj.TypeId,
|
|
"properties": property_metadata(obj),
|
|
}
|
|
|
|
|
|
def probe_module(name):
|
|
try:
|
|
module = importlib.import_module(name)
|
|
return {"name": name, "available": True, "file": getattr(module, "__file__", None)}
|
|
except Exception as error:
|
|
return {"name": name, "available": False, "error": str(error)}
|
|
|
|
|
|
document = App.newDocument("ReferenceProbe")
|
|
version = App.Version()
|
|
result = {
|
|
"schemaVersion": 1,
|
|
"baselineId": "freecad-1.1.1",
|
|
"freecadVersion": ".".join(str(value) for value in version[:3]),
|
|
"revision": str(version[3]),
|
|
"gitBranch": str(version[6]) if len(version) > 6 else "",
|
|
"gitCommit": str(version[7]) if len(version) > 7 else "",
|
|
"guiUp": bool(getattr(App, "GuiUp", False)),
|
|
"buildPurpose": "headless-reference-oracle",
|
|
"modules": [probe_module(name) for name in [
|
|
"Part", "Material", "Measure", "Sketcher", "PartDesign", "TechDraw",
|
|
"Spreadsheet", "Draft", "Mesh", "Fem", "CAM", "Assembly",
|
|
]],
|
|
"objects": [probe_object(document, type_id) for type_id in [
|
|
"Part::Box", "Part::Cylinder", "Part::Sphere", "Part::Cone",
|
|
"Part::Feature", "PartDesign::Feature", "Sketcher::SketchObject",
|
|
]],
|
|
}
|
|
App.closeDocument(document.Name)
|
|
print("FREECAD_REFERENCE_RESULT=" + json.dumps(result, sort_keys=True, separators=(",", ":")))
|