Jump to content

Script for import g3d and stl


---
 Share

Recommended Posts

Hello,

I have this script:

# -*- coding: utf-8 -*-

import gom
import os


RESULT=gom.script.sys.execute_user_defined_dialog (content='<dialog>' \
' <title>List files in a folder</title>' \
' <style>Standard</style>' \
' <control id="OkCancel"/>' \
' <position></position>' \
' <embedding></embedding>' \
' <sizemode></sizemode>' \
' <size width="182" height="107"/>' \
' <content rows="1" columns="1">' \
'  <widget rowspan="1" row="0" column="0" columnspan="1" type="input::file">' \
'   <name>directory</name>' \
'   <tooltip>Klick to select a folder</tooltip>' \
'   <type>directory</type>' \
'   <title>Choose Folder</title>' \
'   <default></default>' \
'   <limited>false</limited>' \
'   <file_types/>' \
'   <file_types_default></file_types_default>' \
'  </widget>' \
' </content>' \
'</dialog>')

dir = RESULT.directory
for (basepath, subfolders, filenames) in os.walk(dir):
	for filename in filenames:
		base, ext = os.path.splitext(filename)
		if ext == '.stl':
			stlfile = os.path.join(basepath, filename)
			gom.script.sys.import_stl (
				bgr_coding=True, 
				files=[stlfile], 
				import_mode='clipboard', 
				length_unit='mm', 
				stl_color_bit_set=False, 
				target_type='mesh')
		if ext == '.g3d':
			g3dfile = os.path.join(basepath, filename)
			gom.script.sys.import_g3d (
				files=[g3dfile], 
				import_mode='clipboard')

and with this I can import a "Existing Folder" with both stl and g3d files inside. But I have to modify this script to select "Multiple existing files". I have modified the dialog as shown in the images, but it doesn't work. Someone could help me?

 

Thank you very much.

CopyQ.QXbibo.png

CopyQ.xvaDCn.png

Link to comment
Share on other sites

Hello,

I've modified your script:

# -*- coding: utf-8 -*-

import gom
import os

RESULT=gom.script.sys.execute_user_defined_dialog (content='<dialog>' \
' <title>List files in a folder</title>' \
' <style>Standard</style>' \
' <control id="OkCancel"/>' \
' <position></position>' \
' <embedding></embedding>' \
' <sizemode></sizemode>' \
' <size height="159" width="305"/>' \
' <content rows="1" columns="1">' \
'  <widget columnspan="1" row="0" rowspan="1" column="0" type="input::file">' \
'   <name>directory</name>' \
'   <tooltip>Klick to select a folder</tooltip>' \
'   <type>multi_file</type>' \
'   <title>Choose Folder</title>' \
'   <default></default>' \
'   <limited>true</limited>' \
'   <file_types>' \
'    <file_type name="*.stl *.g3d" description=""/>' \
'   </file_types>' \
'   <file_types_default>*.stl *.g3d</file_types_default>' \
'  </widget>' \
' </content>' \
'</dialog>')

dir = RESULT.directory
for filename in dir:
	print(filename)
	base, ext = os.path.splitext(filename)
	if ext == '.stl':
		stlfile = os.path.join(filename)
		gom.script.sys.import_stl (
			bgr_coding=True, 
			files=[stlfile], 
			import_mode='clipboard', 
			length_unit='mm', 
			stl_color_bit_set=False, 
			target_type='mesh')
	if ext == '.g3d':
		g3dfile = os.path.join(filename)
		gom.script.sys.import_g3d (
			files=[g3dfile], 
			import_mode='clipboard')

Regards,

Marcus

Link to comment
Share on other sites

 Share

×
×
  • Create New...