Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to "create new project" by code #917

Open
zhangkaihua88 opened this issue Jul 7, 2024 · 2 comments
Open

How to "create new project" by code #917

zhangkaihua88 opened this issue Jul 7, 2024 · 2 comments
Labels
kind/feature New feature request needs-triage Issue needs a triage/* label

Comments

@zhangkaihua88
Copy link

What would you like to be added?

I would like to ask how to quickly create a project through code instead of a UI interface

like this app.plugins.plugins["obsidian-projects"].createProject()

Why is this needed?

Due to my many projects, I want to automate the creation

@zhangkaihua88 zhangkaihua88 added kind/feature New feature request needs-triage Issue needs a triage/* label labels Jul 7, 2024
@zhangkaihua88
Copy link
Author

I implemented it by adding the following code in main.js

  addNewProject(data){
    data.id = v4_default()
    data.views.forEach(view => {
        view.id = v4_default();  // Setting the 'type' property to 2
      });
    settings.addProject(data);
    // this.activateView(data.id);
    return data.id
  }

Calling through JavaScript

a = {
  "fieldConfig": {},
  "defaultName": "",
  "templates": [],
  "excludedNotes": [],
  "isDefault": false,
  "dataSource": {
    "kind": "folder",
    "config": {
      "path": "14_Quant/因子学习",
      "recursive": true
    }
  },
  "newNotesFolder": "",
  "views": [
    {
      "config": {},
      "filter": {
        "conjunction": "and",
        "conditions": []
      },
      "colors": {
        "conditions": []
      },
      "sort": {
        "criteria": []
      },
      "name": "表格",
      "type": "table"
    }
  ],
  "name": "Quant_test"
};

app.plugins.getPlugin('obsidian-projects').addNewProject(a)

@AttackOnTyler
Copy link

I don't know why this isn't being thumbs-up-ed more. I know this is a relatively new issue, but the use case for programmatically creating projects is great.

Especially, the ability to define a fieldConfig and have the fields be exposed and in the proper order instead of manually adding, dragging and dropping the fields that we wish to see on each project. Even when using Templater to define the new note template, projects doesn't automatically set the fields to the template.

Currently, I'm using the QuickAdd plugin to create project folders through code and input prompts, and lastly a call to the create project modal, where I need to fill in the details kinda stinks as a workflow. Being able to reuse variables set by the input prompts would be amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature request needs-triage Issue needs a triage/* label
Projects
None yet
Development

No branches or pull requests

2 participants