Jump to content

Exporting .stl from .ginspect


---
 Share

Recommended Posts

Hello - I'm looking for advice on how to script or if it is possible to script the export of a .stl mesh from a .ginspect file?

We have hundreds of .ginspect files that are too large to keep. In an effort to save storage, i am going to export only the .stl mesh from these files. 

Is there a way to script this to streamline the process? Thanks!

Link to comment
Share on other sites

---

If all your ginspect files are in different folders than there are more advanced ways to cycle through them all and keep them where they are supposed to be, but I'd have to invoice you for that 😉

For the below to work all your ginspect files should be in one folder, then all the stl files will get export to the export folder you choose:

The below program will open each program, export the stl, remove it, then re-save it without the stl.  Test on three programs in a temporary folder to start with, preferably one with mm and one with inches. to make sure the default unit selection in the code works, otherwise you gotta retrieve that from the program and pass it into the function, but that is easy.

 

import gom


ginspect_folder_path = r'C:\replace with your path'
stl_folder_path = r'C:\replace with your path'

# build list of ginspect files
ginspect_files = [file for file in os.listdir(ginspect_folder_path) if file.endswith('.ginspect')]


for i in ginspect_files:
	
	# load project
	gom.script.sys.load_project (file=ginspect_folder_path + "/" + i)
	
	# get stl name
	stl_name = gom.app.project.parts['Part'].actual.name

	gom.script.cad.show_element_exclusively (elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'],        'explorer_category', 'actual_part']}))

	gom.script.sys.export_stl (
		bgr_coding=False, 
		binary=True, 
		color=False, 
		elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'actual_part']}), 
		export_in_one_file=True, 
		export_stages_mode='current', 
		file= stl_folder_path + '/' + stl_name, 
		length_unit='default', 
		set_stl_color_bit=False)
		
	print(f'{stl_name} exported successfully')
	
	gom.script.cad.delete_element (
		elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'actual_part']}), 
		with_measuring_principle=True)
	
	gom.script.sys.save_project ()
	gom.script.sys.close_project ()
	
	print(f'{i} program saved successfully')

 

Link to comment
Share on other sites

---

i didn't add import os to the top...so here is the completed version:

import gom
import os


ginspect_folder_path = r'C:\replace with your path'
stl_folder_path = r'C:\replace with your path'

# build list of ginspect files
ginspect_files = [file for file in os.listdir(ginspect_folder_path) if file.endswith('.ginspect')]


for i in ginspect_files:
	
	# load project
	gom.script.sys.load_project (file=ginspect_folder_path + "/" + i)
	
	# get stl name
	stl_name = gom.app.project.parts['Part'].actual.name

	gom.script.cad.show_element_exclusively (elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'],        'explorer_category', 'actual_part']}))

	gom.script.sys.export_stl (
		bgr_coding=False, 
		binary=True, 
		color=False, 
		elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'actual_part']}), 
		export_in_one_file=True, 
		export_stages_mode='current', 
		file= stl_folder_path + '/' + stl_name, 
		length_unit='default', 
		set_stl_color_bit=False)
		
	print(f'{stl_name} exported successfully')
	
	gom.script.cad.delete_element (
		elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'actual_part']}), 
		with_measuring_principle=True)
	
	gom.script.sys.save_project ()
	gom.script.sys.close_project ()
	
	print(f'{i} program saved successfully')

 

 

Link to comment
Share on other sites

 Share

×
×
  • Create New...