CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 21, 2018, 09:14:36 am


Login with username, password and session length


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

Posts: 325


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: 1140


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: 7605



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: 256


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: 942


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: 325


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
Pages: [1]
  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.125 seconds with 19 queries.

Copyright © 2018 HexRay Ltd. | Sitemap