LibreOffice with Python 3.5

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: LibreOffice with Python 3.5

Post by looo »

It would be interesting to have an ide which handles c++ and python. (KDeveloper has this feature, but the python support is a bit limited. Maybe there is a better tool which can handle both languages.)

For python I see the difficulties in the way how FreeCAD adds new modules. As this quite a bit different from normal python-modules, ide's will need some special configuration to work with FreeCAD. This means you have to add the path to every module manually to the ide-configuration

With fc 0.17 it's possible to add modules in a more natural way. So for new modules it's possible to use a correct package setup which will work with ide's by default. But as most people don't care about this (ignorance/ lack of knowledge) these issues won't go away.

references:
https://forum.freecadweb.org/viewtopic.php?f=10&t=21128
https://forum.freecadweb.org/viewtopic.php?f=22&t=13238
https://forum.freecadweb.org/viewtopic.php?f=10&t=23197
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: LibreOffice with Python 3.5

Post by Joel_graff »

It's funny I just now stumbled across this topic as I'm trying to solve the same problem.

I've got some ideas about how to implement it, and I'd like to abstract it a bit so it would be possible to have multiple external sources (spreadsheets, databases, text files, etc) providing parametric input...

Anyway, I'm currently trying to get FreeCAD and python 3.6 working. I've succeeded (thanks to this thread), but I'm stuck getting pivy to import... working on that.

If I can get the python bindings for FreeCAD's dependencies to work, my goal is to get some basic interoperability between LO Calc and FreeCAD using Python and UNO. I'm reasonably confident something can be done, anyway.
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
salp
Posts: 250
Joined: Thu Nov 21, 2013 11:58 pm
Location: Putnam, NY

Re: LibreOffice with Python 3.5

Post by salp »

Nice to see this topic being kept alive.

What kind of problems are you having importing pivy? I'm in the middle of rebuilding my test system (lost a hard drive) but I can look back in my notes to see if I have any thing.

Sal
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: LibreOffice with Python 3.5

Post by Joel_graff »

https://forum.freecadweb.org/viewtopic. ... &start=590

I don't really know much about it, and right now, I'm rebuilding my system, so it might be a week before I can get back on it. But I have a clear idea of how to get it done if I can just get started. :)
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
User avatar
cjones6108
Posts: 11
Joined: Sat Nov 14, 2020 12:30 am
Location: South-Central USA (GMT -6)

Re: LibreOffice with Python 3.5

Post by cjones6108 »

All:

I've been attempting to work on "Bug #0002957: please add spreadsheet direct printing" from your "Low Hanging Fruit" list. After several days of banging my head against it, my conclusions are that
  • (1) developing a direct spreadsheet print function in FreeCAD makes no sense when LibreOffice has this functionality already built in. So then, I worked at getting FreeCAD to integrate with LibreOffice. Determined with Python macros, and using some of the socket / UNO scripts available from this thread, one may get FC Python to open LO, but there it all stops because the FC Python is much newer than that included with LO, a condition that will likely always exist; thus, conclusion
  • (2): Python is not really an option that I can see. Next, I considered at some length coding a solution in C++, without ever being able to get any of the simple sample C++ programs included with the 7.0 LibreOffice SDK to compile (tried both with VS19 and MinGW C++ compilers), and without finding anywhere anyone who had successfully done this. So, conclusion
  • (3): I'm sorry folks, best I can tell this is going to be much more trouble than it's worth -- I won't say impossible. I'm guessing some of you long-time experts knew this already, which is how I came to see someone's remark that there were no plans to integrate FC and LO. Well, I just had to try it.
Bottom line, if we think this is really a valuable feature needed in FC, I'd be open to suggestions; otherwise, I've spent more time on it than is warranted.

For completeness,
FreeCAD
OS: Windows 10 Version 2004
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23721 (Git)
Build type: Release
Branch: master
Hash: 4c323a63258b94903290fb23426be240c8663950
Python version: 3.8.6+
Qt version: 5.15.1
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United States (en_US)

LibreOffice + v.7 SDK
Version: 7.0.4.2 (x64)
Build ID: dcf040e67528d9187c66b2379df5ea4407429775
CPU threads: 8; OS: Windows 10.0 Build 19041; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL

-----
caj
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: LibreOffice with Python 3.5

Post by heda »

thinking out of the box...

your tripping point is that you cannot get uno to work in fc python,
would it then be possible to hook up to a python where uno already works (without pip installing).

i'm on linux, and then uno imports in a system python as is (and fc not), and i guess on windows there is python included in lo that has a working uno.

