Skip to content

Commit 5968152

Browse files
committed
1
1 parent 64a0828 commit 5968152

File tree

7 files changed

+242
-24
lines changed

7 files changed

+242
-24
lines changed

doc/Demo.gif

-2.79 MB
Loading

doc/Demo.mp4

-7.49 MB
Binary file not shown.

doc/ch1.png

25.1 KB
Loading

doc/en1.png

15.9 KB
Loading

import_cad_model/__init__.py

Lines changed: 151 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,88 @@ def update_inifile(self, context):
5959
with open(ini_path, 'w') as configfile:
6060
config.write(configfile)
6161

62+
def update_chordal_deflection(self, context):
63+
sna_updated_prop = self.chordal_deflection
64+
value=(str(round(sna_updated_prop, abs(2))) + 'mm')
65+
66+
ini_path = get_ini_directory()
67+
if not os.path.isfile(ini_path):
68+
print(_('No found the mayo-gui.ini file in plugin directory!'))
69+
return
70+
71+
config = configparser.ConfigParser()
72+
config.read(ini_path)
73+
74+
# 读取ini_path这个文件,找到这个文件里以meshingQuality=开头的这行,将这行改为meshingQuality=self.mesh_quality,然后保存文件
75+
76+
# 检查 meshing section 是否存在,并且 meshingchordaldeflection 是否在其中
77+
if 'meshing' in config and 'meshingchordaldeflection' in config['meshing']:
78+
# 如果存在,则更新 meshingchordaldeflection 的值
79+
config['meshing']['meshingchordaldeflection'] = value
80+
else:
81+
# 如果不存在,则添加 meshingchordaldeflection 到 meshing section
82+
if 'meshing' not in config:
83+
config['meshing'] = {}
84+
config['meshing']['meshingchordaldeflection'] = value
85+
86+
with open(ini_path, 'w') as configfile:
87+
config.write(configfile)
88+
89+
90+
def update_angular_deflection(self, context):
91+
sna_updated_prop = self.angular_deflection
92+
value=(str(round(sna_updated_prop, abs(6))) + 'rad')
93+
94+
ini_path = get_ini_directory()
95+
if not os.path.isfile(ini_path):
96+
print(_('No found the mayo-gui.ini file in plugin directory!'))
97+
return
98+
99+
config = configparser.ConfigParser()
100+
config.read(ini_path)
101+
102+
# 读取ini_path这个文件,找到这个文件里以meshingQuality=开头的这行,将这行改为meshingQuality=self.mesh_quality,然后保存文件
103+
104+
# 检查 meshing section 是否存在,并且 meshingangulardeflection 是否在其中
105+
if 'meshing' in config and 'meshingangulardeflection' in config['meshing']:
106+
# 如果存在,则更新 meshingangulardeflection 的值
107+
config['meshing']['meshingangulardeflection'] = value
108+
else:
109+
# 如果不存在,则添加 meshingangulardeflection 到 meshing section
110+
if 'meshing' not in config:
111+
config['meshing'] = {}
112+
config['meshing']['meshingangulardeflection'] = value
113+
114+
with open(ini_path, 'w') as configfile:
115+
config.write(configfile)
116+
117+
118+
def update_relatire(self, context):
119+
value='ture' if self.relatire else 'false'
120+
121+
ini_path = get_ini_directory()
122+
if not os.path.isfile(ini_path):
123+
print(_('No found the mayo-gui.ini file in plugin directory!'))
124+
return
125+
126+
config = configparser.ConfigParser()
127+
config.read(ini_path)
128+
129+
# 读取ini_path这个文件,找到这个文件里以meshingQuality=开头的这行,将这行改为meshingQuality=self.mesh_quality,然后保存文件
130+
131+
# 检查 meshing section 是否存在,并且 meshingrelative 是否在其中
132+
if 'meshing' in config and 'meshingrelative' in config['meshing']:
133+
# 如果存在,则更新 meshingrelative 的值
134+
config['meshing']['meshingrelative'] = value
135+
else:
136+
# 如果不存在,则添加 meshingrelative 到 meshing section
137+
if 'meshing' not in config:
138+
config['meshing'] = {}
139+
config['meshing']['meshingrelative'] = value
140+
141+
with open(ini_path, 'w') as configfile:
142+
config.write(configfile)
143+
62144
#####每次操作前都要把语言设置为en,不然可能返回的内容是中文
63145
def set_inifile_language():
64146
ini_path = get_ini_directory()
@@ -131,11 +213,23 @@ class MayoConvPreferences(bpy.types.AddonPreferences):
131213
('Coarse', _('Coarse Quality'), _('Coarse quality'), 0, 1),
132214
('Normal', _('Normal Quality'), _('Standard quality'), 0, 2),
133215
('Precise', _('Precise Quality'), _('High precision'), 0, 3),
134-
('VeryPrecise', _('Very Precise'), _('Highest precision'), 0, 4)],
216+
('VeryPrecise', _('Very Precise'), _('Highest precision'), 0, 4),
217+
('UserDefined', _('User Defined'), _('User Defined'), 0, 5)],
135218
default='Normal',
136219
update=update_inifile
137220
)
138221

