Skip to main content

Hi,

I know that you can set new attribute names and new attribute values using a list attributes as such:

attribute{0}.name

attribute{0}.fme_data_type

But how do I set the value of this new attribute?

Is it something like:

attribute{0}.value?

Thanks

You simply treat it as if it was any other attribute. In an AttributeManager:

0684Q00000ArLOjQAN.png

Or in Python:

feature.setAttribute('attribute{0}.name', 'MyAttributeName')
feature.setAttribute('attribute{0}.fme_data_type', 'fme_varchar(64)')
feature.setAttribute('MyAttributeName', 'MyAttributeValue')

Here's a sample workspace (FME 2017) that I hope makes it clearer. Output looks like:

dynamic-excel.fmw


Here's a sample workspace (FME 2017) that I hope makes it clearer. Output looks like:

dynamic-excel.fmw

I'd provide another example that describes how a schema feature can be defined separately from data features and how it works.

 

dynamic-excel-with-schema-feature.fmw (FME 2017.1)

 


I think the part you need is how to dynamically create attribute names. I would use 2 AttributeCreators. The first to create the attribute name, the second to create an attribute with this name.

00-create-schema-feature2017.fmw


I'd provide another example that describes how a schema feature can be defined separately from data features and how it works.

 

dynamic-excel-with-schema-feature.fmw (FME 2017.1)

 

Excellent, that's a cleaner solution for sure, although perhaps slightly more complicated to implement for beginners since you have to be super careful about the schema feature coming first.

I think the part you need is how to dynamically create attribute names. I would use 2 AttributeCreators. The first to create the attribute name, the second to create an attribute with this name.

00-create-schema-feature2017.fmw

I'm not sure that would work, as-is...

You simply treat it as if it was any other attribute. In an AttributeManager:

0684Q00000ArLOjQAN.png

Or in Python:

feature.setAttribute('attribute{0}.name', 'MyAttributeName')
feature.setAttribute('attribute{0}.fme_data_type', 'fme_varchar(64)')
feature.setAttribute('MyAttributeName', 'MyAttributeValue')
Ok I finally understand!  When I use the function name that I put as the Attribute Value for attribute{0}.name as the 'Output Attribute' and then gave it a value, it did work.  Thanks for all your help.  Sorry I was a bit slow catching on to the concept!

 

 


Ok I finally understand! When I use the function name that I put as the Attribute Value for attribute{0}.name as the 'Output Attribute' and then gave it a value, it did work. Thanks for all your help. Sorry I was a bit slow catching on to the concept!

 

 

Excellent! Let me just say that I agree that this isn't exactly trivial...

 

Feel free to vote for this idea to improve the experience: https://knowledge.safe.com/idea/19730/introduce-new-transformer-to-modify-schema-easily.html
Excellent! Let me just say that I agree that this isn't exactly trivial...

 

Feel free to vote for this idea to improve the experience: https://knowledge.safe.com/idea/19730/introduce-new-transformer-to-modify-schema-easily.html
Hi @david_r I have a completely different FME workbench to the one I was developing when I initially wrote this question, but I am trying to do the exact same type of thing as in this thread. I have set all my attribute{0}.name, attribute{0}.fme_data_type and 'MyAttributeName' attributes in AttributeManager. When I run the workbench I can see in the log that these attributes are all being populated correctly. However, the excel spreadsheet that I am trying to write to is not being created and I am getting this error:

 

 

'ERROR |XLSX Writer: No DEF line could be found for feature type 'test'. If you are using dynamic schemas, ensure that the fme_feature_type attribute exists on the incoming feature and corresponds to a valid feature type definition'

 

 

Even if I set the Excel Sheet name to 'fme_feature_type', I still get an error. Any ideas as to what the problem could be?

 


Hi @david_r I have a completely different FME workbench to the one I was developing when I initially wrote this question, but I am trying to do the exact same type of thing as in this thread. I have set all my attribute{0}.name, attribute{0}.fme_data_type and 'MyAttributeName' attributes in AttributeManager. When I run the workbench I can see in the log that these attributes are all being populated correctly. However, the excel spreadsheet that I am trying to write to is not being created and I am getting this error:

 

 

'ERROR |XLSX Writer: No DEF line could be found for feature type 'test'. If you are using dynamic schemas, ensure that the fme_feature_type attribute exists on the incoming feature and corresponds to a valid feature type definition'

 

 

Even if I set the Excel Sheet name to 'fme_feature_type', I still get an error. Any ideas as to what the problem could be?

 

