Skip to content

Instantly share code, notes, and snippets.

@bjulius
Last active June 29, 2024 05:47
Show Gist options
  • Save bjulius/d3404392474a0b474d95fe04c7ac5e87 to your computer and use it in GitHub Desktop.
Save bjulius/d3404392474a0b474d95fe04c7ac5e87 to your computer and use it in GitHub Desktop.
Python Script for GPT4O to Extract BIM from PBIX
import zipfile
import os
def extract_bim_from_pbix(pbix_path, output_dir):
# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True)
# Extract the pbix file (which is a zip file)
with zipfile.ZipFile(pbix_path, 'r') as pbix_zip:
# Extract all files to the output directory
pbix_zip.extractall(output_dir)
# Locate the DataModel file
data_model_path = os.path.join(output_dir, 'DataModel')
# Define the output path for the .bim file
bim_file_path = os.path.join(output_dir, 'DataModel.bim')
# Rename the DataModel file to DataModel.bim
os.rename(data_model_path, bim_file_path)
return bim_file_path
# Example usage
pbix_file_path = 'your_file.pbix' # Replace with the path to your .pbix file
output_directory = 'extracted_files' # Directory where files will be extracted
bim_file = extract_bim_from_pbix(pbix_file_path, output_directory)
print(f'Model.bim file extracted to: {bim_file}')
@bjulius
Copy link
Author

bjulius commented Jun 29, 2024

Add this to your custom instructions, instructing GPT40 to run this script whenever a PBIX file is uploaded to extract the BIM file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment