how to get textfiles open into the freecad editor

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

how to get textfiles open into the freecad editor

Post by microelly2 »

To add more comfort I'm looking for a method to open and edit text- and yaml files with the text editor inside freecad.
I can open macros and py-files but other filetypes .txt, .yaml not
csv Files are opened as calculation sheets

how to configure freecad to open text files (and adding a tool for syntax highlighting)
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to get textfiles open into the freecad editor

Post by wmayer »

Code: Select all

FreeCAD.addImportType("Yaml file (*.yaml)","mymodule")
Then mymodule is a Python module that implements the method "open(filename, documentname)". The second parameter can be ignored in your case.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: how to get textfiles open into the freecad editor

Post by microelly2 »

I have tested this, but it opens a3D window and not a text window
what is wrong with the open method to get a text window?

Code: Select all

import os
import FreeCAD

def open(filename):
        docname=os.path.split(filename)[1]
        doc=FreeCAD.newDocument(docname)
       #  fill content
        
        return doc
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to get textfiles open into the freecad editor

Post by wmayer »

Code: Select all

FreeCAD.newDocument
always creates a 3d window.
If you want to have a text editor then create an instance of QTextEdit and add it to the mdi area.
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: how to get textfiles open into the freecad editor

Post by ebrahim raeyat »

wmayer wrote: Tue Jun 23, 2015 3:56 pm

Code: Select all

FreeCAD.addImportType("Yaml file (*.yaml)","mymodule")
Then mymodule is a Python module that implements the method "open(filename, documentname)". The second parameter can be ignored in your case.
Thank for your reply. I found it useful, but i want to know if i want to open an existing file format (like *.xlsx), but I want to process my open function, not predefined function. I am writing pyconcrete workbench that reads exported excel file from CSI SAFE software and draw foundation and so on. how can i do that?

thanks for your help.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: how to get textfiles open into the freecad editor

Post by wmayer »

With

Code: Select all

FreeCAD.addImportType("Excel file (*.xlsx)","mymodule")
you register your module "mymodule" to handle Excel files. When you load an Excel via File > Open then the system searches for the "open" function of the module that has registered the xlsx format and calls it.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: how to get textfiles open into the freecad editor

Post by bernd »

User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: how to get textfiles open into the freecad editor

Post by ebrahim raeyat »

bernd wrote: Wed Sep 04, 2019 8:04 pm as an example see frd calculix result files in FEM:

https://github.com/FreeCAD/FreeCAD/blob ... nit.py#L37
and
https://github.com/FreeCAD/FreeCAD/blob ... py#L46-L49
Thanks a lot. how can i overwrite default xlsx opening format? now it give me an option to select on of them, but i can't that.
open.png
open.png (12.68 KiB) Viewed 1117 times
Post Reply