222+
chordal_deflection: bpy.props.FloatProperty(name=_('Chordal Deflection(mm)'),
223+
description=_('For the tessellation of faces the Chordal Deflection limits the distance between a curve and its tessellation\nThe smaller the value, the more grids.'),
224+
default=1.0, subtype='NONE', unit='NONE', min=0.1, step=3, precision=2, update=update_chordal_deflection)
225+
226+
angular_deflection: bpy.props.FloatProperty(name=_('Angular Deflection'),
227+
description=_('For the tessellation of faces the angular deflection limits the angle between subsequent segments in a polyline\nThe smaller the value, the more grids.'),
228+
default=0.34906585, subtype='ANGLE', unit='NONE', min=0.01745329, step=3, precision=2, update=update_angular_deflection)
229+
230+
relatire: bpy.props.BoolProperty(name=_('Relatire'), description=_('Relative computation of edge tolerance.\nIf activated, deflection used for the polygonalisation of each edge will be ChordalDeflection X SizeOfEdge.The deflection used for the faces will be the maximum deflection of their edges.'),
231+
default=False, update=update_relatire)
232+
139233
# global_scale : FloatProperty(
140234
# name='Scale',
141235
# description='Value by which to enlarge or shrink the objects with respect to the world origin',
@@ -195,6 +289,12 @@ class MayoConvPreferences(bpy.types.AddonPreferences):
195289
default=True,
196290
)
197291

292+
clean_reimport_obj: BoolProperty(
293+
name=_('Automatically delete duplicate imported objects.'),
294+
description=_('Remove duplicate imported objects with .001 suffixes,如果新导入的物体的无后缀网格名已出现当前场景里,并且网格的顶点数一样,则自动删除新导入的'),
295+
default=False,
296+
)
297+
198298
def draw(self, context):
199299
layout = self.layout
200300
row = layout.box().column(align=True)
@@ -234,8 +334,9 @@ def draw(self, context):
234334
row.label(text=' b) Manually import the CAD file in Mayo')
235335
row.label(text=' c) After optimization, click "Exchange > Save as..." at bottom of Options panel')
236336
row.label(text=' d) Overwrite the mayo-gui.ini file in plugin directory')
237-
row.label(text='3. The meshingQuality parameter in the mayo-gui.ini file can be manually set in the import panel.')
238-
row.label(text='4. Usage: File > Import > STEP/IGES (*.step *.stp *.iges *.igs) or Drag-and-Drop to 3D Viewport')
337+
row.label(text='3. The meshing parameter in the mayo-gui.ini file can be manually set in the import panel.')
338+
row.label(text='4. The exported results of Mayo (GUI app) and mayo-conv may be different, even when using the same settings')
339+
row.label(text='5. Usage: File > Import > STEP/IGES (*.step *.stp *.iges *.igs) or Drag-and-Drop to 3D Viewport')
239340

240341

241342
layout = self.layout
@@ -1118,7 +1219,7 @@ def draw(self, context):
11181219
layout.use_property_split = True
11191220
layout.use_property_decorate = False # No animation.
11201221
pre=get_pre()
1121-
1222+
layout.label(text='Mayo Export')
11221223
# t=_(".obj (by collections)") if pre.geshi == '.obj' else _(".gltf (by parent Empty object)")
11231224
# row=layout.row()
11241225
# row.alert = True
@@ -1127,12 +1228,17 @@ def draw(self, context):
11271228
layout.prop(pre, 'geshi')
11281229

11291230
layout.prop(pre, 'mesh_quality')
1231+
if pre.mesh_quality=='UserDefined':
1232+
layout.prop(pre, 'chordal_deflection')
1233+
layout.prop(pre, 'angular_deflection')
1234+
layout.prop(pre, 'relatire')
11301235

