diff options
author | Spivak Vladimir (cwolf3d) <cwolf3d@gmail.com> | 2019-08-15 03:03:26 +0300 |
---|---|---|
committer | Spivak Vladimir (cwolf3d) <cwolf3d@gmail.com> | 2019-08-15 03:04:01 +0300 |
commit | af291e44f861f2adc6fbbcff038e7dcb94862a10 (patch) | |
tree | 6990f7f7fb5e0405dfb567a9a0167aed8fa640c5 /add_mesh_extra_objects | |
parent | c047f6460486566bc6019bae86648ab0d064ffaf (diff) |
Addon: Mesh Extra Objects: Gears, Wallfactory, Beam, Pipe: Implemented add object in edit mode
Diffstat (limited to 'add_mesh_extra_objects')
-rw-r--r-- | add_mesh_extra_objects/Wallfactory.py | 52 | ||||
-rw-r--r-- | add_mesh_extra_objects/__init__.py | 36 | ||||
-rw-r--r-- | add_mesh_extra_objects/add_mesh_beam_builder.py | 19 | ||||
-rw-r--r-- | add_mesh_extra_objects/add_mesh_gears.py | 150 | ||||
-rw-r--r-- | add_mesh_extra_objects/add_mesh_pipe_joint.py | 333 |
5 files changed, 495 insertions, 95 deletions
diff --git a/add_mesh_extra_objects/Wallfactory.py b/add_mesh_extra_objects/Wallfactory.py index db7918c3..66926214 100644 --- a/add_mesh_extra_objects/Wallfactory.py +++ b/add_mesh_extra_objects/Wallfactory.py @@ -872,26 +872,40 @@ class add_mesh_wallb(Operator): stepBack ) - if self.change == True and self.change != None: - obj = context.active_object - oldmesh = obj.data - oldmeshname = obj.data.name - mesh = bpy.data.meshes.new("Wall") - mesh.from_pydata(verts_array, [], faces_array) - obj.data = mesh - bpy.data.meshes.remove(oldmesh) - obj.data.name = oldmeshname - else: - mesh = bpy.data.meshes.new("Wall") + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + oldmesh = obj.data + oldmeshname = obj.data.name + mesh = bpy.data.meshes.new("Wall") + mesh.from_pydata(verts_array, [], faces_array) + obj.data = mesh + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh = bpy.data.meshes.new("Wall") + mesh.from_pydata(verts_array, [], faces_array) + obj = object_utils.object_data_add(context, mesh, operator=None) + + mesh.update() + + obj.data["Wall"] = True + obj.data["change"] = False + for prm in WallParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') + mesh = bpy.data.meshes.new("TMP") mesh.from_pydata(verts_array, [], faces_array) obj = object_utils.object_data_add(context, mesh, operator=None) - - mesh.update() - - obj.data["Wall"] = True - obj.data["change"] = False - for prm in WallParameters(): - obj.data[prm] = getattr(self, prm) + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} @@ -965,4 +979,4 @@ def WallParameters(): "StepOnly", "StepBack", ] - return WallParameters
\ No newline at end of file + return WallParameters diff --git a/add_mesh_extra_objects/__init__.py b/add_mesh_extra_objects/__init__.py index 560305be..f785c663 100644 --- a/add_mesh_extra_objects/__init__.py +++ b/add_mesh_extra_objects/__init__.py @@ -86,7 +86,6 @@ else: import bpy from bpy.types import Menu -from sys import * class VIEW3D_MT_mesh_vert_add(Menu): # Define the "Single Vert" menu @@ -289,6 +288,41 @@ def Extras_contex_menu(self, context): setattr(props, prm, obj.data[prm]) layout.separator() + if 'ElbowJoint' in obj.data.keys(): + props = layout.operator("mesh.primitive_elbow_joint_add", text="Change ElbowJoint") + props.change = True + for prm in add_mesh_pipe_joint.ElbowJointParameters(): + setattr(props, prm, obj.data[prm]) + layout.separator() + + if 'TeeJoint' in obj.data.keys(): + props = layout.operator("mesh.primitive_tee_joint_add", text="Change TeeJoint") + props.change = True + for prm in add_mesh_pipe_joint.TeeJointParameters(): + setattr(props, prm, obj.data[prm]) + layout.separator() + + if 'WyeJoint' in obj.data.keys(): + props = layout.operator("mesh.primitive_wye_joint_add", text="Change WyeJoint") + props.change = True + for prm in add_mesh_pipe_joint.WyeJointParameters(): + setattr(props, prm, obj.data[prm]) + layout.separator() + + if 'CrossJoint' in obj.data.keys(): + props = layout.operator("mesh.primitive_cross_joint_add", text="Change CrossJoint") + props.change = True + for prm in add_mesh_pipe_joint.CrossJointParameters(): + setattr(props, prm, obj.data[prm]) + layout.separator() + + if 'NJoint' in obj.data.keys(): + props = layout.operator("mesh.primitive_n_joint_add", text="Change NJoint") + props.change = True + for prm in add_mesh_pipe_joint.NJointParameters(): + setattr(props, prm, obj.data[prm]) + layout.separator() + # Register classes = [ VIEW3D_MT_mesh_vert_add, diff --git a/add_mesh_extra_objects/add_mesh_beam_builder.py b/add_mesh_extra_objects/add_mesh_beam_builder.py index 9aa89ef1..623fc0ca 100644 --- a/add_mesh_extra_objects/add_mesh_beam_builder.py +++ b/add_mesh_extra_objects/add_mesh_beam_builder.py @@ -790,9 +790,20 @@ class addBeam(Operator): obj.data[prm] = getattr(self, prm) return {'FINISHED'} - - self.report({'WARNING'}, "Option only valid in Object mode") - return {'CANCELLED'} + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') + mesh = addBeamMesh(self, context) + obj = object_utils.object_data_add(context, mesh, operator=None) + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') + + return {'FINISHED'} def BeamParameters(): BeamParameters = [ @@ -803,4 +814,4 @@ def BeamParameters(): "edgeA", "Cursor", ] - return BeamParameters
\ No newline at end of file + return BeamParameters diff --git a/add_mesh_extra_objects/add_mesh_gears.py b/add_mesh_extra_objects/add_mesh_gears.py index 35ec12bd..0ccc265d 100644 --- a/add_mesh_extra_objects/add_mesh_gears.py +++ b/add_mesh_extra_objects/add_mesh_gears.py @@ -19,7 +19,6 @@ from mathutils import ( Matrix, ) from bpy_extras import object_utils -from sys import * # A very simple "bridge" tool. # Connects two equally long vertex rows with faces. @@ -671,38 +670,58 @@ class AddGear(Operator): def execute(self, context): - if self.change == True and self.change != None: - obj = context.active_object - if 'Gear' in obj.data.keys(): - oldmesh = obj.data - oldmeshname = obj.data.name - mesh, verts_tip, verts_valley = AddGearMesh(self, context) - obj.data = mesh - try: - bpy.ops.object.vertex_group_remove(all=True) - except: - pass - bpy.data.meshes.remove(oldmesh) - obj.data.name = oldmeshname + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + if 'Gear' in obj.data.keys(): + oldmesh = obj.data + oldmeshname = obj.data.name + mesh, verts_tip, verts_valley = AddGearMesh(self, context) + obj.data = mesh + try: + bpy.ops.object.vertex_group_remove(all=True) + except: + pass + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh, verts_tip, verts_valley = AddGearMesh(self, context) + obj = object_utils.object_data_add(context, mesh, operator=None) else: mesh, verts_tip, verts_valley = AddGearMesh(self, context) obj = object_utils.object_data_add(context, mesh, operator=None) - else: + + # Create vertex groups from stored vertices. + tipGroup = obj.vertex_groups.new(name='Tips') + tipGroup.add(verts_tip, 1.0, 'ADD') + + valleyGroup = obj.vertex_groups.new(name='Valleys') + valleyGroup.add(verts_valley, 1.0, 'ADD') + + obj.data["Gear"] = True + obj.data["change"] = False + for prm in GearParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') mesh, verts_tip, verts_valley = AddGearMesh(self, context) obj = object_utils.object_data_add(context, mesh, operator=None) - - # Create vertex groups from stored vertices. - tipGroup = obj.vertex_groups.new(name='Tips') - tipGroup.add(verts_tip, 1.0, 'ADD') - - valleyGroup = obj.vertex_groups.new(name='Valleys') - valleyGroup.add(verts_valley, 1.0, 'ADD') - - obj.data["Gear"] = True - obj.data["change"] = False - for prm in GearParameters(): - obj.data[prm] = getattr(self, prm) - + + # Create vertex groups from stored vertices. + tipGroup = obj.vertex_groups.new(name='Tips') + tipGroup.add(verts_tip, 1.0, 'ADD') + + valleyGroup = obj.vertex_groups.new(name='Valleys') + valleyGroup.add(verts_valley, 1.0, 'ADD') + + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} def GearParameters(): @@ -848,37 +867,58 @@ class AddWormGear(Operator): def execute(self, context): - if self.change == True and self.change != None: - obj = context.active_object - if 'WormGear' in obj.data.keys(): - oldmesh = obj.data - oldmeshname = obj.data.name - mesh, verts_tip, verts_valley = AddWormGearMesh(self, context) - obj.data = mesh - try: - bpy.ops.object.vertex_group_remove(all=True) - except: - pass - bpy.data.meshes.remove(oldmesh) - obj.data.name = oldmeshname + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + if 'WormGear' in obj.data.keys(): + oldmesh = obj.data + oldmeshname = obj.data.name + mesh, verts_tip, verts_valley = AddWormGearMesh(self, context) + obj.data = mesh + try: + bpy.ops.object.vertex_group_remove(all=True) + except: + pass + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh, verts_tip, verts_valley = AddWormGearMesh(self, context) + obj = object_utils.object_data_add(context, mesh, operator=None) else: mesh, verts_tip, verts_valley = AddWormGearMesh(self, context) obj = object_utils.object_data_add(context, mesh, operator=None) - else: + + # Create vertex groups from stored vertices. + tipGroup = obj.vertex_groups.new(name = 'Tips') + tipGroup.add(verts_tip, 1.0, 'ADD') + + valleyGroup = obj.vertex_groups.new(name = 'Valleys') + valleyGroup.add(verts_valley, 1.0, 'ADD') + + obj.data["WormGear"] = True + obj.data["change"] = False + for prm in WormGearParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') mesh, verts_tip, verts_valley = AddWormGearMesh(self, context) obj = object_utils.object_data_add(context, mesh, operator=None) - - # Create vertex groups from stored vertices. - tipGroup = obj.vertex_groups.new(name = 'Tips') - tipGroup.add(verts_tip, 1.0, 'ADD') - - valleyGroup = obj.vertex_groups.new(name = 'Valleys') - valleyGroup.add(verts_valley, 1.0, 'ADD') - - obj.data["WormGear"] = True - obj.data["change"] = False - for prm in WormGearParameters(): - obj.data[prm] = getattr(self, prm) + + # Create vertex groups from stored vertices. + tipGroup = obj.vertex_groups.new(name = 'Tips') + tipGroup.add(verts_tip, 1.0, 'ADD') + + valleyGroup = obj.vertex_groups.new(name = 'Valleys') + valleyGroup.add(verts_valley, 1.0, 'ADD') + + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} @@ -894,4 +934,4 @@ def WormGearParameters(): "skew", "crown", ] - return WormGearParameters
\ No newline at end of file + return WormGearParameters diff --git a/add_mesh_extra_objects/add_mesh_pipe_joint.py b/add_mesh_extra_objects/add_mesh_pipe_joint.py index 0fe5d67b..0c1e315f 100644 --- a/add_mesh_extra_objects/add_mesh_pipe_joint.py +++ b/add_mesh_extra_objects/add_mesh_pipe_joint.py @@ -1,20 +1,22 @@ # GPL # "author": "Buerbaum Martin (Pontiac)" -import bpy +import bpy, bmesh from math import sin, cos, tan, pi, radians from bpy.types import Operator from bpy.props import ( FloatProperty, IntProperty, + BoolProperty, + StringProperty, ) - +from bpy_extras import object_utils # Create a new mesh (object) from verts/edges/faces. # verts/edges/faces ... List of vertices/edges/faces for the # new mesh (as used in from_pydata) # name ... Name of the new mesh (& object) -def create_mesh_object(context, verts, edges, faces, name): +def create_mesh(context, verts, edges, faces, name): # Create new mesh mesh = bpy.data.meshes.new(name) @@ -24,9 +26,7 @@ def create_mesh_object(context, verts, edges, faces, name): # Update mesh geometry after adding stuff. mesh.update() - from bpy_extras import object_utils - return object_utils.object_data_add(context, mesh, operator=None) - + return mesh # A very simple "bridge" tool. @@ -87,6 +87,15 @@ def createFaces(vertIdx1, vertIdx2, closed=False, flipped=False): # Create the vertices and polygons for a simple elbow (bent pipe) +def ElbowJointParameters(): + ElbowJointParameters = [ + "radius", + "div", + "angle", + "startLength", + "endLength", + ] + return ElbowJointParameters class AddElbowJoint(Operator): bl_idname = "mesh.primitive_elbow_joint_add" @@ -94,6 +103,15 @@ class AddElbowJoint(Operator): bl_description = "Construct an elbow pipe mesh" bl_options = {'REGISTER', 'UNDO', 'PRESET'} + ElbowJoint : BoolProperty(name = "ElbowJoint", + default = True, + description = "ElbowJoint") + + #### change properties + change : BoolProperty(name = "Change", + default = False, + description = "change ElbowJoint") + radius: FloatProperty( name="Radius", description="The radius of the pipe", @@ -133,6 +151,16 @@ class AddElbowJoint(Operator): unit="LENGTH" ) + def draw(self, context): + layout = self.layout + + box = layout.box() + box.prop(self, 'radius') + box.prop(self, 'div') + box.prop(self, 'angle') + box.prop(self, 'startLength') + box.prop(self, 'endLength') + def execute(self, context): radius = self.radius div = self.div @@ -188,14 +216,54 @@ class AddElbowJoint(Operator): # Create faces faces.extend(createFaces(loop1, loop2, closed=True)) faces.extend(createFaces(loop2, loop3, closed=True)) - - base = create_mesh_object(context, verts, [], faces, "Elbow Joint") + + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + oldmesh = obj.data + oldmeshname = obj.data.name + mesh = create_mesh(context, verts, [], faces, "Elbow Joint") + obj.data = mesh + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh = create_mesh(context, verts, [], faces, "Elbow Joint") + obj = object_utils.object_data_add(context, mesh, operator=None) + + mesh.update() + + obj.data["ElbowJoint"] = True + obj.data["change"] = False + for prm in ElbowJointParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') + mesh = create_mesh(context, verts, [], faces, "TMP") + obj = object_utils.object_data_add(context, mesh, operator=None) + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} # Create the vertices and polygons for a simple tee (T) joint # The base arm of the T can be positioned in an angle if needed though +def TeeJointParameters(): + TeeJointParameters = [ + "radius", + "div", + "angle", + "startLength", + "endLength", + "branchLength", + ] + return TeeJointParameters class AddTeeJoint(Operator): bl_idname = "mesh.primitive_tee_joint_add" @@ -203,6 +271,15 @@ class AddTeeJoint(Operator): bl_description = "Construct a tee-joint pipe mesh" bl_options = {'REGISTER', 'UNDO', 'PRESET'} + TeeJoint : BoolProperty(name = "TeeJoint", + default = True, + description = "TeeJoint") + + #### change properties + change : BoolProperty(name = "Change", + default = False, + description = "change TeeJoint") + radius: FloatProperty( name="Radius", description="The radius of the pipe", @@ -254,6 +331,17 @@ class AddTeeJoint(Operator): unit="LENGTH" ) + def draw(self, context): + layout = self.layout + + box = layout.box() + box.prop(self, 'radius') + box.prop(self, 'div') + box.prop(self, 'angle') + box.prop(self, 'startLength') + box.prop(self, 'endLength') + box.prop(self, 'branchLength') + def execute(self, context): radius = self.radius div = self.div @@ -373,11 +461,52 @@ class AddTeeJoint(Operator): faces.extend(createFaces(loopMainStart, loopJoint1, closed=True)) faces.extend(createFaces(loopJoint2, loopArm, closed=True)) faces.extend(createFaces(loopJoint3, loopMainEnd, closed=True)) - - base = create_mesh_object(context, verts, [], faces, "Tee Joint") + + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + oldmesh = obj.data + oldmeshname = obj.data.name + mesh = create_mesh(context, verts, [], faces, "Tee Joint") + obj.data = mesh + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh = create_mesh(context, verts, [], faces, "Tee Joint") + obj = object_utils.object_data_add(context, mesh, operator=None) + + mesh.update() + + obj.data["TeeJoint"] = True + obj.data["change"] = False + for prm in TeeJointParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') + mesh = create_mesh(context, verts, [], faces, "TMP") + obj = object_utils.object_data_add(context, mesh, operator=None) + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} +def WyeJointParameters(): + WyeJointParameters = [ + "radius", + "div", + "angle1", + "angle2", + "startLength", + "branch1Length", + "branch2Length", + ] + return WyeJointParameters class AddWyeJoint(Operator): bl_idname = "mesh.primitive_wye_joint_add" @@ -385,6 +514,15 @@ class AddWyeJoint(Operator): bl_description = "Construct a wye-joint pipe mesh" bl_options = {'REGISTER', 'UNDO', 'PRESET'} + WyeJoint : BoolProperty(name = "WyeJoint", + default = True, + description = "WyeJoint") + + #### change properties + change : BoolProperty(name = "Change", + default = False, + description = "change WyeJoint") + radius: FloatProperty( name="Radius", description="The radius of the pipe", @@ -444,6 +582,18 @@ class AddWyeJoint(Operator): unit="LENGTH" ) + def draw(self, context): + layout = self.layout + + box = layout.box() + box.prop(self, 'radius') + box.prop(self, 'div') + box.prop(self, 'angle1') + box.prop(self, 'angle2') + box.prop(self, 'startLength') + box.prop(self, 'branch1Length') + box.prop(self, 'branch2Length') + def execute(self, context): radius = self.radius div = self.div @@ -573,13 +723,56 @@ class AddWyeJoint(Operator): faces.extend(createFaces(loopMainStart, loopJoint1, closed=True)) faces.extend(createFaces(loopJoint2, loopArm1, closed=True)) faces.extend(createFaces(loopJoint3, loopArm2, closed=True)) - - base = create_mesh_object(context, verts, [], faces, "Wye Joint") + + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + oldmesh = obj.data + oldmeshname = obj.data.name + mesh = create_mesh(context, verts, [], faces, "Wye Joint") + obj.data = mesh + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh = create_mesh(context, verts, [], faces, "Wye Joint") + obj = object_utils.object_data_add(context, mesh, operator=None) + + mesh.update() + + obj.data["WyeJoint"] = True + obj.data["change"] = False + for prm in WyeJointParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') + mesh = create_mesh(context, verts, [], faces, "TMP") + obj = object_utils.object_data_add(context, mesh, operator=None) + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} # Create the vertices and polygons for a cross (+ or X) pipe joint +def CrossJointParameters(): + CrossJointParameters = [ + "radius", + "div", + "angle1", + "angle2", + "angle3", + "startLength", + "branch1Length", + "branch2Length", + "branch3Length", + ] + return CrossJointParameters class AddCrossJoint(Operator): bl_idname = "mesh.primitive_cross_joint_add" @@ -587,6 +780,15 @@ class AddCrossJoint(Operator): bl_description = "Construct a cross-joint pipe mesh" bl_options = {'REGISTER', 'UNDO', 'PRESET'} + CrossJoint : BoolProperty(name = "CrossJoint", + default = True, + description = "CrossJoint") + + #### change properties + change : BoolProperty(name = "Change", + default = False, + description = "change CrossJoint") + radius: FloatProperty( name="Radius", description="The radius of the pipe", @@ -657,6 +859,20 @@ class AddCrossJoint(Operator): unit="LENGTH" ) + def draw(self, context): + layout = self.layout + + box = layout.box() + box.prop(self, 'radius') + box.prop(self, 'div') + box.prop(self, 'angle1') + box.prop(self, 'angle2') + box.prop(self, 'angle3') + box.prop(self, 'startLength') + box.prop(self, 'branch1Length') + box.prop(self, 'branch2Length') + box.prop(self, 'branch3Length') + def execute(self, context): radius = self.radius div = self.div @@ -833,13 +1049,51 @@ class AddCrossJoint(Operator): faces.extend(createFaces(loopJoint2, loopArm1, closed=True)) faces.extend(createFaces(loopJoint3, loopArm2, closed=True)) faces.extend(createFaces(loopJoint4, loopArm3, closed=True)) - - base = create_mesh_object(context, verts, [], faces, "Cross Joint") + + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + oldmesh = obj.data + oldmeshname = obj.data.name + mesh = create_mesh(context, verts, [], faces, "Cross Joint") + obj.data = mesh + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh = create_mesh(context, verts, [], faces, "Cross Joint") + obj = object_utils.object_data_add(context, mesh, operator=None) + + mesh.update() + + obj.data["CrossJoint"] = True + obj.data["change"] = False + for prm in CrossJointParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') + mesh = create_mesh(context, verts, [], faces, "TMP") + obj = object_utils.object_data_add(context, mesh, operator=None) + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'} # Create the vertices and polygons for a regular n-joint +def NJointParameters(): + NJointParameters = [ + "radius", + "div", + "number", + "length", + ] + return NJointParameters class AddNJoint(Operator): bl_idname = "mesh.primitive_n_joint_add" @@ -847,6 +1101,15 @@ class AddNJoint(Operator): bl_description = "Construct a n-joint pipe mesh" bl_options = {'REGISTER', 'UNDO', 'PRESET'} + NJoint : BoolProperty(name = "NJoint", + default = True, + description = "NJoint") + + #### change properties + change : BoolProperty(name = "Change", + default = False, + description = "change NJoint") + radius: FloatProperty( name="Radius", description="The radius of the pipe", @@ -878,6 +1141,15 @@ class AddNJoint(Operator): unit="LENGTH" ) + def draw(self, context): + layout = self.layout + + box = layout.box() + box.prop(self, 'radius') + box.prop(self, 'div') + box.prop(self, 'number') + box.prop(self, 'length') + def execute(self, context): radius = self.radius div = self.div @@ -1000,7 +1272,36 @@ class AddNJoint(Operator): faces.extend( createFaces(loopsJoints[loopIdx], loopsEndCircles[loopIdx], closed=True)) - - base = create_mesh_object(context, verts, [], faces, "N Joint") + + if bpy.context.mode == "OBJECT": + if self.change == True and self.change != None: + obj = context.active_object + oldmesh = obj.data + oldmeshname = obj.data.name + mesh = create_mesh(context, verts, [], faces, "N Joint") + obj.data = mesh + bpy.data.meshes.remove(oldmesh) + obj.data.name = oldmeshname + else: + mesh = create_mesh(context, verts, [], faces, "N Joint") + obj = object_utils.object_data_add(context, mesh, operator=None) + + obj.data["NJoint"] = True + obj.data["change"] = False + for prm in NJointParameters(): + obj.data[prm] = getattr(self, prm) + + if bpy.context.mode == "EDIT_MESH": + active_object = context.active_object + name_active_object = active_object.name + bpy.ops.object.mode_set(mode='OBJECT') + mesh = create_mesh(context, verts, [], faces, "TMP") + obj = object_utils.object_data_add(context, mesh, operator=None) + obj.select_set(True) + active_object.select_set(True) + bpy.ops.object.join() + context.active_object.name = name_active_object + bpy.ops.object.mode_set(mode='EDIT') + return {'FINISHED'} |