By far the easiest way to debug this is to manually create a small Excel sample file that demonstrates what you need and then read it using the "Schema (Any format)" reader. If you send the output to the Inspector you should find all the necessary attributes with their correspondig values there. I use this technique a lot when I'm not quite certain what FME expects when using dynamic writers..
By far the easiest way to debug this is to manually create a small Excel sample file that demonstrates what you need and then read it using the "Schema (Any format)" reader. If you send the output to the Inspector you should find all the necessary attributes with their correspondig values there. I use this technique a lot when I'm not quite certain what FME expects when using dynamic writers..
Hi @david_r

 

Thanks. I created the sample Excel File and read it using the Schema (Any format) reader. The results are below. I'm not sure how this will help me debug though...

 

 

Sample Excel File

 

BOROUGHROAD_DESC0.25m to 0.5m_AREA_M20.1m to 0.25m_AREA_M2Test boroughTest road description546.222111122.8766Schema (Any Format) Reader output in Inspector

 

fme_feature_type_namefme_format_long_namefme_format_short_namefme_basenameSheet1Microsoft ExcelXLSXRTEST_SCHEMASheet2Microsoft ExcelXLSXRTEST_SCHEMASheet3Microsoft ExcelXLSXRTEST_SCHEMAThanks,

 

 


Hi @david_r

 

Thanks. I created the sample Excel File and read it using the Schema (Any format) reader. The results are below. I'm not sure how this will help me debug though...

 

 

Sample Excel File

 

BOROUGHROAD_DESC0.25m to 0.5m_AREA_M20.1m to 0.25m_AREA_M2Test boroughTest road description546.222111122.8766Schema (Any Format) Reader output in Inspector

 

fme_feature_type_namefme_format_long_namefme_format_short_namefme_basenameSheet1Microsoft ExcelXLSXRTEST_SCHEMASheet2Microsoft ExcelXLSXRTEST_SCHEMASheet3Microsoft ExcelXLSXRTEST_SCHEMAThanks,

 

 

That's only the static attributes. Don't forget to "inspect" each feature by selecting a line and looking at the attributes in the Feature Information windows, that's where you'll find the dynamic (run-time) attributes.

 

 


Hi @david_r

 

Thanks. I created the sample Excel File and read it using the Schema (Any format) reader. The results are below. I'm not sure how this will help me debug though...

 

 

Sample Excel File

 

BOROUGHROAD_DESC0.25m to 0.5m_AREA_M20.1m to 0.25m_AREA_M2Test boroughTest road description546.222111122.8766Schema (Any Format) Reader output in Inspector

 

fme_feature_type_namefme_format_long_namefme_format_short_namefme_basenameSheet1Microsoft ExcelXLSXRTEST_SCHEMASheet2Microsoft ExcelXLSXRTEST_SCHEMASheet3Microsoft ExcelXLSXRTEST_SCHEMAThanks,

 

 

hmm..I have looked at all the Attributes in the Feature Information window but what I have set in my Attribute Manager appears to be ok based on the comparison. I think my issue is related to the fme_feature_type attribute..

 

 


hmm..I have looked at all the Attributes in the Feature Information window but what I have set in my Attribute Manager appears to be ok based on the comparison. I think my issue is related to the fme_feature_type attribute..

 

 

Also make sure that you've told the output feature class to use the schema feature and not any of the reader schemas.

 

 

You should probably also set fme_feature_type_name = fme_feature_type
hmm..I have looked at all the Attributes in the Feature Information window but what I have set in my Attribute Manager appears to be ok based on the comparison. I think my issue is related to the fme_feature_type attribute..

 

 

I also get this error message, if this helps:

 

 

WARN |Cannot define schema for 'RP_200' as the feature does not contain schema information, and schema source is set to 'Schema from Schema Feature'. Please verify writer feature type configuration.
2018-01-29 15:52:08| 25.4| 0.0|INFORM|FME API version of module 'XLSXW' matches current internal version (3.8 20170315)

 

 

 


I also get this error message, if this helps:

 

 

WARN |Cannot define schema for 'RP_200' as the feature does not contain schema information, and schema source is set to 'Schema from Schema Feature'. Please verify writer feature type configuration.
2018-01-29 15:52:08| 25.4| 0.0|INFORM|FME API version of module 'XLSXW' matches current internal version (3.8 20170315)

 

 

 

Yep I have the Dynamic Schema Definition set as per your screen shot. Where do I set 'fme_feature_type_name'? I set it in the Attribute Manager but I am still having the same errors...

 

 

I am reading in three separate files as part of this workflow. I have only exposed fme_feature_type for the file from which I am using the geometry. Could this be causing any issues?

 

 


Yep I have the Dynamic Schema Definition set as per your screen shot. Where do I set 'fme_feature_type_name'? I set it in the Attribute Manager but I am still having the same errors...

 

 

