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:
@@ -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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user