This commit is contained in:
PaddleStroke
2024-11-07 10:01:52 +01:00
committed by Chris Hennes
parent 4f2bd32048
commit 035e863592
3 changed files with 10 additions and 10 deletions

View File

@@ -526,9 +526,9 @@ class TaskAssemblyCreateView(QtCore.QObject):
UtilsAssembly.restoreAssemblyPartsPlacements(self.assembly, self.initialPlcs)
for move in self.viewObj.Moves:
move.Visibility = False
commands = f'obj = App.ActiveDocument.getObject("{self.viewObj.Name}")\n'
commands = ""
for move in self.viewObj.Moves:
more = UtilsAssembly.generatePropertySettings("obj.Moves[0]", move)
more = UtilsAssembly.generatePropertySettings(move)
commands = commands + more
Gui.doCommand(commands[:-1]) # Don't use the last \n
App.closeActiveTransaction()

View File

@@ -1309,7 +1309,7 @@ class TaskAssemblyCreateJoint(QtCore.QObject):
else:
self.joint.Document.removeObject(self.joint.Name)
cmds = UtilsAssembly.generatePropertySettings("obj", self.joint)
cmds = UtilsAssembly.generatePropertySettings(self.joint)
Gui.doCommand(cmds)
App.closeActiveTransaction()

View File

@@ -1237,30 +1237,30 @@ def getParentPlacementIfNeeded(part):
return Base.Placement()
def generatePropertySettings(objectName, documentObject):
def generatePropertySettings(documentObject):
commands = []
if hasattr(documentObject, "Name"):
commands.append(f'{objectName} = App.ActiveDocument.getObject("{documentObject.Name}")')
commands.append(f'obj = 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}")
commands.append(f"obj.{propertyName} = {propertyValue:.5f}")
elif propertyType == "App::PropertyInt" or propertyType == "App::PropertyBool":
commands.append(f"{objectName}.{propertyName} = {propertyValue}")
commands.append(f"obj.{propertyName} = {propertyValue}")
elif propertyType == "App::PropertyString" or propertyType == "App::PropertyEnumeration":
commands.append(f'{objectName}.{propertyName} = "{propertyValue}"')
commands.append(f'obj.{propertyName} = "{propertyValue}"')
elif propertyType == "App::PropertyPlacement":
commands.append(
f"{objectName}.{propertyName} = App.Placement("
f"obj.{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]}]'
f'obj.{propertyName} = [App.ActiveDocument.getObject("{propertyValue[0].Name}"), {propertyValue[1]}]'
)
else:
# print("Not processing properties of type ", propertyType)