Hello,
For a project, we are making hundreds of models and would like to check each one visually. Instead of opening each one-by-one, I thought I would write a script that would loop through and load each model in the GUI, visualize it in a couple of different planes, saving each as a screenshot, then close the model, load the next one, and repeat. This way we could have all images stored in various planes for each model if we need to visualize them quickly. I found the "testvisuals.py" script example, which has been a good helpful base, but I'm stuck on a few functions.
My questions are:
1. What are functions for: saving a view as an image, and closing a model (or close all) -- similar to how loadModel() works?
2. In the example, "gfxWindowSendKey('x')" orients the view in the x direction, which is helpful for y and z -- but what about if you want to view in a -x, -y, or -z?
Otherwise, I think the loop construction and everything else will be simple given the script example.
Thanks,
Brett
Shell scripting to save images
- Brett Allaire
- Posts: 3
- Joined: Tue Mar 07, 2017 10:05 am
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Shell scripting to save images
Hello,
This seems better fit for the API visualizer, where you can programmatically close it, control the camera and maybe save images etc. For the record, the scripting shell allows most commands that take no input dialog to be executed, for example will perform File->Close
The API visualizer is documented here
https://stanford.edu/~dembia/simbody_ta ... lizer.html
Hope this helps,
-Ayman
This seems better fit for the API visualizer, where you can programmatically close it, control the camera and maybe save images etc. For the record, the scripting shell allows most commands that take no input dialog to be executed, for example
Code: Select all
performAction("FileClose")
The API visualizer is documented here
https://stanford.edu/~dembia/simbody_ta ... lizer.html
Hope this helps,
-Ayman
- Brett Allaire
- Posts: 3
- Joined: Tue Mar 07, 2017 10:05 am
Re: Shell scripting to save images
Dear Ayman,
Thank you for your reply. The scripting shell seemed to work well with turning off and on visualizations of specific muscles and moving the camera as needed. However, based on your reply it doesn't seem like I can then just save out images automatically (i.e. I can't write a script in the Jython shell that effectively clicks the "Save view as image" icon). I'm effectively trying to do this:
I would even be good without saving the screenshots -- say that I could pause the script to wait for a keypress or "enter" instead of each "SAVE SCREENSHOT." But given what you said, it's probably not able to handle any user input like this?
I have looked into using the visualizer in Matlab, but the documentation is difficult for me to follow. Is it possible to do something like I was trying to do above, but using Matlab and the visualizer? Forces don't inherently have geometry the way bodies do in the models, so setting muscles to not be visualized is not apparent to me. Nor are the camera controls or saving the window image to a file name.
Thanks again for your initial response and any help you can give further.
Regards,
Brett
Thank you for your reply. The scripting shell seemed to work well with turning off and on visualizations of specific muscles and moving the camera as needed. However, based on your reply it doesn't seem like I can then just save out images automatically (i.e. I can't write a script in the Jython shell that effectively clicks the "Save view as image" icon). I'm effectively trying to do this:
Code: Select all
for idnum in idlist:
# Load model
loadModel("MODEL PATH")
# Get a handle to the current model (the one just loaded)
model = getCurrentModel()
gfxWindowSendKey('x')
##SAVE SCREENSHOT
gfxWindowSendKey('z')
pelvis = findObject(model, "Body", "pelvis")
setObjectOpacity(pelvis, 0.2)
##SAVE SCREENSHOT
#hide muscles to look at body orientation
for musc in musclelist:
bod = findObject(model, "Force", musc)
toggleObjectDisplay(bod, 0)
##SAVE SCREENSHOT
#performAction("FileClose")
I have looked into using the visualizer in Matlab, but the documentation is difficult for me to follow. Is it possible to do something like I was trying to do above, but using Matlab and the visualizer? Forces don't inherently have geometry the way bodies do in the models, so setting muscles to not be visualized is not apparent to me. Nor are the camera controls or saving the window image to a file name.
Thanks again for your initial response and any help you can give further.
Regards,
Brett
- Ayman Habib
- Posts: 2248
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Shell scripting to save images
Hi Brett,
There're a couple methods on the Visualizer to control the camera transform that would help, as well as a method to shutdown the visualizer, though I'm not sure how much of these are exposed through Matlab/Java Bindings.
There's a display-hints object that controls what types are displayed but no fine control over individual objects visibility.
If you start down this route and run into problems please let me know, it should be possible to accomplish if all the C++ functionality is available through Matlab (or python). If not and you want to use the latest GUI, try it and let me know so we can assess what it takes to make your workflow possible.
Best regards,
-Ayman
There're a couple methods on the Visualizer to control the camera transform that would help, as well as a method to shutdown the visualizer, though I'm not sure how much of these are exposed through Matlab/Java Bindings.
There's a display-hints object that controls what types are displayed but no fine control over individual objects visibility.
If you start down this route and run into problems please let me know, it should be possible to accomplish if all the C++ functionality is available through Matlab (or python). If not and you want to use the latest GUI, try it and let me know so we can assess what it takes to make your workflow possible.
Best regards,
-Ayman