Jump to content

Dinamically change the default folder


---
 Share

Recommended Posts

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

  • 2 weeks later...

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

  • 3 weeks later...

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

Of course.

Use "create_user_defined_dialog" instead of "execute_user_defined_dialog":
image.png.34bce394ea3b47635d590de01b9fede8.png

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

 Share

×
×
  • Create New...