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

Default Imports would be a nice QoL #178

Open
cppcooper opened this issue May 11, 2023 · 1 comment
Open

Default Imports would be a nice QoL #178

cppcooper opened this issue May 11, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@cppcooper
Copy link

Is your feature request related to a problem? Please describe.
Not launching VSCode from MO2 means many scripts aren't visible when developing. The solution is to add the paths to the mods that introduce them as imports in the ppj file. It is annoying needing to do this every time I generate a new project.

Describe the solution you'd like
It would be nice to have a list of paths that are imported by default to newly generated ppj files.

@cppcooper cppcooper added the enhancement New feature or request label May 11, 2023
@bigbellyburger
Copy link

I am using a small python script to use the exported MO2 mod list to update my ppj file. It would be nice if this was more integrated, but perhaps this helps someone in the meantime:

import csv, os
import lxml.etree as ET

imports = []

def add_import(name):
    if os.path.isdir(name):
        imports.append(name)

# the game base scripts
add_import("..\Game Root\Data\Scripts\Source")

with open('modlist.csv', newline='') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        name = row['#Mod_Name']
        add_import(f"..\Mods\{name}\Source\Scripts")
        add_import(f"..\Mods\{name}\Scripts\Source")

imports.reverse()

parser = ET.XMLParser(remove_blank_text=True)
tree = ET.parse('skyrimse.ppj', parser)
root = tree.getroot()

imports_elem = root.find('{PapyrusProject.xsd}Imports')
imports_elem.clear()

for value in imports:
    elem = ET.Element('{PapyrusProject.xsd}Import')
    elem.text = value
    imports_elem.append(elem)

result = ET.tostring(root, xml_declaration=False, pretty_print=True, encoding='UTF-8')
with open('skyrimse.ppj', 'w') as fp:
    fp.write(result.decode('utf-8'))

This script requires python3 and the lxml module. On Windows you can open cmd.exe and run:

python3 --version
pip3 install lxml

To install it. The python3 command should have Windows install it if not already installed.

The script assumes it is placed alongside your skyrimse.ppj in a directory such as MO2Directory/mods/MyMod.

Then in MO2 do ... -> Export to csv -> Only active (checked) mods from your current profile and save this file as modlist.csv alongside the script, then run the script with python3 ppj-update.py

It will then update your skyrimse.ppj and replace the <Imports> tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants