Example #1
0
    def execute(self, context):
        s = bpy.context.scene
        fixUnits()

        if s.objects.get('CAM_machine') is None:
            utils.addMachineAreaObject()
        # if len(s.cam_material)==0:
        #     s.cam_material.add()

        s.cam_operations.add()
        o = s.cam_operations[-1]
        s.cam_active_operation = len(s.cam_operations) - 1
        o.name = 'Operation_' + str(s.cam_active_operation + 1)
        o.filename = o.name
        ob = bpy.context.active_object
        if ob is not None:
            o.object_name = ob.name
            minx, miny, minz, maxx, maxy, maxz = utils.getBoundsWorldspace([ob])
            o.minz = minz

        return {'FINISHED'}
Example #2
0
	def execute(self, context):
		#main(context)
		s=bpy.context.scene
		
		fixUnits()
		
		if s.objects.get('CAM_machine')==None:
			utils.addMachineAreaObject()
		#if len(s.cam_material)==0:
		#	 s.cam_material.add()
		  
		s.cam_operations.add()
		o=s.cam_operations[-1]
		s.cam_active_operation=len(s.cam_operations)-1
		o.name='Operation_'+str(s.cam_active_operation+1)
		o.filename=o.name
		ob=bpy.context.active_object
		if ob!=None:
			o.object_name=ob.name
			minx,miny,minz,maxx,maxy,maxz=utils.getBoundsWorldspace([ob])
			o.minz=minz
		
		return {'FINISHED'}
Example #3
0
def sliceObject(ob):  # April 2020 Alain Pelletier
    # get variables from menu
    thickness = bpy.context.scene.cam_slice.slice_distance
    slice3d = bpy.context.scene.cam_slice.slice_3d
    indexes = bpy.context.scene.cam_slice.indexes
    above0 = bpy.context.scene.cam_slice.slice_above0
    # setup the collections
    scollection = bpy.data.collections.new("Slices")
    bpy.context.scene.collection.children.link(scollection)
    if indexes:
        tcollection = bpy.data.collections.new("Text")
        bpy.context.scene.collection.children.link(tcollection)

    # show object information
    print(ob.dimensions)
    print(ob.location)

    bpy.ops.object.mode_set(mode='OBJECT')  # force object mode
    minx, miny, minz, maxx, maxy, maxz = utils.getBoundsWorldspace([ob])

    start_height = minz
    if above0 and minz < 0:
        start_height = 0

    layeramt = 1 + int((maxz - start_height) //
                       thickness)  # calculate amount of layers needed

    for layer in range(layeramt):
        height = round(layer * thickness, 6)  # height of current layer
        t = str(layer) + "-" + str(height * 1000)
        slicename = "slice_" + t  # name for the current slice
        tslicename = "t_" + t  # name for the current slice text
        height += start_height
        print(slicename)

        ob.select_set(True)  # select object to be sliced
        bpy.context.view_layer.objects.active = ob  # make object to be sliced active
        bpy.ops.object.duplicate()  # make a copy of object to be sliced
        bpy.context.view_layer.objects.active.name = slicename  # change the name of object

        obslice = bpy.context.view_layer.objects.active  # attribute active object to obslice
        scollection.objects.link(obslice)  # link obslice to scollecton
        if slice3d:
            slicing3d(
                obslice, height, height + thickness
            )  # slice 3d at desired height and stop at desired height
        else:
            slicesuccess = slicing2d(obslice,
                                     height)  # slice object at desired height

        if indexes and slicesuccess:
            # text objects
            bpy.ops.object.text_add()  # new text object
            textob = bpy.context.active_object
            textob.data.size = 0.006  # change size of object
            textob.data.body = t  # text content
            textob.location = (0, 0, 0)  # text location
            textob.name = tslicename  # change the name of object
            bpy.ops.object.select_all(action='DESELECT')  # deselect everything
            tcollection.objects.link(textob)  # add to text collection
            textob.parent = obslice  # make textob child of obslice

    # select all slices
    for obj in bpy.data.collections['Slices'].all_objects:
        obj.select_set(True)