11311236
if bpy.app.version >= (4, 2):
11321237
layout.separator(type="LINE")
11331238
else:
1134-
layout.separator()
1239+
layout.label(text='.....................................................')
11351240

1241+
layout.label(text='Blender Import')
11361242
# row=layout.row()
11371243
# row.alert = True
11381244
# row.alignment = 'RIGHT'.upper()#'EXPAND', 'LEFT', 'CENTER', 'RIGHT'
@@ -1145,7 +1251,7 @@ def draw(self, context):
11451251
if bpy.app.version >= (4, 2):
11461252
layout.separator(type="LINE")
11471253
else:
1148-
layout.separator()
1254+
layout.label(text='.....................................................')
11491255

11501256

11511257
layout.prop(pre, 'del_gltf')
@@ -1155,11 +1261,7 @@ def draw(self, context):
11551261

11561262
def invoke(self, context, event):
11571263
self.start_time = time.time()
1158-
try:
1159-
context.space_data.clip_start=0.001
1160-
context.space_data.clip_end = 100000
1161-
except:
1162-
pass
1264+
11631265

11641266
if len(self.files) > 1:
11651267
self.report({'ERROR'}, _("Single file import only"))
@@ -1233,15 +1335,17 @@ def modal(self, context, event):
12331335

12341336
# 增强文件检查
12351337
if not os.path.exists(output_path):
1236-
self.report({'ERROR'}, f"Can`t found mesh model: {output_path}")
1338+
self.report({'ERROR'}, f"Mayo Convert CAD model failed,Can`t found exported mesh model: {output_path}")
1339+
bpy.context.workspace.status_text_set(None)
12371340
return {'CANCELLED'}
12381341

12391342
# 确保文件可读
12401343
try:
12411344
with open(output_path, 'rb') as f_test:
12421345
pass
12431346
except IOError as e:
1244-
self.report({'ERROR'}, f"Can`t read mesh model: {str(e)}")
1347+
self.report({'ERROR'}, f"Can`t read exported mesh model: {str(e)}")
1348+
bpy.context.workspace.status_text_set(None)
12451349
return {'CANCELLED'}
12461350

12471351
# # 取消所有物体的选择
@@ -1424,6 +1528,13 @@ def execute(self, context):
14241528
return {'CANCELLED'}
14251529

14261530
set_inifile_language()
1531+
1532+
try:
1533+
context.space_data.clip_start=0.001
1534+
context.space_data.clip_end = 100000
1535+
except:
1536+
pass
1537+
14271538
# 构建输出路径
14281539
input_path = os.path.abspath(self.filepath)
14291540
output_dir = os.path.dirname(input_path)
@@ -1527,13 +1638,13 @@ def status_bar_draw(self, context,text,importing=False,):
15271638
layout.label(text="Cancel", icon="EVENT_ESC")
15281639
layout.separator(factor=2.0)
15291640
layout.label(text=f"{text}", icon="TEMP")
1530-
1531-
1641+
15321642

15331643
def sna_add_to_topbar_mt_file_import_4A389(self, context):
15341644
self.layout.operator(IMPORT_OT_STEPtoGLTF.bl_idname, text='STEP/IGES (*.step *.stp *.iges *.igs)',emboss=True, depress=False)
15351645

15361646
#TODO:自动更新网格避免重复导入,拖入多个文件,添加导入预设保存;是否可以让mayo直接转换obj和iges两种,然后让用户一次把2种都导入
1647+
#自动更新网格避免重复导入,比如一个之前已经导入过的,并且新导入的网格数一样(这里要提示导入的网格精度要一致),就直接删除新导入的
15371648

