ue python二次开发启动教程+ 导入fbx到指定文件夹

仓库

https://github.com/nils-soderman/vscode-unreal-python.git

nils-soderman/vscode-unreal-python | DeepWiki

参考

(超级方便的)在UE5中执行Python脚本 - 知乎

我的ue4.24不能运行5.7可以

python 复制代码
import unreal

unreal.log("Hello UE5")

vscode要开插件

=================================================================================================================================================

ue也要开插件

Failed to connect to Unreal Engine Troubleshooting · nils-soderman/vscode-unreal-python Wiki

连接到 Unreal Engine 失败 故障排除 · nils-soderman/vscode-unreal-python Wiki --- Failed to connect to Unreal Engine Troubleshooting · nils-soderman/vscode-unreal-python Wiki

导入fbx到指定文件夹

python 复制代码
import unreal
import tkinter as tk
from tkinter import filedialog
import os

def import_fbx_with_tk_safe():
    """
    使用 tkinter 弹窗选择 FBX 文件并安全导入
    """
    try:
        # 隐藏主窗口
        root = tk.Tk()
        root.withdraw()
        
        # 打开文件选择对话框
        file_path = filedialog.askopenfilename(
            title="选择FBX文件",
            filetypes=[("FBX files", "*.fbx"), ("All files", "*.*")]
        )
        
        # 销毁根窗口
        root.destroy()
        
        if not file_path or not os.path.exists(file_path):
            unreal.log("未选择有效文件")
            return
        
        # 检查是否是 FBX 文件
        if not file_path.lower().endswith('.fbx'):
            unreal.log(f"文件 {file_path} 不是有效的 FBX 文件")
            return
        
        # 定义目标路径
        destination_path = "/Game/Characters/MainChar/W/Meshes/"
        
        # 创建导入任务
        import_task = unreal.AssetImportTask()
        import_task.set_editor_property('filename', file_path)
        import_task.set_editor_property('destination_path', destination_path)
        import_task.set_editor_property('save', True)
        import_task.set_editor_property('automated', True)
        import_task.set_editor_property('replace_existing', True)
        
        # 执行导入任务
        asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
        asset_tools.import_asset_tasks([import_task])
        
        unreal.log(f"成功导入文件: {os.path.basename(file_path)}")
        unreal.log(f"导入到路径: {destination_path}")
        
    except Exception as e:
        unreal.log(f"导入过程中发生错误: {str(e)}")

# 执行函数
import_fbx_with_tk_safe()

运行结果

可以开启输出日志

相关推荐
如竟没有火炬21 分钟前
最大矩阵——单调栈
数据结构·python·线性代数·算法·leetcode·矩阵
阳区欠31 分钟前
【LangChain】LLM基础介绍
开发语言·python·langchain
Cosolar32 分钟前
保姆级 CrewAI 教程:从零构建多智能体协作系统
人工智能·python·架构
Jinkxs42 分钟前
Java 跨域14-Java 与区块链(Hyperledger)集成
java·开发语言·区块链
GDAL1 小时前
使用 uv 管理 Python 版本
python·uv·版本
真实的菜1 小时前
Redis 从入门到精通(十二):典型业务场景实战 —— 排行榜、限流器、秒杀系统、Session 共享
数据库·redis·python
cup111 小时前
[开源] Meta Assistant / 告别命令行,我为一堆 Python 脚本做了一个 Windows 任务栏的“家”
windows·python·工具·nuitka·脚本运行
晨曦中的暮雨2 小时前
Golang速通(Javaer版)
java·开发语言·后端·golang
小小编程路2 小时前
Python 还有容器类型互转、进制转换、字符编码转换
开发语言·windows·python
qeen872 小时前
【C++】类与对象之类的默认成员函数(二)
android·c语言·开发语言·c++·笔记·学习