SCL in FreeCAD

285 views
Skip to first unread message

Jürgen Riegel

unread,
Jan 5, 2014, 2:18:12 PM1/5/14
to scl...@googlegroups.com
Hi together,
today I started to integrate the SCL into FreeCAD. I'm a long time unhappy with the OCC STEP support and looked for something more open and with python support.

For the beginning I will use OCC to transfer shapes and investigate the python generated classes for high level STEP interpretation. My idea is to use for the high-level stuff python to make it easier to contribute and debug translation methodes. We have a lot of objects and module in FC which can be transfered from/to a lot of Schema. So I'm looking forward to investigate that.

My first plan is to write a simple part21 parser, since Part21.py is only a stub, and implement an importer (AP 214) for our in-develop Assembly module.

In the long run I would like to go much further with other Schema and maybe an own Shape translator (like IfcOpenShell)...

Cheers
Jürgen

Mark

unread,
Jan 5, 2014, 7:41:55 PM1/5/14
to scl...@googlegroups.com
Hi Jürgen

I'm glad to hear that you'll be able to use STEPcode in FreeCAD!

I am not nearly as familiar with the python side of SC as Thomas Paviot is, but I'll be glad to answer any questions that I can.

For C++ examples, take a look at 

Regards
Mark



--
You received this message because you are subscribed to the Google Groups "STEPcode - Developers Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scl-dev+u...@googlegroups.com.
To post to this group, send email to scl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scl-dev/ce7988a6-cbe0-4ce6-8ab0-e71f6cc2e7b3%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thomas Paviot

unread,
Jan 10, 2014, 5:24:47 AM1/10/14
to scl...@googlegroups.com
2014/1/5 Jürgen Riegel <juergen.r...@googlemail.com>
Hi Jürgen,

I contributed the python code for SCL about one year ago as far as I remember. Unfortunately I didn't have any time to further improve these first experiments, and SCL has changed a lot in the meantime thanks to Mark's efforts. Everything thus remains in a very experimental stage. When I started this work, my objectives were:
* be able to read/write step files from a set of instances created from a python script. My first experiment was a python wrapper on top of JSDAI, using Jython (http://sourceforge.net/projects/pysdai/), but I didnt' feel very confortable with using both Java and Python. I needed something with python only ;
* SCL made possible to generate python code directly from an EXPRESS schema. My goal was to be as simple as possible: from an EXPRESS schema, generate only 1 python module that could be used with a simple 'from ap203 import*'.
* at last, more important: to be able to check EXPRESS rules. When a STEP based data exchange fails between A and B, it's quite difficult to identify where does the problem comes from, and which program is responsible for the failure: the source A or the target B? both ? Being able to ensure that the instance file is valid in regard with the integrity rules defined in the schema is thus something important.

I may have something on my hard disk that I did not push yet, I'll check that. Feel free to ask any question, I will give you an answer if I can remember what I did.

Best Regards,

Thomas



Jürgen Riegel

unread,
Jan 21, 2014, 2:37:12 AM1/21/14
to scl...@googlegroups.com
Hi Thomas,


I contributed the python code for SCL about one year ago as far as I remember. Unfortunately I didn't have any time to further improve these first experiments, and SCL has changed a lot in the meantime thanks to Mark's efforts. Everything thus remains in a very experimental stage. When I started this work, my objectives were:
* be able to read/write step files from a set of instances created from a python script. My first experiment was a python wrapper on top of JSDAI, using Jython (http://sourceforge.net/projects/pysdai/), but I didnt' feel very confortable with using both Java and Python. I needed something with python only ;
* SCL made possible to generate python code directly from an EXPRESS schema. My goal was to be as simple as possible: from an EXPRESS schema, generate only 1 python module that could be used with a simple 'from ap203 import*'.

Thats what I also looking for, works quit will. In one AP I generated I had to change manually to get it interpreted, but was a small thing.
 
* at last, more important: to be able to check EXPRESS rules. When a STEP based data exchange fails between A and B, it's quite difficult to identify where does the problem comes from, and which program is responsible for the failure: the source A or the target B? both ? Being able to ensure that the instance file is valid in regard with the integrity rules defined in the schema is thus something important.

As an application programmer I have a different goal ;) I want to read everything possible, checking other's format is nice, but non of our concern. 

I may have something on my hard disk that I did not push yet, I'll check that. Feel free to ask any question, I will give you an answer if I can remember what I did.

Thank you very much. So far its going well. I already implemented a SimpleParser.py which is able to parse and recursively instantiate most of the standard file. Also already done is a GraphViz exporter which generate a graph diagram of the STEP graph. Makes it much easier for me to interpret new STEP files. 

Next steps will be finishing instantiation and implementing a filter facility which allows to limit the transfer process to certain subsets of Item-types.

At the moment I develop on a certain subset of FreeCAD, but when I have something usable, I will send you a patch upstream.

Cheers
Jürgen  

st...@costvision.com

unread,
Jan 21, 2014, 1:26:27 PM1/21/14
to scl...@googlegroups.com
Hi Jurgen, 


On Tuesday, January 21, 2014 12:37:12 AM UTC-7, Jürgen Riegel wrote:
As an application programmer I have a different goal ;) I want to read everything possible, checking other's format is nice, but non of our concern. 
 
