Created
October 11, 2016 14:59
-
-
Save MikeUdin/0b528375c6283c76bf8d2e973772e915 to your computer and use it in GitHub Desktop.
Open in Explorer/Finder folder from customizable popup menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import c4d | |
from os import path as p | |
from c4d import storage as st | |
from c4d import gui | |
# Welcome to the world of Python | |
# Author: Mike Udin, | |
# Tutorial here http://mikeudin.net/?p=2930 | |
# 2016 | |
def main(): | |
ini_file = p.join(p.split(__file__)[0],'ini_file.txt') | |
c4d_user_dir = st.GeGetStartupWritePath() | |
points = [ | |
('Active Doc Folder',doc.GetDocumentPath()), | |
('Preferences',st.GeGetC4DPath(c4d.C4D_PATH_PREFS)), | |
('Desktop',st.GeGetC4DPath(c4d.C4D_PATH_DESKTOP)), | |
('Scripts',p.join(c4d_user_dir,'library','scripts')), | |
('Plugins',p.join(c4d_user_dir,'plugins')) | |
] | |
sub_points = [] | |
if p.exists(ini_file): | |
with open(ini_file,'r') as t_file: | |
data = t_file.read() | |
for line in data.splitlines(): | |
name,n_dir = line.split(';') | |
sub_points.append((name,n_dir)) | |
menu = c4d.BaseContainer() | |
for x in points: | |
menu.SetString(c4d.FIRST_POPUP_ID+len(menu), x[0]) | |
menu.SetString(0,'') | |
if sub_points: | |
sub_menu = c4d.BaseContainer() | |
sub_menu.SetString(1, 'Custom Folder') | |
subID = c4d.FIRST_POPUP_ID+1000 | |
for item in sub_points: | |
sub_menu.SetString(subID+len(sub_menu), item[0]) | |
menu.SetContainer(c4d.FIRST_POPUP_ID+len(menu)-1, sub_menu) | |
menu.SetString(c4d.FIRST_POPUP_ID+len(menu),'Add Custom Folder') | |
result = gui.ShowPopupDialog(cd=None, bc=menu, x=c4d.MOUSEPOS, y=c4d.MOUSEPOS)-c4d.FIRST_POPUP_ID | |
#print result | |
if result == c4d.FIRST_POPUP_ID*-1: return | |
if result == len(menu)-1: | |
c_dir = st.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING, title="Add New Directory to list", flags=c4d.FILESELECT_DIRECTORY, force_suffix="") | |
if c_dir: | |
with open(ini_file,'a') as t_file: | |
t_file.write(p.split(c_dir)[1]+';'+c_dir+'\n') | |
return | |
if result > 1000: | |
st.ShowInFinder(sub_points[result-1001][1], False) | |
return | |
st.ShowInFinder(points[result][1], False) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment