import STL file

Started by
2 comments, last by AverageMidget 13 years, 7 months ago
Hi,
This is my first attempt in programming something of this nature.
I have a 3D model (from Solidworks),. So that means, I have the model information on all the formats as supported by solidworks.
Now, I want to program in C# which can open this 3D model and then if i am able to rotate/select/ pan this model.
How do I go about this.
I dont know what I am asking is trivial or is it a big deal as I have no clue about this thing?
Any help is appreciated..:)
Thanks
Advertisement
Whether it's a big deal or not, is how well you know how to program, and if you're using libraries to help you do the graphical display. In general, yes, it's a big deal.

In an attempt to help answer this complicated question, I'll tell you how I would personally approach the situation. You have a list of tasks you want to achieve: Load model, display model, rotate/select/pan model. I would break those down into separate tasks and work on one at a time (don't even think of the other ones, focus on getting the current one working). You then have a singular task and a much more defined field of thought, for when you're searching Google to find an answer.

My second bit of help would be to explain the pretty simple file structure of the STL file (I assume you mean a stereolithography CAD file).

An STL file is structured is such a way:

1) The first 80 bytes is an ASCII "header", that usually just tells what software created the file. Although, some software like Magics, will store things like color information. Mostly, this section isn't important.

2) The next 4 bytes is an unsigned long integer that tells you how many facets (triangles) are in the file.

3) The next 50 bytes stores the normals, vertex 1, vertex 2, vertex 3, and a little padding. This 50 bytes is broken up as follows:

4 byte float: Normal i
4 byte float: Normal j
4 byte float: Normal k

4 byte float: Vertex 1 x
4 byte float: Vertex 1 y
4 byte float: Vertex 1 z

4 byte float: Vertex 2 x
4 byte float: Vertex 2 y
4 byte float: Vertex 2 z

4 byte float: Vertex 3 x
4 byte float: Vertex 3 y
4 byte float: Vertex 3 z

2 byte unsigned integer: padding

As far as I know, that last 2 byte "padding" isn't used, but I'm no expert on the STL file format (wrote a parser for it not to long ago).

Hope that helps get you started!

Edit:
I guess I wasn't perfectly clear on that 50 byte pattern part. The number you get from the unsigned long integer (section 2, the number of triangles), is the number of times you loop through and read 50 bytes.

[Edited by - AverageMidget on August 31, 2010 10:04:44 PM]
hi,
thanks for replying.
What you told me is of great help..
Is the procedure to load SLDPRT format also the same..
I mean the default format generated by solidworks?
Thanks for helping me out...:)
No, Ma'am/Sir.

As far as I know, the .sldprt format isn't "open" and hasn't been publicly reverse engineered. The format is guaranteed to be different from an STL file. In fact, the .sldprt file is probably different from itself, depending on what version of Solidworks saved it. Trying to open a much newer version of a proprietary file format, in a much older version of the software, usually results in an error.

Your best bet is to export your .sldprt file into a format that is publicly understood (.stl, .iges, etc.). As you may know, Solidworks has an association "tree" for a model and, if you change something about the model (change a fillet to have a different radius, for example), it affects everything associated. You, unfortunately, will lose all of this associative history, when you export the model to another format. If your goal is to use the model and retain all of the Solidworks association (not sure what your ultimate goal is), you might want to look into developing a "plugin" for Solidworks, via their API.

Regarding an STL file: the format I posted about is for the binary STL file (.sltb, explicitly). There is an ASCII STL file (.stla, explicitly), but it's rarely used, due to the much larger file size produced.

This topic is closed to new replies.

Advertisement