Validation of a file to a schema is useful when developing a STEP exporter, since the syntax and semantics can be difficult to human interpret.   Free resources for this include Express Engine (http://exp-engine.sourceforge.net/) for 203 and 214, and LKSoft's (www.lksoft.com) IDA-STEP viewer or JSDAI for these and 242.    Another tool that you may find useful include the NIST STEP File Analyzer, http://www.nist.gov/el/msid/infotest/step-file-analyzer.cfm, for generating an organized, table-based view of a STEP file.    

Thank you very much. So far its going well. I already implemented a SimpleParser.py which is able to parse and recursively instantiate most of the standard file. Also already done is a GraphViz exporter which generate a graph diagram of the STEP graph. Makes it much easier for me to interpret new STEP files. 

 Your GraphViz-based viewer sounds similar to SCView, https://github.com/LaurentBauer/SCView, which is an Express-G Viewer.   This would be a useful stand-alone tool, and the basis of other tools such as an editor.     


Next steps will be finishing instantiation and implementing a filter facility which allows to limit the transfer process to certain subsets of Item-types.

At the moment I develop on a certain subset of FreeCAD, but when I have something usable, I will send you a patch upstream.

Cheers
Jürgen  

Sounds like you are making progress.   The more you let us know what you want to do, and where you are, the more we can contribute and point you to resources.   

Regards, Charlie 

TomThurman

unread,
Jan 22, 2014, 9:49:11 AM1/22/14
to scl...@googlegroups.com
Hi Jurgen,
I am very interested in the GraphViz export functionality, as I am currently working on developing complex mappings and would import that into yrEd, a 
Graphviz compatible editor.

Best Regards,
Tom Thurman

Mark

unread,
Jan 22, 2014, 11:18:42 AM1/22/14
to scl...@googlegroups.com

Hi Jürgen,

If you are working with large files of which you only need a subset, you might be interested in lazy loading, implemented in cllazyfile. I'm not sure that using it from python would be feasible, but it would reduce loading time and memory use if you don't need the entire file.

Once Dave and I get exp2cxx working with small files, I'll be able to debug a branch that I was working on previously. The changes in this branch allow inverse references to be located and associated with the inverse attribute, when using the cllazyfile. This isn't currently possible with or without lazy loading.

The IFC folks will be happy to have inverse references, and it'll also mean that STEPcode passes 100% of our tests for the first time.

Regards
Mark

--
You received this message because you are subscribed to the Google Groups "STEPcode - Developers Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scl-dev+u...@googlegroups.com.
To post to this group, send email to scl...@googlegroups.com.

Mark

unread,
Jan 22, 2014, 11:25:22 AM1/22/14
to scl...@googlegroups.com

Actually, the more I think about it, the more certain I am that cllazyfile could be used with python easily. It wouldn't take much to add a method that returns a string containing the full text of an instance. This could be fed to the python instance parser.

Maurice B

unread,
Mar 23, 2016, 8:46:06 AM3/23/16
to STEPcode - Developers Mailing List
Hi Thomas,
I'm investigating to export STEP using SCL or pythonOCC with a python script...
the main purpose of my work is to reduce the size of the STEP file exported...
I noticed that if I open a STEP file generated by commercial sw and save it by OCC I get a correct STEP file, but with a file size much bigger from 3 to 6 times bigger...
i.e. if I open https://github.com/stepcode/stepcode/blob/master/data/ap214e3/sg1-c5-214.stp
and I save it with OCC the size increases from 24kb to 143kb...
I also noticed that if I re-open the big-size file in a commercial sw and save it, the size will return to previous smaller value...

Is there a way with pythonOCC to export STEP file without adding extra size?
Is that extra size related to tessellation?
Have you any suggestion in a way to export it using SCL?

here a link of a small python script that I used to test reading and writing STEP using pythonOCC
https://github.com/easyw/kicad-3d-models-in-freecad/blob/master/pythonocc/ImportExportStepR3.py

thank you
Maurice

TomThurman

unread,
Mar 23, 2016, 6:56:27 PM3/23/16
to STEPcode - Developers Mailing List
Hi Maurice,
I have to defer to others for this question.
Regards,
Thomas

Christopher Sean Morrison

unread,
Mar 24, 2016, 2:49:10 AM3/24/16
to scl...@googlegroups.com
I noticed that if I open a STEP file generated by commercial sw and save it by OCC I get a correct STEP file, but with a file size much bigger from 3 to 6 times bigger...
i.e. if I open https://github.com/stepcode/stepcode/blob/master/data/ap214e3/sg1-c5-214.stp
and I save it with OCC the size increases from 24kb to 143kb...
I also noticed that if I re-open the big-size file in a commercial sw and save it, the size will return to previous smaller value…

I don’t have much to add here as to the potential cause but you named some reasonable guesses.  With that significant a size change, I suspect you will be able to look at the file and see where the differences are coming from.  It could be floating point numbers with a ridiculous number of significant digits getting printed, tessellation data, or who knows what else.  Either way, it should be kind of obvious if you compare them side by size or count entities in each.

Cheers!
Sean

Message has been deleted

Maurice B

unread,
Mar 24, 2016, 10:29:11 AM3/24/16
to STEPcode - Developers Mailing List
Hi,
it is not the floating numbers...
you can have a look at the original file here
https://github.com/easyw/kicad-3d-models-in-freecad/blob/master/pythonocc/sg1-c5-214.stp
and the occ exported one
https://github.com/easyw/kicad-3d-models-in-freecad/blob/master/pythonocc/sg1-c5-214-out.stp

I opened the file with a text editor and, for me, it is not so obvious to compare the entity structures...

I would like to code a STEP trans-coder using SCL ...
my purpose would be reading the STEP file coming from occ and writing back a STEP file using SCL again to see if the size would be reduced as in fact happens with other CAD sw...

would someone point me toward an example to do something similar in StepCode?

thank you
Maurice

Christopher Sean Morrison

unread,
Mar 24, 2016, 10:51:23 AM3/24/16
to scl...@googlegroups.com

> On Mar 24, 2016, at 10:29 AM, Maurice B <eas...@gmail.com> wrote:
>
> Hi,
> it is not the floating numbers...
> you can have a look at the original file here
> https://github.com/easyw/kicad-3d-models-in-freecad/blob/master/pythonocc/sg1-c5-214.stp
> and the occ exported one
> https://github.com/easyw/kicad-3d-models-in-freecad/blob/master/pythonocc/sg1-c5-214-out.stp
>
> I opened the file with a text editor and, for me, it is not so obvious to compare the entity structures…

Really? That’s a little concerning because reading the first label on each line and knowing nothing about the file format, I would think you can see at quick glance that there are a *ton* of sets of CARTESIAN_POINT lines in one but not in the other…

You can see that they’re appearing in big blocks repeatedly in one version, but not the other. Notice they’re all preceded by a B_SPLINE_CURVE_WITH_KNOTS entity too that doesn’t appear at all in the other version at all.

Not knowing anything else, that tells me that you have two different programs dumping out the same geometry in different ways.

Cheers!
Sean


Maurice B

unread,
Mar 24, 2016, 11:13:46 AM3/24/16
to STEPcode - Developers Mailing List
On Thursday, March 24, 2016 at 3:51:23 PM UTC+1, Sean wrote:
Not knowing anything else, that tells me that you have two different programs dumping out the same geometry in different ways.
that was the assumption of my main mail, otherwise you won't get the same result reopening the step file...

so, I'm back to what I would like to reach which is a STEP trans-coder using SCL ...

my purpose would be reading the STEP file coming from occ and writing back a STEP file using SCL again to see if the size would be reduced as in fact happens with other CAD sw...

would someone point me toward an example to do something similar in StepCode?
thanks again
Maurice

roman...@gmail.com

unread,
Mar 24, 2016, 11:43:48 AM3/24/16
to STEPcode - Developers Mailing List
Hello folks,

Let me offer some thoughts as we use OCC STEP exporter in our product (you can easily google the product name from mine, if you will).

Unlike other modeling kernels, the OCC data model requires 3D and 2D representations for edge curves - i.e. in 3D model space and in 2D parametric space of a surface an edge lies upon. Therefore when exporting to STEP, OCC writes both. This contributes to file size growth.

Given that most often 2D representations are B-Spline curves (which are computed by projecting 3D curves onto surfaces) this makes the greatest impact as B-Splines produce the largest footprint.

'Trans-coding' seems to remove either 3D or 2D representation (as other CAD systems/kernels can suffice with one representation only) what decreases the size back.

This may be not the only reason of growth observed in the OCC export (additional reasons may include greater number of loops) but this is definitively the greatest one.

Hope this helps.
Roman Lygin

Maurice B

unread,
Mar 24, 2016, 4:43:31 PM3/24/16
to STEPcode - Developers Mailing List
Hi,
I'm going in the right direction, I hope :)

I downloaded and built stepcode in MSYS2 mingw64 using these commands:
git clone https://github.com/stepcode/stepcode.git stepcode
cd stepcode
; mkdir build; cd build
cmake
.. -G "MSYS Makefiles" -DSC_BUILD_SCHEMAS=ap214 -DSC_BUILD_SCHEMAS=../data/ap214e3
make
-j4
cd bin
then I tested the "p21read_sdai_ap214e3,exe" sample with the cube-nx.stp file
./p21read_sdai_ap214e3.exe cube-nx.stp cube-scl.stp
and the conversion went fine
Then I tried with a cube coming from FreeCAD STEP AP214
./p21read_sdai_ap214e3.exe cube-out-fc.stp cube-scl.stp
and I got the followings errors
\p21read_sdai_ap214e3.exe: load file ...
Reading Data from cube-out-fc.stp...
HEADER read
:
ERROR
: instance #8 'MECHANICAL_CONTEXT': Unknown ENTITY type.
   
Data lost: ('',#2,'mechanical')
ERROR
: instance #24 'PRODUCT_TYPE': Unknown ENTITY type.
   
Data lost: ('part',$,(#7))
ERROR
: instance #366 'MECHANICAL_CONTEXT': Unknown ENTITY type.
   
Data lost: ('',#2,'mechanical')
ERROR
: instance #373 'PRODUCT_TYPE': Unknown ENTITY type.
   
Data lost: ('part',$,(#365))
FIRST PASS complete
:  380 instances created.
 
4  ERRORS      0  WARNINGS
ERROR
:  ENTITY #7 Product
  frame_of_reference
:    index:  1
Reference to non-existent ENTITY #8.
ERROR
in EXCHANGE FILE: incomplete instance #7.
ERROR
: in 2nd pass, instance #8 not found.
   
Data lost:  = MECHANICAL_CONTEXT('',#2,'mechanical')
ERROR
: in 2nd pass, instance #24 not found.
   
Data lost:  = PRODUCT_TYPE('part',$,(#7))
ERROR
:  ENTITY #365 Product
  frame_of_reference
:    index:  1
Reference to non-existent ENTITY #366.
ERROR
in EXCHANGE FILE: incomplete instance #365.
ERROR
: in 2nd pass, instance #366 not found.
   
Data lost:  = MECHANICAL_CONTEXT('',#2,'mechanical')
ERROR
: in 2nd pass, instance #373 not found.
   
Data lost:  = PRODUCT_TYPE('part',$,(#365))
Second pass complete - instance summary:
   
Total instances: 380
   
Invalid instances: 4
   
Incomplete instances (includes invalid instances): 0
   
Warnings: 0.
SECOND PASS complete
:  380 instances valid.
 
6  ERRORS      0  WARNINGS
Finished reading file.
Severity: SEVERITY_WARNING
User message in parens:
(STEPfile Reading File: Unable to create 4 instances.
   
In first pass through DATA section. Check for invalid entity types.
Second pass complete - instance summary:
   
Total instances: 380
   
Invalid instances: 4
   
Incomplete instances (includes invalid instances): 0
   
Warnings: 0.
 
6  ERRORS      0  WARNINGS
)
Detailed message in parens:
(Second pass complete - instance summary:
   
Total instances: 380
   
Invalid instances: 4
   
Incomplete instances (includes invalid instances): 0
   
Warnings: 0.
)
p21
ReadExchangeFile() Physical memory: 1132kb; Virtual memory: 528kb; User CPU time: 1ms; System CPU time: 0ms
so it seems to me that only two entities are missing...

'MECHANICAL_CONTEXT': Unknown ENTITY type
'PRODUCT_TYPE': Unknown ENTITY type.

Is there a way to solve this problem in reading the source STEP file?
Thank you

roman...@gmail.com

unread,
Mar 24, 2016, 4:54:56 PM3/24/16
to STEPcode - Developers Mailing List
AFAIR, these are due to the fact that OCC (in older versions) writes AP214DIS (Draft International Standard) which SLCode is not able to parse.
Make sure you write in AP214IS (International Standard) - that should resolve this. OCC has a tweak to do this, not certain whether this is exposed in FreeCAD though.

Good luck!
Roman

Maurice B

unread,
Mar 24, 2016, 5:30:18 PM3/24/16
to STEPcode - Developers Mailing List
Hi Roman,
thank you for your reply...
I tried also
 ./p21read_sdai_ap210e2.exe cube-out-fc.stp cube-fc-scl.stp
and in this case I got only one entity error
 'PRODUCT_TYPE': Unknown ENTITY type.
I don't know if that would be managed...

Moreover which is the tweak in OCC to write in AP214IS?
thanks
Maurice

roman...@gmail.com

unread,
Mar 24, 2016, 5:38:18 PM3/24/16
to STEPcode - Developers Mailing List
Hi Maurice,

#include <Interface_Static.hxx>

Interface_Static::SetCVal ("write.step.schema", "AP214IS");

Roman

Maurice B

unread,
Mar 24, 2016, 6:01:20 PM3/24/16
to STEPcode - Developers Mailing List
I tried with pythonocc, and the cube that I converted seems to loose color, moreover when I try to parse it I got this error:
p21 ReadExchangeFile() Physical memory: 1016kb; Virtual memory: 508kb; User CPU time: 1ms; System CPU time: 0ms
This pair of schema names do not match - AUTOMOTIVE_DESIGN_CC2 { 1 2 10303 214 -1 1 5 4 } and AUTOMOTIVE_DESIGN
ERROR
- schema name mismatch. Tried all available combinations.

Moreover it seems that someone else tried to read a cube stp file coming from FreeCAD and he succeed ...
https://groups.google.com/forum/#!searchin/scl-dev/mechanical_context/scl-dev/lU4V-2F4FyY/6bVXMSBrDg4J
he had exactly my two errors...
what could I do to?
thank you again

Maurice
Reply all
Reply to author
Forward
0 new messages