Hi Bart,
Since the .txt file format is not working as well, please find below the script I trying to use to create assemblies.
Currently I am able to create an assembly, but it comes empty without any child element. This is achieved after I the script throws some error that I am currently investigating.
Additionally, the selected elements are being moved and displaced relative to each other after selection... which is something I don't actually want.
#===================================================================================
from __future__ import annotations
from typing import TYPE_CHECKING
from enum import IntEnum
import NemAll_Python_Utility as AllplanUtil
import NemAll_Python_BaseElements as AllplanBaseElements
import NemAll_Python_Precast as AllplanPrecast
from BaseScriptObject import BaseScriptObject, BaseScriptObjectData
from CreateElementResult import CreateElementResult
from ScriptObjectInteractors.MultiElementSelectInteractor import (
MultiElementSelectInteractor,
MultiElementSelectInteractorResult,
)
from PythonPart import PythonPart, View2D3D
if TYPE_CHECKING:
from __BuildingElementStubFiles.InputInteractorBuildingElement import (
InputInteractorBuildingElement as BuildingElement,
) # type: ignore
else:
from BuildingElement import BuildingElement
def check_allplan_version(_build_ele: BuildingElement,
_version : str) -> bool:
""" Check the current Allplan version
Args:
_build_ele: building element with the parameter properties
_version: the current Allplan version
Returns:
True
"""
# Support all versions
return True
def create_script_object(
build_ele: BuildingElement,
script_object_data: BaseScriptObjectData) -> BaseScriptObject:
return AssemblyGroupScript(build_ele, script_object_data)
class InputStep(IntEnum):
"""Input step for the input sequence"""
Undefined = 0
SelectElements = 1
Done = 2
class AssemblyGroupScript(BaseScriptObject):
def __init__(
self,
build_ele: BuildingElement,
script_object_data: BaseScriptObjectData,
):
super().__init__(script_object_data)
self.build_ele = build_ele
self.multi_select_result = MultiElementSelectInteractorResult()
self.current_input_step = InputStep.Undefined
self.generated_elements: list = []
def start_input(self):
# Prompt user to select elements to group
self.script_object_interactor = MultiElementSelectInteractor(
self.multi_select_result,
prompt_msg="Select elements to group")
self.current_input_step = InputStep.SelectElements
def start_next_input(self):
if self.current_input_step == InputStep.SelectElements:
# End selection
self.script_object_interactor = None
# Collect valid adapters
adapters = self.multi_select_result.sel_elements
print(adapters)
adaptersList = AllplanBaseElements.GetElements(adapters)
print(adaptersList)
valid_adapters = [a for a in adapters if a.IsValid()]
print("Valid adapters", valid_adapters)
if not valid_adapters:
AllplanUtil.ShowMessageBox(
"No valid elements selected.", AllplanUtil.MB_OK
)
# restart selection
self.current_input_step = InputStep.SelectElements
return
asg_element = AllplanPrecast.AssemblyGroupElement()
asg_element.Name = "Assembly_XY"
asg_element.Number = 12
asg_element.ReinforcementList=[]
asg_element.FixtureElementsList=adaptersList
# clear out any existing entries (if needed)
asg_element.LibraryElementsList = []
print("TEST_C")
# keep a reference for execute()
self.assembly_group = asg_element
print("Assembly Elements", asg_element.LibraryElementsList)
attr_list = [
AllplanBaseElements.AttributeString(1444, "ASSEMBLYGROUP"),
AllplanBaseElements.AttributeString(684, "IfcElementAssembly")
]
attr_set_list = [AllplanBaseElements.AttributeSet(attr_list)]
attributes = AllplanBaseElements.Attributes(attr_set_list)
asg_element.SetAttributes(attributes)
AllplanUtil.ShowMessageBox(
"Assembly_AB group created", AllplanUtil.MB_OK)
self.current_input_step = InputStep.Done
return
if self.current_input_step == InputStep.Done:
# end interaction
self.script_object_interactor = None
return
# Default: start selection
self.start_input()
def execute(self) -> CreateElementResult:
views = [View2D3D([])] # Add 3D geometry list if available
common_props = AllplanBaseElements.CommonProperties()
common_props.GetGlobalProperties()
self.assembly_group.SetCommonProperties(common_props)
pp = PythonPart("AssemblyGroup",
parameter_list=self.build_ele.get_params_list(),
hash_value=self.build_ele.get_hash(),
python_file=self.build_ele.pyp_file_name,
views=views,
reinforcement=[],
common_props=common_props,
library_elements=[],
fixture_elements=[],
assembly_elements=[self.assembly_group],
mws_elements=[],
type_display_name="Assembly Group",
type_uuid="3f2504e0-4f89-11d3-9a0c-0305e82c3301",
)
print("Execute was runned")
result_elements = pp.create()
print(f"Created {len(result_elements)} elements.")
return CreateElementResult(elements=result_elements)
#===================================================================================
Cheers,