BlenderCN论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1798|回复: 3

surface 平板电脑 绘图辅助工具python

[复制链接]
发表于 2015-1-5 00:53:39 | 显示全部楼层 |阅读模式
用blender在surface上绘图时无法用键盘上的快捷键
连调整笔刷大小 缩放视图都很吃力
用ps想自定义功能无从下手
还是咱blender最亲
下面是一个简单脚本在图片编辑器右侧添加几个快捷按钮的效果
笔刷尺寸= 2,5,20
视图倍数=0.5,1,2
paint_bpy.blend1.jpg

py菜鸟写的  也许还可以精简


  1. bl_info = {
  2.     "name": "paintTools",
  3.     "category": "Object",
  4. }
  5. #in blender2.72
  6. import bpy

  7. class brushSize002(bpy.types.Operator):
  8.     """bbss002"""
  9.     bl_idname= "object.bs002"
  10.     bl_label= "size 2"
  11.     bl_options= {'REGISTER', 'UNDO'}
  12.    
  13.     def execute(self,context):
  14.         scene = bpy.context.scene
  15.         scene.tool_settings.unified_paint_settings.size = 2
  16.         
  17.         return {'FINISHED'}
  18.    
  19. class brushSize005(bpy.types.Operator):
  20.     """bbss002"""
  21.     bl_idname= "object.bs005"
  22.     bl_label= "size 5"
  23.     bl_options= {'REGISTER', 'UNDO'}
  24.    
  25.     def execute(self,context):
  26.         scene = bpy.context.scene
  27.         scene.tool_settings.unified_paint_settings.size = 5
  28.         
  29.         return {'FINISHED'}   
  30. class brushSize020(bpy.types.Operator):
  31.     """bbss020"""
  32.     bl_idname= "object.bs020"
  33.     bl_label= "size 20"
  34.     bl_options= {'REGISTER', 'UNDO'}
  35.    
  36.     def execute(self,context):
  37.         scene = bpy.context.scene
  38.         scene.tool_settings.unified_paint_settings.size = 20
  39.         
  40.         return {'FINISHED'}

  41. class paintTool(bpy.types.Panel):
  42.     bl_idname = "Quick Change"
  43.     bl_label = "Hello World"
  44.     bl_space_type = 'IMAGE_EDITOR'
  45.     bl_region_type = 'UI'
  46.     bl_context = "Tools"
  47.    
  48.     @classmethod
  49.     def poll(cls, context):
  50.         return (context.object is not None)
  51.         
  52.     def draw(self, context):
  53.         layout = self.layout

  54.         row = layout.row()
  55.         row.operator("object.bs002")
  56.         row.operator("object.bs005")
  57.         row.operator("object.bs020")
  58.         
  59.         row = layout.row()
  60.         row.operator("image.view_zoom_ratio","x0.5").ratio = 0.5
  61.         row.operator("image.view_zoom_ratio","x1").ratio = 1
  62.         row.operator("image.view_zoom_ratio","x2").ratio = 2

  63. def register():
  64.     bpy.utils.register_class(brushSize002)
  65.     bpy.utils.register_class(brushSize005)
  66.     bpy.utils.register_class(brushSize020)
  67.    
  68. def unregister():
  69.     bpy.utils.unregister_class(brushSize002)
  70. bpy.utils.register_class(paintTool)

  71. #  by  Jianzwan
  72. #if __name__ == "__main__":
  73. #   register()
复制代码



 楼主| 发表于 2015-1-9 01:57:58 | 显示全部楼层