so could one socket inbetween those 2 different python in the same machine, and get it done that way,
i.e. server/client the 2 different python to work around the incompatibilities.

not really knowing anything about sockets, it took me 10 minutes to find some code on the web, which after adjusting the ip/port connected the py3.8 and py2.7 on my box.

don't see why this should not work (except that it will take some time to build the server/client api),
but i'm probably missing something...
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: LibreOffice with Python 3.5

Post by jmaustpc »

cjones6108 wrote: Tue Feb 02, 2021 7:42 pm Bottom line, if we think this is really a valuable feature needed in FC, I'd be open to suggestions; otherwise, I've spent more time on it than is warranted.
I know it's not perfect and not exactly the same thing but you already can print spreadsheets from FreeCAD, but via a "spreasheet view" into a TechDraw drawing, which can be based on a plain page template.

Here is an example file made in today's Daily PPa,
the fcstd file
bucket_flange_tube.FCStd
(595.63 KiB) Downloaded 92 times
the PDF exported from the Drawing
test_spreadsheet_print_via_techdraw.pdf
(271.45 KiB) Downloaded 61 times
As you can see, it does not handle "merged cells" properly.

Perhaps improving this is TechDraw might be a better use of your time? But that is a genuine question.

Also LibreOffice is a large application so interacting with it would be good but incorporating/distributing with it with FreeCAD would not. You also have to be careful to watch for any possible licence compatibility issues.

I also wonder if supporting at least some of the LibreCalc file format so we don't have to use CSV as an interchange format, but I have no idea how complex that might be.

Jim

OS: Ubuntu 18.04.5 LTS (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.today's daily PPA
Build type: Release
Branch: unknown
Hash: d02a0d558e212528f1197418a8a752d5cd925bf9
Python version: 3.6.9
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/Australia (en_AU)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: LibreOffice with Python 3.5

Post by Kunda1 »

Also wanted to mention this thread: "How much interest is there to integrate LibreOffice into FreeCAD?" https://www.forum.freecadweb.org/viewto ... =8&t=44005 @salp made some progress with pyuno in that thread.
I agree with the different sentiments in this thread. I like @heda's idea as well. Its safe to say that libreoffice is deployed with almost every opensource distro these days. I don't see the harm in creating better interoperability with it. It can benefit all 3 projects involved: FreeCAD, LibreOffice and Python.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
cjones6108
Posts: 11
Joined: Sat Nov 14, 2020 12:30 am
Location: South-Central USA (GMT -6)

Re: LibreOffice with Python 3.5

Post by cjones6108 »

OK, thanks for the feedback. Heda's idea is intriguing; I had not thought to approach it from that direction. Also jmaustpc's thought, which I haven't looked at at all, and I'll see if I can review the stuff on the GitHub link mentioned.

I'll keep looking at this as it sounds as if there might end up being value added beyond just the initial feature request (Bug 2957). The requestor dismissed the TechDraw angle, but three or four years later, maybe it's worth another look.

Just to provide context, if that is useful (maybe not), I latched onto this particular problem just as a method of "jumping in" on FC development. I'm starting at ground-zero on that, LO, C++ and Python all at once, so I have a lot of catching up to do, and I wanted something that didn't seem to be a big priority or that anyone else was doing much work on, because I knew it would take me more time than perhaps a more experiecned FC dev.

-----
caj
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: LibreOffice with Python 3.5

Post by heda »

some more thoughts...
if one completely ignores security, the whole story starts to look fully doable (at least as a thought experiment).
it won't be pretty going over 2 bridges - but if it works it works and it takes you there.

prerequisite is that there is a python on the machine that imports uno out of the box.
that one would be started with subprocess and client.py

pyoo seems to be single py file and mit license,
if i am not mistaking, that opens up for just copying it to a place where fc finds it, you would then not import it in fc, but reading it as a text file and send it over the socket to the uno-python and dynamically import it from there (not much benefit for linux, but could be a way to get things working smoothly on windows).

one way to get data over the socket could be to "pickle", then it should be easy enough to ship data back and forth.

if using pyoo, can't help but wonder if one cannot get away with not bothering much about an api at all, why not just send strings that are pyoo commands as they would be written if things truly were in one file and then exec them in client.py (one just needs to keep variable state in mind in client.py before sending commands that will error out because of missing variables).

the last thing needed would be a simple row/column datastructure that can be pickled (think a class which has methods to get/set cell data with references like 'c2'),
and I think you would be good to go.

this starts to look like it even could be a "simple" macro, even though it would be at least 3 files, making the wb structure the more natural approach.

regardless of what happens - it has been an enjoyable thought experiment, which is where i will leave it at.
Post Reply