Jump to content
Mr. Carsten Fuetterer

File I/O: How to read a file with a feature

Recommended Posts

Hi,

 

if you want to read data from text or csv files it's fairly simple to do it in a feature definition.

 

We use a simple file like this:

 

post-85-0-15039300-1503303904_thumb.png

 

To start we create a new feature definition:

 

post-85-0-77015200-1503304079_thumb.png

 

In the "create function" tab, we can use the code templates to create a basic control structure:

 

post-85-0-46379700-1503304316_thumb.png

 

The variable "FilePath" is not defined and has to be supplied with an argument. In this case I want the object "file" as an argument. So I comment the first line from the feature and create an new argument:

 

post-85-0-20593800-1503306529_thumb.png

 

The feature code looks like this:

 

post-85-0-48507700-1503306458_thumb.png

 

You can see that a string is  create for each line of the file. So now we have to split this string in order to access the double values. Therefor I use the split command, which has the output of an objectlist. Then I create a point, which accesses each value of that object list:

post-85-0-07589800-1503306464_thumb.png

 

Now we have to store the points for each line inside an extra objectlist.Therefor we create a new list and add the point:

 

post-85-0-22296100-1503306470_thumb.png

 

Finally we create fore example an bsplinecurve, with the new list of points. Additionally encapsulated the while loop into a persistent section in order to visualize the points for each loop. Otherwise we would just see the last point.

 

post-85-0-28079900-1503306477_thumb.png

 

Now we create the feature from the feature definition:

 

post-85-0-95433300-1503306124_thumb.png

 

 

We set the path to the reference file:

post-85-0-26076600-1503306842_thumb.png

 

 

This nice dialog only appeared, because we didn't allow expressions for the argument inside the feature definition:

post-85-0-24005500-1503306853_thumb.png

 

The final curve:

post-85-0-65761700-1503306617_thumb.png

 

I hope this helps you to create you own custom file reader.

 

best regards

 

Carsten

 

 

 

 

 

readTextFile.fdb

data.zip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...