新加入了 撤消 重做 新建画布1280*800  绘画模式切换 几个按钮  m= =
  1. bl_info = {
  2.     "name": "paintTools",
  3.     "category": "Object",
  4. }
  5. #in blender2.72
  6. import bpy

  7. class brushSize002(bpy.types.Operator):
  8.     """bbss002"""
  9.     bl_idname= "object.bs002"
  10.     bl_label= "2"
  11.     bl_options= {'REGISTER', 'UNDO'}
  12.    
  13.     def execute(self,context):
  14.         scene = bpy.context.scene
  15.         scene.tool_settings.unified_paint_settings.size = 2
  16.         
  17.         return {'FINISHED'}
  18.    
  19. class brushSize005(bpy.types.Operator):
  20.     """bbss005"""
  21.     bl_idname= "object.bs005"
  22.     bl_label= "5"
  23.     bl_options= {'REGISTER', 'UNDO'}
  24.    
  25.     def execute(self,context):
  26.         scene = bpy.context.scene
  27.         scene.tool_settings.unified_paint_settings.size = 5
  28.         
  29.         return {'FINISHED'}
  30.      
  31. class brushSize020(bpy.types.Operator):
  32.     """bbss020"""
  33.     bl_idname= "object.bs020"
  34.     bl_label= "20"
  35.     bl_options= {'REGISTER', 'UNDO'}
  36.    
  37.     def execute(self,context):
  38.         scene = bpy.context.scene
  39.         scene.tool_settings.unified_paint_settings.size = 20
  40.         
  41.         return {'FINISHED'}

  42. class brushSize060(bpy.types.Operator):
  43.     bl_idname= "object.bs060"
  44.     bl_label= "60"
  45.     bl_options= {'REGISTER', 'UNDO'}
  46.    
  47.     def execute(self,context):
  48.         scene = bpy.context.scene
  49.         scene.tool_settings.unified_paint_settings.size = 60
  50.         
  51.         return {'FINISHED'}

  52. class paintTool(bpy.types.Panel):
  53.     bl_idname = "Quick Change"
  54.     bl_label = "PaintTools"
  55.     bl_space_type = 'IMAGE_EDITOR'
  56.     bl_region_type = 'UI'
  57.     bl_context = "Tools"
  58.    
  59.     @classmethod
  60.     def poll(cls, context):
  61.         return (context.object is not None)
  62.         
  63.     def draw(self, context):
  64.         layout = self.layout
  65.         
  66.         layout.label('brush size')
  67.         row = layout.row()
  68.         row.operator("object.bs002")
  69.         row.operator("object.bs005")
  70.         row.operator("object.bs020")
  71.         row.operator("object.bs060")
  72.         
  73.         layout.label('zoom')
  74.         row = layout.row()
  75.         row.operator("image.view_zoom_ratio","x0.5").ratio = 0.5
  76.         row.operator("image.view_zoom_ratio","x1").ratio = 1
  77.         row.operator("image.view_zoom_ratio","x2").ratio = 2
  78.         
  79.         layout.label("===(^3^)===")
  80.         
  81.         col = layout.split()
  82.         col.operator("ed.undo")
  83.         col.operator("ed.redo")
  84.         
  85. class newImage(bpy.types.Operator):
  86.     bl_idname= "images.newimage"
  87.     bl_label= "new image"
  88.     bl_options= {'REGISTER', 'UNDO'}
  89.    
  90.     def execute(self,context):
  91.         scene = bpy.context.scene
  92.         bpy.ops.image.new(name="Untitled", width=1280, height=800, color=(0.0, 0.0, 0.0, 1.0), alpha=False, generated_type='BLANK', float=False)
  93.         
  94.         return {'FINISHED'}
  95.         
  96. class paintMode(bpy.types.Operator):
  97.     bl_idname= "images.paintmode"
  98.     bl_label= "Paint Mode"
  99.     bl_options= {'REGISTER', 'UNDO'}
  100.    
  101.     def execute(self,context):
  102.         area = bpy.context.area
  103.         print(area.spaces)
  104.         space = area.spaces.active
  105.         print(space)
  106.         if space.mode !='PAINT':
  107.             space.mode = 'PAINT'
  108.         else:
  109.             space.mode = 'VIEW'
  110.         
  111.         return {'FINISHED'}

  112. class paintTool2(bpy.types.Panel):
  113.     bl_idname = "new"
  114.     bl_label = "PaintTools2"
  115.     bl_space_type = 'IMAGE_EDITOR'
  116.     bl_region_type = 'UI'
  117.     bl_context = "Tools"
  118.    
  119.     def draw(self, context):
  120.         layout = self.layout

  121.         column = layout.column()
  122.         column.operator("images.newimage")
  123.         column.label('~~~~~~~')
  124.         column.operator("images.paintmode")
  125.         
  126.         
  127. def register():
  128.     bpy.utils.register_class(brushSize002)
  129.     bpy.utils.register_class(brushSize005)
  130.     bpy.utils.register_class(brushSize020)
  131.     bpy.utils.register_class(brushSize060)
  132.     bpy.utils.register_class(newImage)
  133.     bpy.utils.register_class(paintMode)
  134.     bpy.utils.register_class(paintTool2)
  135.     bpy.utils.register_class(paintTool)
  136.    
  137. def unregister():
  138.     bpy.utils.unregister_class(brushSize002)
  139.     bpy.utils.unregister_class(brushSize005)
  140.     bpy.utils.unregister_class(brushSize020)
  141.     bpy.utils.unregister_class(brushSize060)
  142.     bpy.utils.unregister_class(newImage)
  143.     bpy.utils.unregister_class(painMode)
  144.     bpy.utils.unregister_class(paintTool2)
  145.     bpy.utils.unregister_class(paintTool)


  146. # by  Jianzwan
  147. #if __name__ == "__main__":
  148. #    register()
复制代码



回复 支持 1 反对 0

使用道具 举报

发表于 2015-3-19 09:27:37 | 显示全部楼层
挺好!Python就是这么用的,先DIY简单的,慢慢就会改复杂的了,这是进步的必经之路。

点评

帮助文件里如果范例多点就没这么吃劲了。。。。。  详情 回复 发表于 2015-4-2 21:45
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-4-2 21:45:46 | 显示全部楼层
nirenyang 发表于 2015-3-19 09:27
挺好!Python就是这么用的,先DIY简单的,慢慢就会改复杂的了,这是进步的必经之路。 ...

帮助文件里如果范例多点就没这么吃劲了。。。。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

Blender最新中文教学视频|Blender头条|小黑屋|手机版|Archiver|Blender中国 ( 蜀ICP备17002929号 )360网站安全检测平台

GMT+8, 2019-12-16 11:03 , Processed in 0.019405 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表