Add uziom generation script and update wet input documents
- Created a new Python script `uziom.py` for generating DXF drawings of grounding systems based on user input parameters. - Added detailed documentation in `wet_input_15.docx` and `wet_input_3.docx` for the design of grounding systems, including calculations for resistance and resistivity measurements. - Included placeholders for dynamic data insertion in the documents to facilitate project-specific customization.
This commit is contained in:
39
pages/api/generateDxf.js
Normal file
39
pages/api/generateDxf.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { exec } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method === 'POST') {
|
||||
// Get the input data from the request body
|
||||
const data = req.body;
|
||||
|
||||
// Prepare arguments to pass to the Python script if needed
|
||||
const scriptArgs = data.args || [];
|
||||
console.log(scriptArgs)
|
||||
const Arguments = "\"" + scriptArgs.join('" "') + "\"";
|
||||
|
||||
// Run the Python script and pass the arguments
|
||||
exec(`python3 uziom.py ${Arguments}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
// Handle execution errors
|
||||
console.error(`exec error: ${error}`);
|
||||
return res.status(500).json({ message: 'Internal server error' });
|
||||
}
|
||||
|
||||
// The output file needs to have been created by the Python script
|
||||
const filePath = path.resolve('./public/uziom.dxf');
|
||||
const fileName = 'uziom.dxf';
|
||||
|
||||
// Set headers for file download
|
||||
res.setHeader('Content-Disposition', `attachment; filename=${fileName}`);
|
||||
res.setHeader('Content-Type', 'application/dxf');
|
||||
|
||||
// Read and send the file data
|
||||
const fileStream = fs.createReadStream(filePath);
|
||||
fileStream.pipe(res);
|
||||
});
|
||||
} else {
|
||||
// Handle any other HTTP methods if necessary
|
||||
res.status(405).json({ message: 'Method not allowed' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user