Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot open stp file in python #121

Closed
tady57 opened this issue Dec 14, 2017 · 16 comments
Closed

Cannot open stp file in python #121

tady57 opened this issue Dec 14, 2017 · 16 comments

Comments

@tady57
Copy link

tady57 commented Dec 14, 2017

Dear pygmsh and python users, I have connected pygmsh, vtk files,paraview , python and gmsh. My question is how to connect .stp file with python. Inside of that file I have geometry which I have to use to create mesh. I do not know what all text in .stp file mean so I have not tried to read line by line from .stp file yet.

@nschloe
Copy link
Owner

nschloe commented Dec 14, 2017

Never heard of stp. This is pygmsh, so it only reads gmsh's .geo files. If you need any other format, you'll have to get back to gmsh's developers. I don't think they'll implement a whole new format though.

@nschloe nschloe closed this as completed Dec 14, 2017
@gdmcbain
Copy link
Contributor

I suspect 'stp' is an MS-DOS-style three-letter suffix for STEP a three-dimensional CAD format described in ISO 10303.

Gmsh can read STEP; the .geo command is

Merge "thing.stp";

However, one can't do much with it after that beyond marking Physical Surfaces for boundary conditions, &c.; see ‘Can I edit STEP/IGES/BRep models?' in Gmsh's FAQ.

Therefore, I don't think it's a very good fit for pygmsh, probably best left out; just use Gmsh directly.

I have been thinking about STEP this week though for a couple of reasons: parsing and writing.

Parsing:

I do not know what all text in .stp file mean so I have not tried to read line by line from .stp file yet.

I did have a go at this a little while ago as some STEP that I was handed, generated by SolidWorks, was so bad (topologically & geometrically: numerous distinct exactly coincident points, more nearly coincident points separated by picometres, lots of collinear and nearly collinear lines, &c.) that I had to parse it to clean it up before the Merge in Gmsh. Not having access to ISO 10303 or any other description of the format (anyone know of one?), I did study enough of the body of the files to work out how to extract points, lines, and circular arcs using pyparsing. It was quite laborious and only partially rewarding. I could share some of those learnings if of interest, but they're far from complete and not really industrially robust; I still had to manipulate the geometry interactively in the Gmsh GUI in most cases.

Writing:

The other thing that I was thinking was using the partial knowledge of the format gained above, making a sibling of pygmsh.built_in.Geometry whose methods .add_point, .add_line, .add_circular_arc would write STEP (or some other CAD format). The pygmsh description is nice enough to work with but .geo output isn't much use for anything besides meshing in Gmsh.

One way to read and write STEP in Python is with FreeCAD, though I haven't been able to compile it for Python 3 as yet and the Python interface is not complete. Both Gmsh and FreeCAD use OpenCASCADE internally to deal with STEP and there are some Python interfaces to this which may be of use, though again, this would probably be quite separate from the concerns of pygmsh.

(I haven't yet tried SetFactory("OpenCASCADE") in Gmsh or the corresponding pygmsh.opencascade module; are they relevant here?)

@gdmcbain gdmcbain mentioned this issue Dec 14, 2017
@tady57
Copy link
Author

tady57 commented Dec 15, 2017

@gdmcbain
Thank you very much for your answer. I am relatively new in all this. I have made .geo file from .stp with gmsh, now I am trying to open it with python to collect the data. The goal is somehow to use data from .stp or .geo files in python ,put them in the vectors and from python activate gmsh and create mesh.
Is that make any sense?(I have to do it in that order because of my project)

@nschloe
Copy link
Owner

nschloe commented Dec 15, 2017

I have made .geo file from .stp with gmsh

No need for pygmsh then! Simply run

gmsh input.geo

on the command line (possibly with some options) and you'll get a msh file. This you can read into Python with meshio.

@tady57
Copy link
Author

tady57 commented Dec 15, 2017

@nschloe

Yeah, I noticed that but my professor insists that I have to make mesh directly from the python with data in .stp (or now .geo file). So confused now...

@nschloe
Copy link
Owner

nschloe commented Dec 15, 2017

So confused now...

Yeah, me too. I don't get it. What does

directly from the python

mean? You already have the geometry, right?

@tady57
Copy link
Author

tady57 commented Dec 16, 2017

@nschloe

Thank you for your patience.

My proffesor gave me this kind of task:
for example this is the code from python(pygmsh example) and I have to change these vectors(points) with data from .stp(.geo) file and then make mesh with all condition. Does that make sense?

poly = geom.add_polygon([
    [0.0,   0.5, 0.0],
    [-0.1,  0.1, 0.0],
    [-0.5,  0.0, 0.0],
    [-0.1, -0.1, 0.0],
    [0.0,  -0.5, 0.0],
    [0.1,  -0.1, 0.0],
    [0.5,   0.0, 0.0],
    [0.1,   0.1, 0.0]
    ],
    lcar=0.05
    )

@nschloe
Copy link
Owner

nschloe commented Dec 16, 2017

I see. The advantage of this approach would be that you can manipulate the geometry in pygmsh. The disadvantage: You'll have to translate the geometry given in the stp (or geo) file into Python (pygmsh) first. I've done this for a bunch of geo files before. -- In fact, that was the original motivation for writing pygmsh. Anyhow, there's no tool I know of that can help you with that. You'll need to look at the geo file and translate it manually.

@tady57
Copy link
Author

tady57 commented Dec 16, 2017

@nschloe

I've done this for a bunch of geo files before

I am sorry , I did not understand - you translated that files manually? Good old "copy-paste and adaptation" method? :)

Thank you very much for your time and answers

@nschloe
Copy link
Owner

nschloe commented Dec 16, 2017

Yes.

@tady57
Copy link
Author

tady57 commented Dec 16, 2017

Ok, have a nice day

@gdmcbain gdmcbain mentioned this issue Dec 21, 2017
@tady57
Copy link
Author

tady57 commented Dec 27, 2017

Hi, I have translated all geo file data except ruled surfaces. There is no command for adding ruled surface to geometry(at least in last editions). If I use geom.add_surface command it is not working(gmsh reports errors), but if I change manually "Surface" into "Ruled Surface" in geo file( after code execution) gmsh does not report any errors. However I am not allowed to do that. Do you have any advice?(If this should be another topic I will erase this and open a new one).

@nschloe
Copy link
Owner

nschloe commented Jan 2, 2018

You should first remove Ruled Surface from your geo files, they are deprecated (see here). Best donsider the gmsh mailing list on how to do that. (I'm no expert on this either.)

@tady57
Copy link
Author

tady57 commented Jan 2, 2018

Ok, thank you. Happy new year :)

@SaimaSafdar
Copy link

I have made .geo file from .stp with gmsh

No need for pygmsh then! Simply run

gmsh input.geo

on the command line (possibly with some options) and you'll get a msh file. This you can read into Python with meshio.

Hi nschloe,
I am new to pygmsh. Actually I need to open the .stl file. I need to read the geometry in the file and create a mesh out of that geometry. is it possible to do it using pygmsh. Previously I used gmsh-api not pygmsh and it worked well as it offers open, merge, write, addvolume , addsurfaceloop directly to the geometry opened.

could you please help in this regard.

thankyou

@nschloe
Copy link
Owner

nschloe commented Aug 30, 2019

@SaimaSafdar Best always open a new issue for new problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants