1818from .cq import Workplane
1919from .occ_impl .shapes import Shape , Compound
2020from .occ_impl .geom import Location
21- from .occ_impl .assembly import Color
21+ from .occ_impl .assembly import Color , Material , AssemblyElement
2222from .occ_impl .solver import (
2323 ConstraintKind ,
2424 ConstraintSolver ,
@@ -85,6 +85,7 @@ class Assembly(object):
8585 loc : Location
8686 name : str
8787 color : Optional [Color ]
88+ material : Optional [Material ]
8889 metadata : Dict [str , Any ]
8990
9091 obj : AssemblyObjects
@@ -107,6 +108,7 @@ def __init__(
107108 loc : Optional [Location ] = None ,
108109 name : Optional [str ] = None ,
109110 color : Optional [Color ] = None ,
111+ material : Optional [Material ] = None ,
110112 metadata : Optional [Dict [str , Any ]] = None ,
111113 ):
112114 """
@@ -116,6 +118,7 @@ def __init__(
116118 :param loc: location of the root object (default: None, interpreted as identity transformation)
117119 :param name: unique name of the root object (default: None, resulting in an UUID being generated)
118120 :param color: color of the added object (default: None)
121+ :param material: material of the added object (default: None)
119122 :param metadata: a store for user-defined metadata (default: None)
120123 :return: An Assembly object.
121124
@@ -135,6 +138,7 @@ def __init__(
135138 self .loc = loc if loc else Location ()
136139 self .name = name if name else str (uuid ())
137140 self .color = color if color else None
141+ self .material = material if material else None
138142 self .metadata = metadata if metadata else {}
139143 self .parent = None
140144
@@ -153,7 +157,9 @@ def _copy(self) -> "Assembly":
153157 Make a deep copy of an assembly
154158 """
155159
156- rv = self .__class__ (self .obj , self .loc , self .name , self .color , self .metadata )
160+ rv = self .__class__ (
161+ self .obj , self .loc , self .name , self .color , self .material , self .metadata
162+ )
157163
158164 for ch in self .children :
159165 ch_copy = ch ._copy ()
@@ -172,6 +178,7 @@ def add(
172178 loc : Optional [Location ] = None ,
173179 name : Optional [str ] = None ,
174180 color : Optional [Color ] = None ,
181+ material : Optional [Material ] = None ,
175182 ) -> "Assembly" :
176183 """
177184 Add a subassembly to the current assembly.
@@ -183,6 +190,8 @@ def add(
183190 the subassembly being used)
184191 :param color: color of the added object (default: None, resulting in the color stored in the
185192 subassembly being used)
193+ :param material: material of the added object (default: None, resulting in the material stored in the
194+ subassembly being used)
186195 """
187196 ...
188197
@@ -193,6 +202,7 @@ def add(
193202 loc : Optional [Location ] = None ,
194203 name : Optional [str ] = None ,
195204 color : Optional [Color ] = None ,
205+ material : Optional [Material ] = None ,
196206 metadata : Optional [Dict [str , Any ]] = None ,
197207 ) -> "Assembly" :
198208 """
@@ -204,6 +214,7 @@ def add(
204214 :param name: unique name of the root object (default: None, resulting in an UUID being
205215 generated)
206216 :param color: color of the added object (default: None)
217+ :param material: material of the added object (default: None)
207218 :param metadata: a store for user-defined metadata (default: None)
208219 """
209220 ...
@@ -225,6 +236,9 @@ def add(self, arg, **kwargs):
225236 subassy .loc = kwargs ["loc" ] if kwargs .get ("loc" ) else arg .loc
226237 subassy .name = kwargs ["name" ] if kwargs .get ("name" ) else arg .name
227238 subassy .color = kwargs ["color" ] if kwargs .get ("color" ) else arg .color
239+ subassy .material = (
240+ kwargs ["material" ] if kwargs .get ("material" ) else arg .material
241+ )
228242 subassy .metadata = (
229243 kwargs ["metadata" ] if kwargs .get ("metadata" ) else arg .metadata
230244 )
@@ -658,22 +672,31 @@ def __iter__(
658672 loc : Optional [Location ] = None ,
659673 name : Optional [str ] = None ,
660674 color : Optional [Color ] = None ,
661- ) -> Iterator [Tuple [Shape , str , Location , Optional [Color ]]]:
675+ material : Optional [Material ] = None ,
676+ ) -> Iterator [AssemblyElement ]:
662677 """
663- Assembly iterator yielding shapes, names, locations and colors .
678+ Assembly iterator yielding shapes, names, locations, colors and materials .
664679 """
665680
666681 name = f"{ name } /{ self .name } " if name else self .name
667682 loc = loc * self .loc if loc else self .loc
668683 color = self .color if self .color else color
684+ material = self .material if self .material else material
669685
670686 if self .obj :
671- yield self .obj if isinstance (self .obj , Shape ) else Compound .makeCompound (
672- s for s in self .obj .vals () if isinstance (s , Shape )
673- ), name , loc , color
687+ shape = (
688+ self .obj
689+ if isinstance (self .obj , Shape )
690+ else Compound .makeCompound (
691+ s for s in self .obj .vals () if isinstance (s , Shape )
692+ )
693+ )
694+ yield AssemblyElement (
695+ shape = shape , name = name , location = loc , color = color , material = material
696+ )
674697
675698 for ch in self .children :
676- yield from ch .__iter__ (loc , name , color )
699+ yield from ch .__iter__ (loc , name , color , material )
677700
678701 def toCompound (self ) -> Compound :
679702 """
0 commit comments