CoDEmanX wrote:your exporter is actually part of a modal operator. It has invoke() and execute(), the modal() part is derived from the ExportHelper (i assume you use it?).
In the export helper code, a file selector is added when operator invoked(!). The file selector is a modal operator. When target is chosen, modal() ends and operator goes on with execute(). So it goes invoke() -> modal() -> execute().
For menu entries, it is the default to invoke operators. In other contexts, they are rather executed.
You could skip the invoke() and modal() (=file selector), and directly go on to the execute() which does the export, and pass it a filename or whatever params are required. (This would have been done by the file selector otherwise).
To make a menu entry execute an operator instead of invoking, you need to set .operator_context before adding the operator using .operator() - but both are elements of a UILayout instance! If you set layout.operator_context = ... , it would apply to a couple entries, and not just yours.
So better add a new ui element:
col = layout.column()
col.operator_context = 'EXEC_DEFAULT'
you could even hardcode a filepath into the menu:
props = col.operator("export.your_operators_name")
props.filename = "..." # assuming your operator has a StringProperty "filename"
So, if I didn't use ExportHelper, it wouldn't invoke the file selector?
I want to export to the same directory where the currently open file is located. Currently, the export function already determines what file is open, and then does a little string manipulation to change the extension, then goes ahead with the export.
I also ran into a new problem which probably has something to do with my understanding(or lack thereof) of how python deals with lists.
In order to minimize the amount of information I need to manipulate in the recipient program, I am going through the set of edge_keys for each polygon. The program seems to randomly choose the order in which it represents the endpoints of edges, but does store the edges in the correct order. I am trying to take a copy of the edge_keys, then swap the edge endpoints at each index if adjacent endpoints in the edge_keys list are not equal.
[(1,2),(24,1),(2,24)] -> [(2,1),(1,24),(24,2)] through use of a loop of comparisons, if statements, and endpoint swaps. Then, when adjacent (and wrapped) endpoints are equal, i can just export 1,24,2 and it will properly represent the poly in question.
But it seems when I try to assign values to the individual sub-elements, i get an error about assigning tuples(not in front of my workstation, cant recall the exact language).
this is an example of the kind of thing that I am trying to do in this endpoint
Code: Select all
edges = bpy.data.objects.data.polygons.edge_keys
temp = edges
edges=edges#this is where the problem happens.
I dont have to do it this way, if there's an easier way to do the sort, i'd be interested to see it.