[Ch...] Posted February 28 Share Posted February 28 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 More sharing options...
[Ti...] Posted March 3 Share Posted March 3 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 More sharing options...
[Ti...] Posted March 4 Share Posted March 4 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 More sharing options...
[Ja...] Posted June 21 Share Posted June 21 Hi, I am working on a script that should do nearly the same: Exporting the stl files. But I have a problem when the part name isn't 'part'. Then the call elements=gom.ElementSelection ({'category': ['key', 'elements', 'part', gom.app.project.parts['Part'], 'explorer_category', 'actual_part']}), gives back an error. I think it is about this entry: gom.app.project.parts['Part'] Is there a way to tell the command that all parts shall to be used? Link to comment Share on other sites More sharing options...
[Ja...] Posted June 21 Share Posted June 21 If you only have one part can replace 'Part' with 0 . I.e. Returns the first value of the list of part entries . If you have multiple parts you would then need a loop to deal with exporting all of them. Hope that helps James Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in