I am reading in three separate files as part of this workflow. I have only exposed fme_feature_type for the file from which I am using the geometry. Could this be causing any issues?

 

 

It's getting complicated to follow what you're doing... 😉 Create a dummy workspace with a FeatureReader that reads your test workspace. Connect an Inspector to both the Schema and the feature output ports and analyze closely what's going on. You need to do exactly the same thing in your workspace.
Hi @david_r I have a completely different FME workbench to the one I was developing when I initially wrote this question, but I am trying to do the exact same type of thing as in this thread. I have set all my attribute{0}.name, attribute{0}.fme_data_type and 'MyAttributeName' attributes in AttributeManager. When I run the workbench I can see in the log that these attributes are all being populated correctly. However, the excel spreadsheet that I am trying to write to is not being created and I am getting this error:

 

 

'ERROR |XLSX Writer: No DEF line could be found for feature type 'test'. If you are using dynamic schemas, ensure that the fme_feature_type attribute exists on the incoming feature and corresponds to a valid feature type definition'

 

 

Even if I set the Excel Sheet name to 'fme_feature_type', I still get an error. Any ideas as to what the problem could be?

 

Ok I have done that. The only differences I can see are as follows:

 

 

1. In my output attributes, all my attributes have "(encoded: utf-8)" after them. Eg: "attribute(0).name (encoded: utf-8)", whereas when I inspect the FeatureReader using the sample excel file, it says "attribute{0}.name (string)".

 

 

2. The FeatureReader inspector outputs a "attribute{0].native_data_type (string)" feature which I have not defined in my real workspace. Do I need to generate these for all the attributes?

 

 

Also, one question: What do I set the "fme_feature_type" and "fme_feature_type_name" to? At the moment I have set them to the name of the Sheet I am outputting in Excel. But should they be set to something else?

 

 

 


Ok I have done that. The only differences I can see are as follows:

 

 

1. In my output attributes, all my attributes have "(encoded: utf-8)" after them. Eg: "attribute(0).name (encoded: utf-8)", whereas when I inspect the FeatureReader using the sample excel file, it says "attribute{0}.name (string)".

 

 

2. The FeatureReader inspector outputs a "attribute{0].native_data_type (string)" feature which I have not defined in my real workspace. Do I need to generate these for all the attributes?

 

 

Also, one question: What do I set the "fme_feature_type" and "fme_feature_type_name" to? At the moment I have set them to the name of the Sheet I am outputting in Excel. But should they be set to something else?

 

 

 

No 1: That shouldn't make any difference.

 

No 2: Yes, I'd try it, but I'm not sure that's really the problem

 

No 3: Yes, the name of the sheet should be ok.

 

I also recommend you look (again?) at the sample workspace I've posted elsewhere in this thread.
No 1: That shouldn't make any difference.

 

No 2: Yes, I'd try it, but I'm not sure that's really the problem

 

No 3: Yes, the name of the sheet should be ok.

 

I also recommend you look (again?) at the sample workspace I've posted elsewhere in this thread.
Still no luck. I understand what your sample workspace is doing and I thought I was replicating it.

 

 

Are you able to tell me what this error message means: 'No DEF line could be found for feature type 'xxx'?

 

 


Still no luck. I understand what your sample workspace is doing and I thought I was replicating it.

 

 

Are you able to tell me what this error message means: 'No DEF line could be found for feature type 'xxx'?

 

 

Sorry, no idea. But if you can re-create the error in a very minimal workspace and post it here, I could have a look at it.
Still no luck. I understand what your sample workspace is doing and I thought I was replicating it.

 

 

Are you able to tell me what this error message means: 'No DEF line could be found for feature type 'xxx'?

 

 

Actually, it could mean that the writer is looking for the schema definition for the feature type "xxx" but was unable to find it.

 

Make sure that your schema feature comes before any data features!
Still no luck. I understand what your sample workspace is doing and I thought I was replicating it.

 

 

Are you able to tell me what this error message means: 'No DEF line could be found for feature type 'xxx'?

 

 

I put the schema feature first but that didn't seem to make a difference. I have posted a new question asking about the 'DEF Line' error here in case someone can shed light on it:

 

https://knowledge.safe.com/questions/62902/error-no-def-line-could-be-found-for-feature-type.html

 

In the meantime I will try to recreate the error in a minimal workspace.

 

Thanks,

 

 


I put the schema feature first but that didn't seem to make a difference. I have posted a new question asking about the 'DEF Line' error here in case someone can shed light on it:

 

https://knowledge.safe.com/questions/62902/error-no-def-line-could-be-found-for-feature-type.html

 

In the meantime I will try to recreate the error in a minimal workspace.

 

Thanks,

 

 

Good, I'll have a look at it.

Reply