Jump to content

Import any file using script


---
 Share

Recommended Posts

Hello, how can I import any file (for example g3d or stl) using a script? Now I am using this:

gom.interactive.sys.import_g3d (
	
	import_mode='new_stage')

but with this I can import only g3d. What code should I use? Thank you very much.

Link to comment
Share on other sites

Hi,

there is no general command where you can import an arbitrary file into our software. The different files allow different operations/target for importing and therefore this is not possible. You have to program this on your own: Dialog for selecting a file, make the decision which kind of file you have and last but not least you have to call the correct import command (directly scripted).

Regards,

Bernd

Link to comment
Share on other sites

Thank you! The truth is that i'm a new with gom script and I want to learn something. Where can I found some information about?

Link to comment
Share on other sites

I wrote in the non right way. I want to import both g3d, and stl file via script. If I use

gom.interactive.sys.import_g3d (
	
	import_mode='new_stage')

I can import ONLY g3d and I have to import, if necessary, stl file. Is it possible using script?

Link to comment
Share on other sites

Hi,

the easiest way is to start the recording and to record how you interactively import a sample STL-file. Stop the recording and afterwards you can edit the recorded script to a more general usage.

Hope this helps?!

Regards

Link to comment
Share on other sites

Thank you, the problem is that I don't know the general command. I don't know how to tell to the software to use the command

gom.interactive.sys.import_g3d 

IF I find g3d and use

gom.interactive.sys.import_stl

IF I find stl. I don't know if I've made myself clear.

 

Thank you very much.

Link to comment
Share on other sites

Please sign in to view this quote.

Marco,

I have a few scripts I've written that do what I think you're looking for. Have you already created a GOM dialog to select the file you're importing? In my script, I check the end of the imported filename with python's ".endswith()" string method and call the appropriate import command based on the file extension. In short, it looks something like this:

filename = #Whatever the return value for your import dialog is

if filename.endswith('.g3d'):
	gom.interactive.sys.import_g3d
elif filename.endswith('.stl'):
	gom.interactive.sys.import_stl 

I don't know that it's the most foolproof method, but it has worked well for my uses thus far. Hope this helps!

Regards,

Michael Henson

Link to comment
Share on other sites

Good morning Marco,

Just to try to help.

I would do what Bernd has suggested - take a recording of importing of g3d and stl.

The reason is that this captures all the syntax behind.

In the example Michael has given i dont know if it will work properly.

A good example is that the stl import has syntax for mm or inches , clearly this is important!

When you have the syntax then can substitute into the if statement.

Hope this helps

Link to comment
Share on other sites

Please sign in to view this quote.

Hi! I tried, but I don't know why it doesn't work. I insert a dialog for import file. This is the screenshot.

CopyQ.yiHqYp.png

Link to comment
Share on other sites

Hello Marco,

there is no definition of the file in line 50 (location on the hard drive) - this should be entered in your dialog. I would recommend to have a look at our FAQ articles regarding basic scriping functions like dialogs:
https://connect.gom.com/label/GKB/scripting

We also have a training "Python Scripting for GOM Applications" on training.gom.com here:
https://training.gom.com/course/574615

Regards,
Nanno

Link to comment
Share on other sites

Hi Marco, i completely agree with Nanno.  I think you need to get a good base level understanding on how to work with python/gom before launching into anything with any complexity.

 

To give short hints

Things with # in front of them are comments .  They will not be processed by the script

They are primarily there to mark out your code for future ease of reading

Does your dialogue box look correct and you are able to choose a file ?  In the dialog box creator the box that has the file to choose has a name , given on the right

hand side of the dialog creator.

It is this name youll need to reference 

So lets say its name was "nameoffilepathobject"

- Needed code will look something like:

Filepath =DIALOG.nameoffilepathobject

 

Im going to assume that you intend to write something that cycles through a directory to do something? 

This is possible , but being honest I also feel that it would be difficult to give the right level of hints through the forum and without you having a base level understanding of coding in GOM. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...