CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 16, 2018, 14:09:00 pm


Login with username, password and session length


Pages: [1] 2 3
  Print  
Author Topic: Working on a Python script (Real Python Interpreter) to parse CB files  (Read 1430 times)
onekk
Wookie
****
Offline Offline

Posts: 394


View Profile
« on: September 07, 2018, 16:38:01 pm »

Some time ago someone posted that the interoperation between Linux and Windows, poses some problem as the file format is slightly different and pose some problem.

As the problem is known and apparently from long time and no fix are present, I'm working on a tool that could fix that problems.

So in the processing of doing that, I have to create a tool that parse the CB file and check some parameters.

For now the tool is in early development, but, I've two problems:

1) for now I haven't a working Windows Machine
2) I don't know very well what are the real problems. I could recall that some problems arise only for the MOP, but didn't remind well.


So for make the thing short, I have started to do some work and as the program will be used on both Windows and Linux I had chose python as a scipting language.

For no I have some pieces of code working, I can:

1) Create a CBfile from scratch
2) Add Layers
3) Add a empty polylines (no points in them)

and it seems to work, in the process I've found that CB 0.9.8 Linux version could accept this minimal code

Code:
<?xml version='1.0' encoding='UTF-8'?>
<CADFile xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="0.9.8.0" Name="Test-file">
  <layers>
    <layer name="Predefinito" color="127,255,0">
      <ModificationCount>0</ModificationCount>
      <objects>
        <pline id="0">
          <ModificationCount>0</ModificationCount>
          <mat m="Identity"/>
          <pts/>
        </pline>
       </objects>
    </layer>
  </layers>
  <MachiningOptions>
    <Stock>
      <Pmin>0,0</Pmin>
      <Pmax>0,0</Pmax>
      <Color>255,165,0</Color>
    </Stock>
    <ToolProfile>Unspecified</ToolProfile>
  </MachiningOptions>
  <parts/>
  <ActiveLayer>Predefinito</ActiveLayer>
</CADFile>


and also that i leave an empty polyline, defined only as

Code:
<pline >
<pline />

CB will fill these empty polylines as follow

Code:
<pline id="1">
          <ModificationCount>1</ModificationCount>
          <mat m="Identity" />
          <pts />
</pline>

If more than one empty polylines are present i will fill the id in a sequential manner, and if i put a id="xx" it gave an error of unreadable CB file.

So to report some work on the CB file format.

The ultimate goal is to be able to parse the file and correct the malformed sentences to permit to work on the file in Linux and Windows without fiddling too much.

One other problem that I've faced is the difficult to copy between two files, as the drag and drop in Linux has some glitch that depends heavily on the "Display Manager" you use, so having the ability to copy some entitites in an empty CB file or adding some entities taken from a CB file into another will be a good solution.

Unforntunately as the Python interpreter on CamBam is not a real environment but a standalone interpreter and to cope with the xml file some external libraries are necessary (lxml.etree) it is not possible to use this approcah internally on CB.

This to inform you on some work on this matter, and to ask you for problematic CB files to "analyze" for a better knowledge of the file format.

In case someone would contribute, please let me know what the problem is and in which version of Cambam the problem arise, (Windows or Linux and the CB versions)

Thanks in advance and Best Regards

Carlo D.
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
Garyhlucas
CNC Jedi
*****
Offline Offline

Posts: 1169


View Profile
« Reply #1 on: September 07, 2018, 18:44:30 pm »

So what language is CB itself written in?
Logged

Gary H. Lucas

Have you read my blog?
 http://a-little-business.blogspot.com/
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 7638



View Profile
« Reply #2 on: September 07, 2018, 19:09:41 pm »

I'm just guessing, but I'd wager on C#.

Lloyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
jk
Wookie
****
Offline Offline

Posts: 261


View Profile
« Reply #3 on: September 07, 2018, 20:39:33 pm »

I think you could add libraries to CB python interpreter.

from CB documentation:
---

Script modules are pretty much like any other script, except they need to be ‘self contained’. The internally generated header block described above will not be automatically added, so all required modules and name-spaces need to be imported into the module.

The module search path can be defined within the script to allow importing standard Python modules.

Code:
# append the module search path
import sys
sys.path.append("C:/Python27/Lib")
# import the Python CSV handling module
import csv
reader = csv.reader(open("C:/devt/test.csv", 'rb'))
for row in reader:
    print str(row)
Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1010


View Profile
« Reply #4 on: September 07, 2018, 23:51:21 pm »

Hi Carlo
This thread might help:http://www.cambam.co.uk/forum/index.php?topic=6649.15
Dave
Logged
onekk
Wookie
****
Offline Offline

Posts: 394


View Profile
« Reply #5 on: September 10, 2018, 17:19:34 pm »

Thanks, if the internal scripting engine could load external python modules, it was great as it could be launched within cambam itself.

