Closed Davys224 closed 3 years ago
Hi @Davys224,
I threw together and tested a quick example to show you how to get it working. Unzip all to the same directory and then open the blender file. Clicking the "play" button above the script should draw a benzene molecule. Chemicals Example.zip
Blender's changed how they handle python between operating systems in small subtle ways so it can take a few attempts to get right. This is working on Blender 2.83 on macOS Big Sur.
Hope it helps!
Hi @Davys224,
I threw together and tested a quick example to show you how to get it working. Unzip all to the same directory and then open the blender file. Clicking the "play" button above the script should draw a benzene molecule. Chemicals Example.zip
Blender's changed how they handle python between operating systems in small subtle ways so it can take a few attempts to get right. This is working on Blender 2.83 on macOS Big Sur.
Hope it helps!
Thanks, it does!!!
Hello,
I've pasted "draw.py" in the scripting panel and hard-coded the path...everything seems to run well until it gets to the line I put in the title (and below). Using Blender 2.9
Obviously, I don't get outputs! To check my hardcoded PATH, I went into Anaconda and ran the lines and asked it to PRINT the JSON in the console. It performed perfectly, so I'm fairly confident of this part.
I wish I could give you the output in the console, but I have none, I'm using Blender portable 2.9...seems to be more stable on my laptop than the installed one.
Thanks in advance!
Bit of code so it gets clearer:
Hard-coding my location:
PATH = 'C:/Users/UserName/Documents/Molecules_jsons/' #Obviously /UserName/ has the right name, but I removed it here with open(os.path.join(PATH, 'caffeine.json')) as in_file: #Testing "draw.py" using caffeine. atom_data = json.load(in_file)
The part that's giving me headaches
if name == 'main': """Uses Blender's limited argv interface to pass args from main script.""" args = sys.argv[sys.argv.index('--') + 1:] #This line stops script in Blender, I've not changed anything from "draw.py" show_bonds, join = True, True if '--space-filling' in args: show_bonds = False args.remove('--space-filling') if '--no-join' in args: join = False args.remove('--no-join')
UPDATE: I got Blender to show me the console (Finally, why a separate window!): Traceback (most recent call last): File "\draw_molecules.py", line 159, in
ValueError: '--' is not in list
Error: Python script failed, check the message in the system console