Python API
Strata’s engine lives in strata.project and has no FreeCAD or Qt dependency: it can run in FreeCAD’s Python console, in freecadcmd, or in plain Python (it needs Git).
The examples in Automate with Python are tested and are the best place to start.
from strata.project import Project
project = Project.locate("C:/cad/Gearbox/Gearbox.FCStd") # None if not in a project
project.create_version("V3", "Released for tooling")
for entry in project.history()[:5]:
print(entry.author, entry.title)
Revision arguments (rev, rev_a, rev_b, from_rev) are commit ids such as entry.sha or version.sha.
For the latest state of a workspace use project.repo.rev_parse("refs/heads/<workspace>"); project.head() is the latest state of the current one.
merge_plan is the exception: it takes a workspace name.
Document paths (doc, docs) are relative to the project folder with forward slashes, for example Parts/Bracket.FCStd; project.rel(path) converts an absolute path.
Opening and creating projects
|
The project containing |
|
The project at |
|
Turn on version control for |
|
Copy a shared project from |
Attributes: root (folder), name (folder name), dir (the .strata folder), repo (low-level strata.gitcore.Repo).
Recording and history
|
Record the files on disk as a history entry of the current workspace. |
|
|
|
Documents in the project at |
|
|
|
Write |
HistoryEntry: sha, title, body, kind (start, save, workspace, restore, merge), author, time (Unix time), docs, parents, versions (names of versions at this entry).
Versions
|
All versions, newest first, as |
|
The next free |
|
Create a version of |
Workspaces
|
Name of the current workspace ( |
|
|
|
Create a workspace from |
|
Record, then switch. Returns the documents rewritten on disk. |
|
Delete a workspace other than Main and the current one. Versions are kept. |
Restore, compare and merge
|
Bring the current workspace back to |
|
|
|
Analyse merging workspace |
|
What |
|
Perform it. |
|
|
|
Return to the state before that merge; the merge leaves history. Returns the documents rewritten on disk. |
|
|
Releases
|
Release one document of a |
|
|
|
|
|
Every attempt of every revision of a part number, newest first. |
|
The next free revision in the project’s revision scheme. |
strata.project.next_revision(existing, scheme="letters") computes the same from a list of labels; REVISION_SCHEMES lists the schemes ("letters", "numeric").
Sharing
|
The shared location, or |
|
Set the shared location. A local or network folder is prepared automatically. |
|
Record, fetch, fast-forward or merge, and push. Returns |
Settings
settings() returns the project settings (record_on_save, track_binary, revision_scheme); save_settings({…}) updates them. project.repo.set_identity(name, email) sets your name and email for this project.
strata.docdiff
DocDiff describes how one document changed:
|
|
|
lists of |
|
list of |
|
changes to the document’s own properties |
docdiff.summarize(diff) returns the one-line description used for history titles.
docdiff.diff_documents(old_xml, new_xml, …) compares two Document.xml contents directly.
strata.fc (inside FreeCAD)
|
The project of a FreeCAD document, or of the active one. |
|
Open a read-only copy of |
|
Create the 3D comparison document and return the volume summary. |
|
Re-open documents after their files changed on disk. |
|
Write part number, description, company and custom properties into documents, save them and record one history entry. An empty custom value removes that property. |
|
Write |