how to get textfiles open into the freecad editor

Need help, or want to share a macro? Post here!
User avatar
microelly2
Posts: 4365
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

how to get textfiles open into the freecad editor

Postby microelly2 » Tue Jun 23, 2015 1:43 pm

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
Site Admin
Posts: 14795
Joined: Thu Feb 19, 2009 10:32 am

Re: how to get textfiles open into the freecad editor

Postby wmayer » 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.
User avatar
microelly2
Posts: 4365
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: how to get textfiles open into the freecad editor

Postby microelly2 » Wed Jul 15, 2015 9:19 pm

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
Site Admin
Posts: 14795
Joined: Thu Feb 19, 2009 10:32 am

Re: how to get textfiles open into the freecad editor

Postby wmayer » Wed Jul 15, 2015 10:36 pm

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: 159
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: how to get textfiles open into the freecad editor

Postby ebrahim raeyat » Wed Sep 04, 2019 5:00 pm

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
Site Admin
Posts: 14795
Joined: Thu Feb 19, 2009 10:32 am

Re: how to get textfiles open into the freecad editor

Postby wmayer » Wed Sep 04, 2019 5:57 pm

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
Posts: 8345
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland

Re: how to get textfiles open into the freecad editor

Postby bernd » Wed Sep 04, 2019 8:04 pm

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

Re: how to get textfiles open into the freecad editor

Postby ebrahim raeyat » Thu Sep 05, 2019 1:30 am

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 110 times