Support macros and console logs in Assembly

This commit is contained in:
bgbsww
2024-09-19 20:35:46 -04:00
committed by Chris Hennes
parent 3395a8d4a7
commit 48c65aed76
14 changed files with 212 additions and 37 deletions

View File

@@ -1170,3 +1170,34 @@ def getParentPlacementIfNeeded(part):
return linkGroup.Placement
return Base.Placement()
def generatePropertySettings(objectName, documentObject):
commands = []
if hasattr(documentObject, "Name"):
commands.append(f'{objectName} = App.ActiveDocument.getObject("{documentObject.Name}")')
for propertyName in documentObject.PropertiesList:
propertyValue = documentObject.getPropertyByName(propertyName)
propertyType = documentObject.getTypeIdOfProperty(propertyName)
# Note: OpenCascade precision is 1e-07, angular precision is 1e-05. For purposes of creating a Macro,
# we are forcing a reduction in precision so as to get round numbers like 0 instead of tiny near 0 values
if propertyType == "App::PropertyFloat":
commands.append(f"{objectName}.{propertyName} = {propertyValue:.5f}")
elif propertyType == "App::PropertyInt" or propertyType == "App::PropertyBool":
commands.append(f"{objectName}.{propertyName} = {propertyValue}")
elif propertyType == "App::PropertyString" or propertyType == "App::PropertyEnumeration":
commands.append(f'{objectName}.{propertyName} = "{propertyValue}"')
elif propertyType == "App::PropertyPlacement":
commands.append(
f"{objectName}.{propertyName} = App.Placement("
f"App.Vector({propertyValue.Base.x:.5f},{propertyValue.Base.y:.5f},{propertyValue.Base.z:.5f}),"
f"App.Rotation(*{[round(n,5) for n in propertyValue.Rotation.getYawPitchRoll()]}))"
)
elif propertyType == "App::PropertyXLinkSubHidden":
commands.append(
f'{objectName}.{propertyName} = [App.ActiveDocument.getObject("{propertyValue[0].Name}"), {propertyValue[1]}]'
)
else:
# print("Not processing properties of type ", propertyType)
pass
return "\n".join(commands) + "\n"