onsdag 8. oktober 2014

Text based coordinate files and how to import them to Revit

In Norway we have a format for coordinates that is used by surveyors, consultants and others alike. It has the file extension .kof and I do not think it's very widespread outside our fiordinfested country

Basically this is a text format which have seperators for substrings or subvalues. Like this:
In the example over, 09_91 marks start of a line and 09_99 marks end of line.
Coordinate block (05) - point number (1037) - Theme code(2201) -Xvalue - Yvalue -Zvalue

By doing some prep work before putting this into dynamo, one could take this via excel and importing into dynamo that way, but where is the fun in that?

With some intense googling, cursing and doing other hair loosening activities I found the keys to my problem: Python and the commands re.compile, find.all and DO NOT forget re.dotall*

However, the problem was to find, extract and divide ALL substrings between 09_91 and 09_99, not just the first and last or every nth item.

So here is the syntax:

And that produces this:

Which means we have separated out each specific string between 09_91 and 09_99.
(I guess I could have done this with inputs for other seperators as well rather than writing it as string directly in the code.)
Not entirely sure I've figured out the best way to go from here, but depending on the string structure one could compose a function like this:

From here on I'm not sure what to do. The goal have to be minimum input by others who will use this definition, and in this workflow one would have to duplicate the steps in the first codeblock pr list instance between 09_91 and 09_99. This is very tedious for large coordinatefiles. Hopefully someone have the solution for a more iterative method! :)

As per now it serves the purpose, but it will have to be polished to work as it should.

If anyone have tips or comments on how to solve the iterative part, please do not hesitate to contact me! :)

*re.DOTALL makes the find.all function find all string characters between 09_91 and 09_99 INCLUDING those on new lines in the string, without it: No results but a empty list...

1 kommentar: