Fix: Prevent attempting to access non-existent nodes

This is defensive code that protects against attempting to dereference
  nodes that are not present, preventing the python code from throwing an
  AttributeError.
This commit is contained in:
schmidtw
2025-10-12 14:49:28 -07:00
parent 9c1454385e
commit 4b2131f501

View File

@@ -141,6 +141,15 @@ class TaskAssemblyInsertLink(QtCore.QObject):
for insertionItem in self.insertionStack:
object = insertionItem["addedObject"]
translation = insertionItem["translation"]
# Check if object.Name & object.LinkedObject.Name exists
if (
not hasattr(object, "Name")
or not hasattr(object, "LinkedObject")
or not hasattr(object.LinkedObject, "Name")
):
continue
commands = commands + (
f'item = assembly.newObject("App::Link", "{object.Name}")\n'
f'item.LinkedObject = App.ActiveDocument.getObject("{object.LinkedObject.Name}")\n'
@@ -149,7 +158,7 @@ class TaskAssemblyInsertLink(QtCore.QObject):
if translation != App.Vector():
commands = commands + (
f"item.Placement.base = App.Vector({translation.x}."
f"item.Placement.base = App.Vector({translation.x},"
f"{translation.y},"
f"{translation.z})\n"
)