FreeCAD/FreeCAD

STEP/GMSH: exported step model is scaled after gmsh meshing

Open

#18 980 ouverte le 10 janv. 2025

Voir sur GitHub
 (10 commentaires) (0 réactions) (0 assignés)C++ (5 550 forks)batch import
3rd party: GmshFile format: STEPHelp wantedStatus: ConfirmedType: Bug

Métriques du dépôt

Stars
 (30 913 stars)
Métriques de merge PR
 (Merge moyen 24j 7h) (217 PRs mergées en 30 j)

Description

Is there an existing issue for this?

  • I have searched the existing issues

Problem description

Exported step model is scaled by 1000 after gmsh meshing, when both are used in the same python session.

The following code imports some FreeCAD model, exports it to STEP format, meshes it in GMSH and then repeats the process (part of workflow for automated geometry optimization).

The file is exported scaled by 1000 after GMSH mesh generation. After session reset, file scale is back to normal.

Setting Part.exportUnits to different value does not help the situation.

import FreeCAD
import Import
import Part
import gmsh
import gc

def show_line(file, start):
    with open(file, 'r') as f:
        for line in f.readlines():
            if line.startswith(start):
                print(line)
                break


doc = FreeCAD.openDocument('/usr/local/share/examples/PartDesignExample.FCStd')
body = doc.findObjects(Type='PartDesign::Body')[0]

Part.exportUnits('MM')
Import.export([body], '/tmp/out.step')
FreeCAD.closeDocument(doc.Name)
del body
del doc
gc.collect()

# inspect some point coordinates
show_line('/tmp/out.step', '#25 =')

gmsh.initialize()
gmsh.option.setString('Geometry.OCCTargetUnit', 'M')
gmsh.model.add('model')
gmsh.merge('/tmp/out.step')
gmsh.model.mesh.generate(2)
gmsh.write('/tmp/out.msh')
gmsh.finalize()

doc = FreeCAD.openDocument('/usr/local/share/examples/PartDesignExample.FCStd')
body = doc.findObjects(Type='PartDesign::Body')[0]

Part.exportUnits('MM')
Import.export([body], '/tmp/out.step')
FreeCAD.closeDocument(doc.Name)

# inspect the same point coordinates
show_line('/tmp/out.step', '#25 =')

Full version info

Discovered in Debian packaged v0.20.2, reproduced in build from source v1.0.0 and latest main branch commit

Subproject(s) affected?

Other (specify in description)

Anything else?

Issue is not present in ImportGui

Code of Conduct

  • I agree to follow this project's Code of Conduct

Guide contributeur