Skip to main content

Hi All,

Does anyone know how to set the FORMAT for a Generic Writer at run-time? I have a generic reader and want to output to whatever format the input data was. Is there a good way to do this?

 

 

I've tried getting the input fme_format_short_name and using that as an attribute, as well as OUT_FORMAT, OUTPUT, FORMAT, and OUTPUT_FORMAT. But all fail with the tautological:

 

 

ERROR |Generic Writer: Cannot use the Generic writer to create a Generic writer. Please select a different writer for the FORMAT keyword.

 

 

Thoughts? Thanks,

 

Jonathan

 

 

This works.

 

Any help?

 

 

Greetzz.
I'm afraid not. I don't want to set it via a parameter because I don't want the user to have to set it. It'd be easy if I could do that. 🙂
I used tst as filename, but you can make this a parameter as well of course.

 

AttributeCreator becomes:

 

outformat =

 

$(DestDataset_GENERIC)$(FileOut).$(GENERIC_OUT_FORMAT_GENERIC)
Hi,

 

 

I not think it is possible to set the Generic writer format at run-time. Your closest bet is using a published or private parameter (those are evaluated just before run-time).

 

 

David
Gio - Sorry, that's not what I want to do. What I want is to be able to set the output format itself.

 

 

David - Ok. It seems odd that it's not possible as it's a simple use-case.

 

Thanks
Hi Jonathan,

 

 

Just an idea.

 

If the input format could be determined by the file extention of specified source dataset, it might be possible to define a scripted parameter that returns appropriate output format name based on the input format.

 

 

Takashi
Ah, i think you must read the extension into the $(GENERIC_OUT_FORMAT_GENERIC) using a script.

 

 

I think a start-up script would do.

 

 

I tried creating a tcl to do that in a scripted parameter, but run into "ParamFuncinvoked from within" error.
yes i did try that Takashi, using tcl scripted parameter :

 

 

/string range $(SourceDataset_SHAPE) @Evaluate(@Evaluate(tstring length $(SourceDataset_SHAPE)])- 3) @Evaluate(tstring length $(SourceDataset_SHAPE)])]

 

to get the extention and then somehow pass it to set the "$(GENERIC_OUT_FORMAT_GENERIC)" parameter.

 

 

..but all attemtps ended in "ParamFuncinvoked from within" error.

 

 

 

Maybe a startUp script to set it?
Gio, a Scripted (Tcl) Parameter with this script returns the extension of the source dataset, for example.

 

-----

 

return nlindex xsplit $FME_MacroValues(SourceDataset_GENERIC) {.}] end]

 

-----

 

 

FME Functions such as @Evaluate don't work in a Tcl script.

 

And also, in FME 2015, the @Evaluate function will not evaluate Tcl script and string expressions no longer. The function is now only for evaluating a math expression.
Actually in the Evaluates are to Evaluate the tcl functions. And they do work in for instance a creator or a tester. The tcl bit i posted works exactly as intneded when used in a creator &co. And it does return the extension.

 

 

This is not the problem though in the scripted parameter. The problem is it can't reach the parameter "$(SourceDataset_SHAPE)" : "ParamFuncinvoked from within" error

 

 

That is what Jonathan is trying to do. Set output filetype to same as inputfiletype.

 

( i think he has to either use a workspacerunner, or use extension to select one writer using a testfilter wich boils down to basicaly entering writers for all expected possibel filetypes.)

 

 

When fme2015 is rolled out here (next week or so; i accepted and tested the instalation) we will see if i can do away with the @Evaluate.  But if u use nested tcl bits, u need to use @Evaluate(). At least in and up to fme 2014sp2. Nesting is common practice.

 

 

This does not apply however to using tcl in script in a tcl caller; no need for the @Eval there.

 

 

So in a start-up i would not need to use the @Evaluate. This is only needed when used in the transformers.

 

 

(i do hope i can still use tcl in transformers though...if not that would be a big drawback)
My words were shortage.

 

The @Evaluate still evaluates Tcl script in FME 2015. But it will return <null> if the result was non-numeric. So you cannot perform any string operation through @Evaluate+Tcl.
Hi All,

 

is there a way to get the FORMAT from the generic reader and pass it to the generic writer automatically in newer versions of FME somehow?

 


Yes, if you have a generic reader and expose the fme_basename, fme_format_short_name and fme_basename, then use a FeatureWriter, in the Writer Parameters set the Output Format to fme_format_short_name and the Base filename to fme_basename (unless you want a different output file name, in which case set it to an attribute containing that name)

 

 

In the feature type parameters set the Feature Type Name to fme_feature_type, Geometry from Schema Definition, Check off Dynamic Schema, and set the Schema Sources to your generic reader.

 

 

If you would like a different Feature Type Name, then set that to whatever attribute contains the name, but the Schema Definition Name must be set to the fme_feature_type.

Reply