freeCAD transform step& stp to stl logging py2exe 打包

这篇博客记录了一位初学者如何将STEP和STP格式的文件转换为STL,并使用py2exe工具将Python代码打包成可执行的EXE文件的过程。
部署运行你感兴趣的模型镜像

由于笔者是初学者 经过几天的折腾,终于把 step&stp格式转化成stl 并使用py2exe打包成 exe文件,

以下是代码:

 

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ============================
# @Author  : TwoBrother Zhu
# @Time    : 2018/7/29 19:32
# @File    : trans
# @Software: PyCharm
# ============================

import sys
sys.path.append('C:\\Software\\FreeCAD 0.17\\lib')
import FreeCAD

import math
import Part     # 此模块在freeCAD中,虽然在pycharm中有红色波浪线,仍然可以使用
import Mesh     # 此模块需要在pycharm安装

import logging
import time

import os


# 第一步 创建一个logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)  # 等级总开关

# 第二步 创建一个handler 用于写入日志文件
rq = time.strftime('%Y%m%d%H', time.localtime(time.time()))
log_path = "./logs/"
if not os.path.exists(log_path):
    os.mkdir(log_path)
log_name = log_path + rq + '.log'
logfile = log_name
fh = logging.FileHandler(logfile, mode='a')
fh.setLevel(logging.DEBUG)  # 输出到file的log等级的开关

# 第三步 定义handler的输出格式
formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
fh.setFormatter(formatter)

# 第四步,将logger添加到handler里面
logger.addHandler(fh)

class Transform(object):

    @classmethod
    def trans_file(self):

        try:
            start_files, out_path = self.trans(path)
            for start_file in start_files:
                name = os.path.basename(start_file)
                end_file = out_path + '\\{}.stl'.format(name)

                shape = Part.Shape()
                shape.read(start_file)
                mesh = Mesh.Mesh()
                mesh.addFacets(shape.tessellate(0.01))
                mesh.write(end_file)

        except Exception as e:
            logger.error(e)

    @classmethod
    def trans(self, path):
        try:
            directory_path, out_path = path
            file_paths = []
            out_stls = []
            file_list = os.walk(directory_path)
            for (dir_path, dir_list, file_names) in file_list:
                for file_name in file_names:
                    if file_name.endswith('STEP') or file_name.endswith('step') or file_name.endswith('stp') or file_name.endswith('STP'):
                        file_path = os.path.join(dir_path, file_name)
                        file_paths.append(file_path)
                        # print(file_path)

                        if not os.path.exists(out_path):
                            os.mkdir(out_path)
                        out_stl = out_path + file_name + '.stl'
                        out_stls.append(out_stl)
                        # print(out_stl)
            return file_paths, out_path

        except Exception as e:
            logger.error(e)

if __name__ == '__main__':
    path = ('D:\\work\\step', 'D:\\work\\stl')
    Transform.trans(path)
    Transform.trans_file()

以下是py2exe打包代码

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ============================
# @Author  : TwoBrother Zhu
# @Time    : 2018/7/29 22:32
# @File    : trans
# @Software: PyCharm
# ============================

FREECADPATH = 'C:\\Software\\FreeCAD 0.17\\lib'
import sys
sys.path.append(FREECADPATH)
import py2exe

from distutils.core import setup
import FreeCAD
import Part
import Mesh

setup(
    console=["C:\\Users\\TwoBrother\\projects\\spider\\day16\\trans.py"],
    options={
        'py2exe': {
            "dll_excludes": [
                "MSVCP90.dll","libzmq.pyd","geos_c.dll","api-ms-win-core-string-l1-1-0.dll",
                "api-ms-win-core-rtlsupport-l1-2-0.dll","api-ms-win-core-registry-l1-1-0.dll",
                "api-ms-win-core-errorhandling-l1-1-1.dll","api-ms-win-core-string-l2-1-0.dll",
                "api-ms-win-core-profile-l1-1-0.dll","api-ms-win*.dll",
                "api-ms-win-core-processthreads-l1-1-2.dll","api-ms-win-core-libraryloader-l1-2-1.dll",
                "api-ms-win-core-file-l1-2-1.dll","api-ms-win-security-base-l1-2-0.dll",
                "api-ms-win-eventing-provider-l1-1-0.dll","api-ms-win-core-heap-l2-1-0.dll",
                "api-ms-win-core-libraryloader-l1-2-0.dll","api-ms-win-core-localization-l1-2-1.dll",
                "api-ms-win-core-sysinfo-l1-2-1.dll","api-ms-win-core-synch-l1-2-0.dll",
                "api-ms-win-core-heap-l1-2-0.dll","api-ms-win-core-handle-l1-1-0.dll",
                "api-ms-win-core-io-l1-1-1.dll","api-ms-win-core-com-l1-1-1.dll",
                "api-ms-win-core-memory-l1-1-2.dll","api-ms-win-core-version-l1-1-1.dll",
                "api-ms-win-core-version-l1-1-0.dll", 'api-ms-win-core-rtlsupport-l1-1-0.dll',
                'api-ms-win-core-processthreads-l1-1-0.dll',  'api-ms-win-core-errorhandling-l1-1-0.dll',
                'api-ms-win-core-sysinfo-l1-1-0.dll'

            ]

        }

    }
)

 

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

Module developer’s guide to FreeCAD source code by Qingfeng Xia http://www.iesensor.com • 2015-09-18 version 0.1 for FreeCAD version 0.16-dev • 2016-09-18 version 0.2 for FreeCAD version 0.17-dev License of this book This ebook is licensed the same as FreeCAD document license CC-BY 3.0 http://creativecommons.org/licenses/by/3.0/Contents 1 FreeCAD overview and architecture 7 1.1 Introduction to FreeCAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.2 Key features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.3 Software architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.3.1 Key software libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.3.2 Mixed python and c++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3.3 GPL code will not be included into installer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4 How 3D model are renderred . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4.1 Selection of 3D visualization libarary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.4.2 Discussion of 3D rendering library selection on FreeCAD Forum . . . . . . . . . . . . . . . . . . . . . 8 1.5 Roadmap of FreeCAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.5.1 Keep updated with main components: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.5.2 C++11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.5.3 Pyside 2 project for Qt 5.x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2 Organisation of FreeCAD source code 11 2.1 Build system for FreeCAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.1.1 Analysis of src/cMake/SMesh.cMake . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.2 List of files and folders in FreeCAD source folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.3 List of modules in FreeCAD Mod folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.4 Learning path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.5 Learning OpenInventor/Coin3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.5.1 OpenInventor in FreeCAD’s ViewProvider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.5.2 Important classes in OpenInventor/Coin3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.5.3 Window System integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.5.4 Pivy: Coin3D ’s Python wrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3 Base, App and Main module 19 3.1 List of header files in Base folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.1.1 Frequently included headers files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.1.2 Correct way of using Sequencer in try-catch block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.1.3 String enconding utf8 and conversion into wchar_t QString . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2 Type, BaseClass, PyObjectBase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2.1 Type system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2.2 src/Base/BaseClass.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.2.3 src/Base/PyObjectBase.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2.4 src/Base/Persistence.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2.5 GeoFeature: Base class of all geometric document objects . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.3 Unit scheme for physial quantity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.3.1 src/Base/Unit.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.3.2 src/Base/Quantity.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.4 List of header files in App folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.5 Property framewrok . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.5.1 Naming of property and PropertyEditor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.5.2 src/App/PropertyStandard.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.5.3 PropertyEnumeration, see src/App/Enumeration.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.5.4 Geometry related property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.5.5 File related property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值