But the documentation for Ironpython is not much a great help as it is generally say that "ironpython is a python interpreter for C#" and then refer to the standard python documentation.

from the example script the script is using a standard installation of python

Code:
sys.path.append("C:/Python27/Lib")

and reuse some module from it.

Anyone know where i could find the problematic files (the files that don't load in windows and are created on Linux and those created on Linux that don't load on Windows)?

I remember that some files aren't working due some problem in the MOP section (deleting the MOPS make the file load without problem) and i remember that some problem where related to some true or false being not written as True or False (or the reverse).

Once having set up a decent python parser for CB files, it will be relatively easy to make a "file check" or a "file translate between Windows and Linux" and maybe some modules that do some roundings and maybe some other things like checking the coerence of some settings across MOPs, like tool numbers and target deps and so on.

Regards

Carlo D.




Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
onekk
Wookie
****
Offline Offline

Posts: 394


View Profile
« Reply #6 on: September 29, 2018, 14:18:45 pm »

Some work in progress:

I have made some work on this front, but I've faced some problems, the main problem was the visualisation.

So I've resolved to do another thing, instead of using some exotic library, I've made some work with FreeCAD.

For now, I've made a parser and visualizer for most of the entities, so it can viewed and used in FreeCAD.

Some problems still remains, the most big is the trasformation matrix.

If anyone is interested, let me know.

Regards

Carlo D.
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3659



View Profile
« Reply #7 on: September 29, 2018, 19:04:48 pm »

Maybe I can help with Windows testing, etc.
Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1010


View Profile
« Reply #8 on: September 30, 2018, 02:15:29 am »

Hi Carlo

Have you seem this page https://www.freecadweb.org/wiki/index.php?title=Macros_recipes
This page may provide some answers for you. https://www.freecadweb.org/wiki/Scenegraph
and as Freecad is based on Open Cascade this might be worth a look. https://dev.opencascade.org/doc/overview/html/index.html

I use Freecad almost constantly now with CB and Import and Export files, (relatively Freely) between them.
The Latest Binaries in the pic which are very stable (if you are using the release package ver .17 ) then you probably want to use the version I'm using as It's quite different.

Dave


* Freecad Version.PNG (203.37 KB, 450x553 - viewed 24 times.)
Logged
onekk
Wookie
****
Offline Offline

Posts: 394


View Profile
« Reply #9 on: September 30, 2018, 10:36:54 am »

Hi Carlo

....

I use Freecad almost constantly now with CB and Import and Export files, (relatively Freely) between them.
The Latest Binaries in the pic which are very stable (if you are using the release package ver .17 ) then you probably want to use the version I'm using as It's quite different.

Dave


I'm using the 0.17 as in my distribution (it's Devuan, Debian without Systemd, based on Debian Stretch) it is not packaged even the 0.17, so I'm using 0.17 AppImage that seem working quite well and pair good with the python 2.7 installed to use the lxml library (that take care of doing the XML work on the CB files)

The main goal of my work is to be able to use the CB entities in FrreCAD, ad it is relatively easy to do the port of the entitites without passing throough the dxf creation.

The main concern now it is the Trasformation matrix of CB, that i've to study and reimplement in FreeCAD (I've not investigated well how FreeCAD manage trasformations).

One thing that I've in mind is to use the CB entities and the associated MOPs to obatain the 3D shapes of the cuttings, maybe to use them with the assembly workbench.

Maybe if I manage to obtain some help (The FreeCAD forum is not at the CB forum level of collaboration) It will be a good thing to produce a CB importer (and maybe Exporter) to cope with some CB limitiation, the main thing is that in CB is not easy (almost impossible) to work with the main interface, and that the function that read the file is not exposed (see the work that was done for the dashed and dotted line plugin).

In FreeCAD is relatively easy to add features and to manipulate "entitites", and the access to the Main interface is almost complete working with python too.

