user2479356
user2479356

Reputation:

Read STEP file (text) and convert to xml

I am currently working on a converter that is supposed to convert STEP files into my own XML in C#. I am struggling with the approach of extracting the data out of the STEP file. For easier use I changed the format from .step/.stp to .txt.

Roughly a STEP file is build of SHAPES, which are created from ADVANCED_SURFACES, which are again created from PLANES and so on. They all contain references to other lines.

...
#33=CLOSED_SHELL('',(#34,#35,#36,#37,#38,#39));
#34=ADVANCED_FACE('',(#46),#40,.F.);
...
#40=PLANE('',#127);
...

Would it be better to read all shapes first, then use it's values to find the surfaces (re-read it), then planes, etc. or is it simpler / faster to read all lines once, store them in a dictionary and then use the dictionary to find all values? Am I on the wrong track? Are the other/better approaches?

Upvotes: 1

Views: 5014

Answers (1)

user1318499
user1318499

Reputation: 1354

Read all entity instances (the things like #40=PLANE('',#127); ) into a dictionary first. There are often multiple references to the same entity instance so you would get a lot of redundancy if you just followed all the chains of references. Even if you want all that redundancy in your output, it will be much slower (O(n^2)) without a dictionary.

Entity instances are often formatted as lines but line breaks are optional and can be anywhere so don't use them for parsing. Parse it properly by following ISO 10303-21 https://www.steptools.com/stds/step/IS_final_p21e3.html . You can do that with a simple recursive descent parser.

Upvotes: 0

Related Questions