15381649
class IO_FH_Step_Iges(bpy.types.FileHandler):
15391650
bl_idname = "IO_FH_step_iges"
@@ -1588,6 +1699,21 @@ class CADM_mesh_Props(bpy.types.PropertyGroup):
15881699
('*', 'High precision'): '高精度',
15891700
('*', 'Very Precise'): '超高精度',
15901701
('*', 'Highest precision'): '超高精度',
1702+
('*', 'User Defined'): '自定义设置',
1703+
1704+
('*', 'Chordal Deflection(mm)'): '弦高公差(mm)',
1705+
('*', 'For the tessellation of faces the Chordal Deflection limits the distance between a curve and its tessellation\nThe smaller the value, the more grids.'):
1706+
'弦高公差:限制曲线与网格折线间的最大距离\n数值越小网格越多',
1707+
1708+
('*', 'Angular Deflection'): '角度公差',
1709+
('*', 'For the tessellation of faces the angular deflection limits the angle between subsequent segments in a polyline\nThe smaller the value, the more grids.'):
1710+
'角度公差:限制折线相邻线段间的最大角度\n数值越小网格越多',
1711+
1712+
('*', 'Relatire'): '相对公差',
1713+
('*', 'Relative computation of edge tolerance.\nIf activated, deflection used for the polygonalisation of each edge will be ChordalDeflection X SizeOfEdge.The deflection used for the faces will be the maximum deflection of their edges.'):
1714+
'边缘公差的相对计算\n如果激活,每个边缘的多边形化使用的偏差将是ChordalDeflection X SizeOfEdge。面使用的偏差将是其边缘的最大偏差。',
1715+
1716+
15911717
('*', 'Scale Factor'): '缩放系数',
15921718
('*', 'Scaling factor for each object in OBJ format,\nScaling factor of the parent empty object in GLTF format'):
15931719
'OBJ格式导入就是每个物体的缩放系数,\nGLTF格式导入就是父级空物体的缩放系数',
@@ -1611,10 +1737,13 @@ class CADM_mesh_Props(bpy.types.PropertyGroup):
16111737
' c) 调整参数到导入的模型网格符合你的要求后,在Options面板底部点击 Exchange->Save as...',
16121738
('*', ' d) Overwrite the mayo-gui.ini file in plugin directory'):
16131739
' d) 覆盖插件目录下的mayo-gui.ini文件',
1614-
('*', '3. The meshingQuality parameter in the mayo-gui.ini file can be manually set in the import panel.'):
1740+
('*', '3. The meshing parameter in the mayo-gui.ini file can be manually set in the import panel.'):
16151741
'3. mayo-gui.ini文件里的meshingQuality参数可在导入面板里手动设置',
1616-
('*', '4. Usage: File > Import > STEP/IGES (*.step *.stp *.iges *.igs) or Drag-and-Drop to 3D Viewport'):
1617-
'4. 使用方法:文件 > 导入 > STEP/IGES 或 直接拖动模型到3D窗口里',
1742+
1743+
('*', '4. The exported results of Mayo (GUI app) and mayo-conv may be different, even when using the same settings'):
1744+
'4.即使在相同的设置下用Mayo.exe直接手动导出的网格和用插件通过指令后台导出的网格效果可能有差异',
1745+
('*', '5. Usage: File > Import > STEP/IGES (*.step *.stp *.iges *.igs) or Drag-and-Drop to 3D Viewport'):
1746+
'5. 使用方法:文件 > 导入 > STEP/IGES 或 直接拖动模型到3D窗口里',
16181747

16191748
('*', 'Sell a plugin ^_~'): '卖个插件 ^_~',
16201749
('*', 'A plug-in that can be converted between the collection and the empty object hierarchy!'):
@@ -1714,8 +1843,10 @@ class CADM_mesh_Props(bpy.types.PropertyGroup):
17141843
' d) プラグインディレクトリのmayo-gui.iniを上書き',
17151844
('*', '3. The meshingQuality parameter can be auto-configured via import panel settings'):
17161845
'3. meshingQualityパラメータはインポートパネルで自動設定可能',
1717-
('*', '4. Usage: File > Import > STEP/IGES (*.step *.stp *.iges *.igs) or Drag-and-Drop to 3D Viewport'):
1718-
'4. 使用方法:ファイルメニューまたは3Dビューポートへドラッグ&ドロップ',
1846+
('*', '4. The exported results of Mayo (GUI app) and mayo-conv may be different, even when using the same settings'):
1847+
'4. 同じ設定でMayo.exeを使用して直接手動でエクスポートしたメッシュと、プラグインを使用して指令バックグラウンドでエクスポートしたメッシュの効果は異なる場合があります。',
1848+
('*', '5. Usage: File > Import > STEP/IGES (*.step *.stp *.iges *.igs) or Drag-and-Drop to 3D Viewport'):
1849+
'5. 使用方法:ファイルメニューまたは3Dビューポートへドラッグ&ドロップ',
17191850