but in FreeCAD the CAM work is only at the beginning and to be able to use the CB MOPs for the CAM work is the long term task (I have done some work on MOPs creation in my Box Plugin and I'm quite confident that i could achieve to write this part ).

Think on some work done in FreeCAD, the Z height is the "Target Depth"  and in the reverse if you have in CB a MOP created with the entity ID you can use the "CAD entity" and obtain from the corresponding MOPs the Z height to pass in the Shape creation, (maybe IMporting only the MOP form a CB file).

As the parser is done in Python it is relatively easy to cope with the slilght different between the Linux and Windows version that CB refuse to load "in toto" and if the work is complex, better to have the 90% imported than having 0%.

Maybe a tool long post, sorry for that.

Carlo D.
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1010


View Profile
« Reply #10 on: September 30, 2018, 14:16:00 pm »

HI Carlo

Seems like an ambitious task you have set yourself,  and will take a bit of work, good on you!

Regarding the Path Module this guy is doing some work with it and has some good videos, well worth a look.
https://www.youtube.com/watch?v=jARnmuWm7n4&list=PLEuOia-QxyFJZSpqb0xOHc9t7MLdCO3io

One of the best tools to help you is ILSpy, here are some of the things that you can find if you can use it (I'm not sure if you can use it on Linux) but there must be a similar tool for doing "Reflection".

The pics show the XML reader from the CamBam.Cad CadFile.
There is a lot of interesting stuff in there.

I do think that Freecad's Pathing Module "Interface" could be made much better, perhaps more like CB's or Fusions.
If you can pull this off your work would be well received by the Freecad Path Workbench Users.

Dave


* Reply for carlo CamBam-CadFile ReadFile.PNG (94.21 KB, 1302x669 - viewed 20 times.)

* Reply for carlo XMLSerializer in CamBam-CAD.PNG (98.58 KB, 1342x696 - viewed 18 times.)
Logged
onekk
Wookie
****
Offline Offline

Posts: 394


View Profile
« Reply #11 on: October 01, 2018, 18:43:06 pm »

Hi, thanks, for the information, ILSPy isn't working well on Linux, Monodevelop has a similar tool and some things could be inspected.

IN the meantime, I have done some work, some "rough work" on the CamBam Workbench (I have named it OneCAM), to separate the Name CamBam from FreeCAD (I don't know Andy position on using the name of his program so just in case i will stay on the "safe side")

Here included a zip file to expand in the Mod subdir of the .FreeCAD user directory in Linux (the only things related to Linux are the path work and the intial import of the lxml library in OCB_Gui.py)

Code:
sys.path.append("/usr/lib/python2.7/dist-packages/")

as the lxml module is not included in the FreeCAD 0.17 python 2.7 appimage.

Maybe it is rough and not too polished, but for now it could import in FreeCAD the main entities.

Once activated the OneCAM workbench, you have to:

1) click on the "yellow cube" icon and in the file chooser window slect a CB file.

2) then you have to select in the "CamBam" Tab in the ComboView a entity and press the "green arrow icon" and the entity is drawn and put in the "drawing window"


That is, text is not yet implemented and also the Transformation Matrix.

The next things to be done are:

1) add a button to "import" all the CB entities
2) implement the text entity
3) add the Transformation Matrix, I know that FreeCAD has a similar thing, but i have to check if the matrix are compatible in  a manner that it is possible to copy the relevant values between the two matrices (Maybe too optimistic).
4) make some work on the MOPs data to extrude the entities in a solid according to the "target depth" and maybe the "stock dimension" of the CB file

The 1st stage is to obtain quickly a view of the CB entities with the Z height in FreeCAD to maybe use the Assembly workbench.

For the Path part, it is promising, but the development is very slow, and the developer are not too kind (The last answer to some of my question was, "It is in heavy development, and it is not usable yet", and I've only asked how to make a pocket with the workbench).

The Path WorkBench has a long story and recently the codebase is changed has the developer have abandoned the HeeksCNC library in favour of a "home made" library to obtain the paths.

Once it is stabilized, maybe some work could be done, but for now CB is more "stable" and it is doing a good job.

If I could obtain a decent tool to import-modify-export a correct CB file, and maybe use some "high level" primitives in the "FreeCAD python scripting interface", plus the ability to print the drawing and make some "Tech Drawing" starting with the CB files.

But the main interesting part is the ability to do some 3D work on the CB entities directly.

Regards

Carlo D.


* OneCAM.zip (15.79 KB - downloaded 7 times.)
Logged

Carlo D. (onekk)

eShapeoko #343 750x1000 mm + GRBL + bCNC + CamBam
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1010


View Profile
« Reply #12 on: October 02, 2018, 03:41:17 am »

HI Carlo.

The "penny's dropped" and I now understand what you want to do.

I'm pretty sure, If my memory hasn't failed me that another user here was trying to do something similar with
CB and Another Cad Program, he called it a bridge.

Anyway I installed your zip file on Freecad .17 for windows (see pic), but the CBloadfile method failed but the Freecad error reporting didn't give any clues as to what the error was and then disappeared.

So tonight I'll try to find the logging settings to see if I can log the errors to a file where I can examine them at leisure.

Dave


* Reply for carlo Freecad Importer.PNG (197.49 KB, 1343x700 - viewed 33 times.)

* Reply for carlo Freecad Importer failed to load.PNG (152.17 KB, 1324x703 - viewed 26 times.)
Logged
EddyCurrent
CNC Jedi
*****
Offline Offline

Posts: 3659



View Profile
« Reply #13 on: October 02, 2018, 10:04:37 am »

This is the other thread, http://www.cambam.co.uk/forum/index.php?topic=833.msg4413#msg4413
    
"CamBam Addon to Alibre Design"
Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 1010


View Profile
« Reply #14 on: October 02, 2018, 15:14:44 pm »

Thanks Eddy, I still couldn't remember the name of the other software.
Dave
Logged
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.175 seconds with 20 queries.

Copyright © 2018 HexRay Ltd. | Sitemap