[Ma...] Posted October 10, 2022 Share Posted October 10, 2022 Hi to all, is there a way to dinamically change the default folder? My goal is to automatically go in a specific folder depending from the template I opened for import stl. In Python the current working directory is C:\WINDOWS\System32. Is there a command I can use in a Python script to change temporarily the default folder? Link to comment Share on other sites More sharing options...
[Th...] Posted October 19, 2022 Share Posted October 19, 2022 Hi, where this folder should be used? Or in which way do you end up in C:\WIDNOWS\System32? In a script dialog (At my side I always end up in user directory which is "Documents" by default)? In script dialogs or in interactive commands you can set a default - which you can read from the imported mesh e.g. with gom.app.project.parts['Part'].actual.import_information.file So you cannot change the (default) parameters, by script but in most cases you can provide a default for most script functionality you can create by your own inside the script. Link to comment Share on other sites More sharing options...
[Ma...] Posted November 3, 2022 Author Share Posted November 3, 2022 Everytime I import stl (or g3d) software lead me to the default directory (in my case S:\QUAREP\Controlli), but since I use a template (the name of template is something like 12015591_04_CAD) and in the directory I have a list of folders named as 12015591, where I have the stl, I thought the can be useful and fester to lead the users directly in the correct folder (in this case S:\QUAREP\Controlli\12015591) and not in the default directory (S:\QUAREP\Controlli). For import stl I use this code: RESULT=gom.script.sys.execute_user_defined_dialog (content='<dialog>' \ ' <title>Importa Figure di Riferimento</title>' \ ' <style>Standard</style>' \ ' <control id="OkCancel"/>' \ ' <position>center</position>' \ ' <embedding></embedding>' \ ' <sizemode>automatic</sizemode>' \ ' <size width="271" height="177"/>' \ ' <content rows="2" columns="1">' \ ' <widget rowspan="1" column="0" row="0" type="label" columnspan="1">' \ ' <name>label</name>' \ ' <tooltip></tooltip>' \ ' <text>IMPORTA FIGURE DI RIFERIMENTO</text>' \ ' <word_wrap>false</word_wrap>' \ ' </widget>' \ ' <widget rowspan="1" column="0" row="1" type="input::file" columnspan="1">' \ ' <name>directory2</name>' \ ' <tooltip>Scegli la Cartella</tooltip>' \ ' <type>multi_file</type>' \ ' <title>Scegli la Cartella</title>' \ ' <default></default>' \ ' <limited>true</limited>' \ ' <file_types>' \ ' <file_type description="" name="*.stl *.g3d"/>' \ ' </file_types>' \ ' <file_types_default>*.stl *.g3d</file_types_default>' \ ' </widget>' \ ' </content>' \ '</dialog>') dir2 = RESULT.directory2 print (dir2) for filenames in dir2: print(filenames) base, ext = os.path.splitext(filenames) if ext == '.stl': stlfile = os.path.join(filenames) gom.script.sys.import_stl ( bgr_coding=True, files=[stlfile], import_mode='new_stage', length_unit='mm', stl_color_bit_set=False, target_type='mesh') if ext == '.g3d': g3dfile = os.path.join(filenames) gom.script.sys.import_g3d ( files=[g3dfile], import_mode='new_stage') Is possible to do what I want? Thank you very much in advance! Link to comment Share on other sites More sharing options...
[Th...] Posted November 8, 2022 Share Posted November 8, 2022 Of course. Use "create_user_defined_dialog" instead of "execute_user_defined_dialog": Because there you can dynamically change the dialog's settings. See this code for reference: import gom import os DIALOG=gom.script.sys.create_user_defined_dialog (content='<dialog>' \ ' <title>Importa Figure di Riferimento</title>' \ ' <style>Standard</style>' \ ' <control id="OkCancel"/>' \ ' <position>center</position>' \ ' <embedding></embedding>' \ ' <sizemode>automatic</sizemode>' \ ' <size height="172" width="271"/>' \ ' <content columns="1" rows="2">' \ ' <widget row="0" type="label" rowspan="1" columnspan="1" column="0">' \ ' <name>label</name>' \ ' <tooltip></tooltip>' \ ' <text>IMPORTA FIGURE DI RIFERIMENTO</text>' \ ' <word_wrap>false</word_wrap>' \ ' </widget>' \ ' <widget row="1" type="input::file" rowspan="1" columnspan="1" column="0">' \ ' <name>directory2</name>' \ ' <tooltip>Scegli la Cartella</tooltip>' \ ' <type>multi_file</type>' \ ' <title>Scegli la Cartella</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>') # get your default path from somewhere my_path = r"E:\temp" # do this little trick to really go into the folder my_path = os.path.join (my_path, "_") # change the dialog content dynamically before executing the dialog DIALOG.directory2.default = my_path RESULT=gom.script.sys.show_user_defined_dialog (dialog=DIALOG) 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