日本語入力を簡単に

投稿ツリー


このトピックの投稿一覧へ

通常 日本語入力を簡単に

msg# 1
depth:
0
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2011/12/17 19:22
Takeshi  新米 居住地: 愛知  投稿数: 9
※追記:UNDO設定をつけ、上書きもできるように変更しました2011/12/27

Blenderが日本語UIに対応しましたね
しかし、いまだ日本語の直接入力が実現していません
以前からまんださんやchromolyが作ったTkを使用したスクリプトを利用してきましたが
http://blender.jp/modules/newbb/viewtopic.php?viewmode=flat&order=ASC&topic_id=857&forum=3&move=next&topic_time=1212205316
http://blender.jp/modules/news/article.php?storyid=3274
バージョンアップに伴って、pythonが内蔵式になったためか僕の環境で使えなくなっていました
新しいのに乗り換えてスクリプトは、古いバージョンで使うか迷っていたんですが


間を取って(?)新しく違うスクリプトを書いてみました
クリップボードを使用して貼り付けるというものです
Windows専用ですがよかったら使ってください
※既存のスクリプトに似ています アップしてもいいのでしょうか?←事後承諾
bl_info = {
    "name": "Paste from Clipbord(for win32)",
    "author": "Takeshi",
    "version": (1, 0),
    "blender": (2, 61, 0),
    "api": 42615,
    "location": "Properties -> ObjectData",
    "description": "Paste text from clipboard",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Text"}


import bpy
from bpy.props import *
import sys
from ctypes import *

OpenClipboard = windll.user32.OpenClipboard
GetClipboardData = windll.user32.GetClipboardData
CloseClipboard = windll.user32.CloseClipboard
GlobalLock = windll.kernel32.GlobalLock
GlobalUnlock = windll.kernel32.GlobalUnlock



#### Text Edit Operator ####
class TEXT_OT_PCB(bpy.types.Operator):
    bl_description = 'Paste text from Clipboard'
    bl_idname = 'text.paste_clipboard'
    bl_label = 'Paste text'
    bl_undo = True

    @classmethod
    def poll(cls, context):
        actob = context.active_object
        return (actob and actob.type == 'FONT')

    def paste(self):
        scene = bpy.context.scene
        if OpenClipboard(c_int(0)):
            hClipMem = GetClipboardData(c_int(13))
            GlobalLock.restype = c_wchar_p
            text = GlobalLock(c_int(hClipMem))
            GlobalUnlock(c_int(hClipMem))
            CloseClipboard()
        
        if text:
            ob = bpy.context.active_object
            editmode = ob.mode
            if editmode == 'EDIT':
                bpy.ops.object.mode_set(mode='OBJECT')
            ####
            if scene.paste_type == "0":
                ob.data.body = text
            if scene.paste_type == "1":
                ob.data.body += text
            ####
            if editmode == 'EDIT':
                bpy.ops.object.mode_set(mode='EDIT')

    def execute(self, context=None):
        self.paste()
        return {'FINISHED'}


## Load Fonts ##
if sys.platform == 'win32':  # Windows
    font_paths = ('C:\WINDOWS\Fonts\msgothic.ttc',
                  'C:\WINDOWS\Fonts\msmincho.ttc',
                  'C:\WINDOWS\Fonts\meiryo.ttc')
else:  # Linux etc.
    font_paths = ('/home/hoge/.fonts/meiryo/meiryo.ttc',
                  '/home/hoge/.fonts/meiryo/meiryob.ttc')
#### Load Fonts Operator ####
class TEXT_OT_load_fonts(bpy.types.Operator):
    '''Load fonts'''
    bl_description = "load fonts (PCB)"
    bl_idname = 'text.load_fonts'
    bl_label = 'Load Fonts'

    setactob = BoolProperty(default=False)

    '''
    @classmethod
    def poll(cls, context):
        actob = context.active_object
        return actob and actob.type == 'FONT'
    '''

    def execute(self, context=None):
        if not font_paths:
            return {'FINISHED'}
        loadedpaths = [f.filepath for f in bpy.data.fonts]
        for path in font_paths:
            if not path in loadedpaths:
                bpy.ops.font.open(filepath=path)

        if self.setactob:
            actob = bpy.context.active_object
            if actob and actob.type == 'FONT':
                for font in bpy.data.fonts:
                    if font.filepath == font_paths[0]:
                        actob.data.font = font
                        break
        return {'FINISHED'}

#### Add Panel ####
class DATA_PT_call_PCB(bpy.types.Panel):
    bl_label = "Paste"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = 'data'

    @classmethod
    def poll(cls, context):
        actob = context.active_object
        return (actob and actob.type == 'FONT')

    def draw(self, context):
        layout = self.layout
        split = layout.split()
        col = split.column(align=True)
        col.operator('text.paste_clipboard', text='Paste from Clipboard', icon='FONT_DATA')
        col.prop(context.scene, "paste_type", expand=True)
        
        col = split.column(align=True)
        op = col.operator('text.load_fonts', text='Load Fonts', icon='FILE_FONT')
        op.setactob = True
        

### Registration ###
def register():
    bpy.utils.register_class(TEXT_OT_PCB)
    bpy.utils.register_class(TEXT_OT_load_fonts)
    bpy.utils.register_class(DATA_PT_call_PCB)
    
    bpy.types.Scene.paste_type = EnumProperty(
        name="Paste Type",
        description="Select the type of way to paste text",
        items=[("0","Over write","over write text"),
               ("1","Add","add text at the end of data")
              ],
        default='1')
    

def unregister():
    bpy.utils.unregister_class(TEXT_OT_PCB)
    bpy.utils.unregister_class(TEXT_OT_load_fonts)
    bpy.utils.unregister_class(DATA_PT_call_PCB)
    del bpy.tepes.Scene.paste_type

if __name__ == '__main__':
    register()

#### 使い方 ####
テキストは末尾に追加されます
・スクリプトを導入
・テキストを追加して選択、propertiesのFとあるObjectDataタブにPasteが追加されていることを確認
・貼り付けたいテキストをどこからでもいいのでコピー(内部はunicodeなので、大体の言語をカバーできると思います)
・Paste from Clipboardボタンをクリック → OK?
・Load Fontsボタンで日本語表示可能な大体のフォントを読み込みます

Thank you


投票数:1 平均点:0.00

  条件検索へ


ログイン

ユーザ名:

パスワード:



パスワード紛失

クイックリンク

2021/07/01版
●Blender.org
BlenderFoundation
- Blenderのダウンロード
- 公式チュート等
- 公式マニュアル(和訳)

●ニュース(英文)
BlenderNation

●Blenderコミュニティ
blenderartists.org

●Blender Q&A
- Blender Stack Exchange

●テストビルド
Buildbot(自動生成)


●開発関連
公式開発サイト
Blender開発blog
Blender Wiki