• tal@lemmy.today
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    5 hours ago

    FreeCAD exposes a Python console as an end-user feature. It has a macro recording system for automating repetitive tasks, much like MS Office does, it uses Python as a scripting language. Can you show me an API reference for this feature?

    kagis

    https://freecad.github.io/SourceDoc/modules.html

    I want to write a macro that will insert some text into the cell of a spreadsheet I have selected. Click a cell, click the macro button, and it puts some text into that cell. It can do this. There are macros published that do this kind of thing. Show me where in their published documentation the functions necessary to do that are described.

    I don’t use FreeCAD, don’t have any familiarity with this spreadsheet functionality, but let’s look.

    kagis

    They appear to have a Doxygen API reference for their spreadsheets here:

    https://freecad.github.io/SourceDoc/d0/da8/classSpreadsheet_1_1Sheet.html

    setCell() looks like it sets a cell value to me.

    That appears to take a CellAddress, which it looks like is obtained via getCellAddress(). As I said, I haven’t used FreeCAD’s spreadsheets, but I expect that it has some cell-addressing syntax akin to spreadsheets that I’ve used, and that one passes the name in to that, same as one would if referencing the cell in a formula to compute another cell’s value. I’ve no idea if FreeCAD’s syntax is the same as Excel’s, or if it differs, though, and I’m not going to look that up; that shouldn’t be an API-specific issue.

    It also looks like it has a macro-recording feature. It looks like, to my quick skim, that natively generates Python:

    https://wiki.freecad.org/Macros

    You can also directly copy/paste python code into a macro, without recording GUI action.

    And looking at the source of an arbitrarily-chosen macro, it appears to be in Python, rather than some app-specific macro language:

    https://wiki.freecad.org/Macro_Rotate_View

    So I expect that you can most-likely just record yourself performing the operation and the macro-recording functionality will give you the code without you needing to write something.

    EDIT: It sounds like you want to get the selected cells rather than specifying the to-be-modified cell by name, which it looks like SheetTableView::selectedRanges() provides you with; Range objects appear to provide for a selection including many cells, but if you only want, say, the starting cell (which would presumably be the case for a single cell selection), then it looks like Range::from() provides that, since the starting cell would be the same cell as the only cell in a selection if there’s a single-cell selection. That returns a CellAddress as well.