17201851
('*', 'Sell a plugin ^_~'):
17211852
'プラグイン販売中 ^_~',
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import subprocess
2+
3+
exe = r"F:\Downloads\开源cad模型查看转换软件Mayo-0.9.0-win64-binaries\Mayo-0.9.0-win64-binaries\mayo-conv.exe"
4+
options = r"D:\OP-1.stp"
5+
orig = ['--export', r"D:\OP-1.gltf"]
6+
7+
# 构建命令列表
8+
cmd = [exe, options] + orig
9+
10+
# 打印命令列表以便调试
11+
print(cmd)
12+
13+
如果路径里有空格就整个路径用双引号包裹
14+
mayo-conv.exe --use-settings "C:\Users\CP\AppData\Roaming\Blender Foundation\Blender\Addons_CP\addons\import_cad_model\mayo-gui.ini" X:\1111\2025年后笔记本往台式机转存文件\dji-fpv-o3-camera-unit-1.snapshot.6\DJIO3CAM.step --export D:\111111111111111.obj
15+
16+
mayo-conv.exe X:\1111\2025年后笔记本往台式机转存文件\dji-fpv-o3-camera-unit-1.snapshot.6\DJIO3CAM.step --export D:\111111111111111.obj
17+
18+
## 运行命令
19+
subprocess.run(cmd)
20+
21+
F:\Downloads\开源cad模型查看转换软件Mayo-0.9.0-win64-binaries\Mayo-0.9.0-win64-binaries\mayo-conv.exe --use-settings F:\Downloads\开源cad模型查看转换软件Mayo-0.9.0-win64-binaries\Mayo-0.9.0-win64-binaries\mayo-gui.ini D:\OP-1.stp --export D:\OP-1.gltf
22+
##mayo-conv.exe如何实用软件设置里的网格配置 https://github.com/fougue/mayo/issues/276
23+
mayo-conv --use-settings D:\data\mayo-gui.ini inputfile.step --export outputfile.wrl
24+
25+
mayo-conv.exe D:\白色半透明塑料副本.stp --export D:\OP-1.gltf --no-progress
26+
'''--no-progress可以返回info
27+
F:\Downloads\开源cad模型查看转换软件Mayo-0.9.0-win64-binaries\Mayo-0.9.0-win64-binaries>mayo-conv.exe D:\白色半透明塑料副本.stp --export D:\OP-1.gltf --no-progress
28+
INFO: "Importing..."
29+
CRITICAL: "Error during import of 'D:\\白色半透明塑料副本.stp'\nFile read problem "
30+
31+
成功就是
32+
INFO: "Importing..."
33+
INFO: "Imported"
34+
INFO: "Exporting OP-1.gltf..."
35+
INFO: "Exported OP-1.gltf"
36+
'''
37+
38+
39+
mayo-conv.exe --system-info
40+
'''
41+
F:\Downloads\开源cad模型查看转换软件Mayo-0.9.0-win64-binaries\Mayo-0.9.0-win64-binaries>mayo-conv.exe --system-info
42+
43+
Mayo: v0.9.0 commit:614755f revnum:1366 64bit
44+
45+
OS: Windows 10 Version 2009 [winnt version 10.0.22631]
46+
Current CPU Architecture: x86_64
47+
48+
Qt 5.15.2 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019)
49+
50+
OpenCascade: 7.8.0 (build)
51+
52+
Assimp: 5.4.3 rev:0 branch:? flags:shared|single-threaded
53+
54+
Import(read) formats:
55+
DXF STEP IGES OCCBREP STL GLTF OBJ VRML OFF PLY AMF 3DS 3MF COLLADA FBX X3D Blender X
56+
Export(write) formats:
57+
STEP IGES OCCBREP STL VRML GLTF OBJ OFF PLY Image
58+
'''
59+
60+
61+
F:\Downloads\开源cad模型查看转换软件Mayo-0.9.0-win64-binaries\Mayo-0.9.0-win64-binaries>mayo-conv.exe --help
62+
Usage: mayo-conv.exe [options] [files...]
63+
mayo-conv the opensource CAD converter
64+
65+
Options:
66+
-?, -h, --help Display help on commandline options
67+
-v, --version Display version information
68+
-u, --use-settings <filepath> Use settings file(INI format) for the
69+
conversion. When this option isn't
70+
specified then cached settings are used
71+
-c, --cache-settings Cache settings file provided with
72+
--use-settings for further use
73+
-w, --write-settings-cache <filepath> Write settings cache to an output
74+
file(INI format)
75+
-e, --export <filepath> Export opened files into an output
76+
file, can be repeated for different
77+
formats(eg. -e file.stp -e file.igs...)
78+
--log-file <filepath> Writes log messages into output file
79+
--debug-logs Don't filter out debug log messages in
80+
release build
81+
--no-progress Disable progress reporting in console
82+
output
83+
--system-info Show detailed system information and
84+
quit
85+
86+
Arguments:
87+
files Files to open(import)

0 commit comments

Comments
 (0)