mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 01:11:40 +00:00
You can now specify a name when adding materials
This commit is contained in:
@@ -118,10 +118,18 @@ class AddMaterial(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_label = "Add Material"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
obj: bpy.props.StringProperty()
|
||||
name: bpy.props.StringProperty(default="Default")
|
||||
|
||||
def invoke(self, context, event):
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def draw(self, context):
|
||||
row = self.layout
|
||||
row.prop(self, "name", text="Name")
|
||||
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.materials.get(self.obj) if self.obj else None
|
||||
core.add_material(tool.Ifc, tool.Material, tool.Style, obj=obj)
|
||||
core.add_material(tool.Ifc, tool.Material, tool.Style, obj=obj, name=self.name)
|
||||
material_prop_purge()
|
||||
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ def unlink_material(ifc, obj=None):
|
||||
ifc.unlink(obj=obj)
|
||||
|
||||
|
||||
def add_material(ifc, material, style, obj=None):
|
||||
def add_material(ifc, material, style, obj=None, name=None):
|
||||
if not obj:
|
||||
obj = material.add_default_material_object()
|
||||
obj = material.add_default_material_object(name)
|
||||
ifc_material = ifc.run("material.add_material", name=material.get_name(obj))
|
||||
ifc.link(ifc_material, obj)
|
||||
ifc_style = style.get_style(obj)
|
||||
|
||||
@@ -446,7 +446,7 @@ class Loader:
|
||||
|
||||
@interface
|
||||
class Material:
|
||||
def add_default_material_object(cls): pass
|
||||
def add_default_material_object(cls, name): pass
|
||||
def add_material_to_set(cls, material_set, material): pass
|
||||
def delete_object(cls, obj): pass
|
||||
def disable_editing_material(cls): pass
|
||||
|
||||
@@ -27,8 +27,8 @@ import ifcopenshell.util.element
|
||||
|
||||
class Material(blenderbim.core.tool.Material):
|
||||
@classmethod
|
||||
def add_default_material_object(cls):
|
||||
return bpy.data.materials.new("Default")
|
||||
def add_default_material_object(cls, name):
|
||||
return bpy.data.materials.new(name or "Default")
|
||||
|
||||
@classmethod
|
||||
def delete_object(cls, obj):
|
||||
|
||||
@@ -28,13 +28,13 @@ class TestUnlinkMaterial:
|
||||
|
||||
class TestAddMaterial:
|
||||
def test_add_a_default_material(self, ifc, material, style):
|
||||
material.add_default_material_object().should_be_called().will_return("obj")
|
||||
material.add_default_material_object("name").should_be_called().will_return("obj")
|
||||
material.get_name("obj").should_be_called().will_return("name")
|
||||
ifc.run("material.add_material", name="name").should_be_called().will_return("material")
|
||||
ifc.link("material", "obj").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return(None)
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
assert subject.add_material(ifc, material, style) == "material"
|
||||
assert subject.add_material(ifc, material, style, name="name") == "material"
|
||||
|
||||
def test_add_a_material_to_a_blender_material_object(self, ifc, material, style):
|
||||
material.get_name("obj").should_be_called().will_return("name")
|
||||
|
||||
@@ -31,10 +31,15 @@ class TestImplementsTool(NewFile):
|
||||
|
||||
class TestAddDefaultMaterialObject(NewFile):
|
||||
def test_run(self):
|
||||
material = subject.add_default_material_object()
|
||||
material = subject.add_default_material_object(None)
|
||||
assert isinstance(material, bpy.types.Material)
|
||||
assert material.name == "Default"
|
||||
|
||||
def test_specify_a_name(self):
|
||||
material = subject.add_default_material_object("Material")
|
||||
assert isinstance(material, bpy.types.Material)
|
||||
assert material.name == "Material"
|
||||
|
||||
|
||||
class TestDeleteObject(NewFile):
|
||||
def test_run(self):
|
||||
|
||||
Reference in New Issue
Block a user