Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
@m_magalhaes said in Add/Remove Groups of User Data:
Hello, I was also talking about something like this. But it's not the best way to go. I suggest a TagData (plugin) with his own UI. pyTagCode = '\ import c4d \n\ #Welcome to the world of Python \n\ \n\ def main():\n\ print "this ia a message"\n\ \n\ ' import c4d # Main function def main(): if op is None: gui.MessageDialog("Please selecte a target object") tag = c4d.BaseTag(c4d.Tpython) tag[c4d.TPYTHON_CODE] = pyTagCode op.InsertTag(tag) c4d.EventAdd() # Execute main() if __name__=='__main__': main() By the way, don't forget you can save tag presets, that include python tags. You can simple add them with right click on your object in OM and "Load tag preset" Cheers, Manuel
Hello,
I was also talking about something like this. But it's not the best way to go. I suggest a TagData (plugin) with his own UI.
pyTagCode = '\ import c4d \n\ #Welcome to the world of Python \n\ \n\ def main():\n\ print "this ia a message"\n\ \n\ ' import c4d # Main function def main(): if op is None: gui.MessageDialog("Please selecte a target object") tag = c4d.BaseTag(c4d.Tpython) tag[c4d.TPYTHON_CODE] = pyTagCode op.InsertTag(tag) c4d.EventAdd() # Execute main() if __name__=='__main__': main()
By the way, don't forget you can save tag presets, that include python tags. You can simple add them with right click on your object in OM and "Load tag preset"
Cheers, Manuel
Oh this is good to know! Thanks so much for the information, this is quite helpful!
Matt
@zipit Thanks so much man, this is really quite helpful! I sure appreciate all the help!
@m_magalhaes I see, but how do you create a script that generates a python tag with that code already in it?
@m_magalhaes Hey man I'm so sorry I didn't see your reply! This was extremely helpful! Pretty much exactly what I was looking for.
Do you know if this can be converted to a Python script so that I can drop it into any project?
@s_bach Okay it's kind of working now, but is only outputting the last track in the list. I am using this script in a python tag:
import c4d #Welcome to the world of Python def main(): # find object in scene, store in obj obj = doc.SearchObject('VO') # store some variables track = obj.GetCTracks() obj[c4d.ID_USERDATA,4] = track[0].GetName() track[0][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,6] track[0][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,7] track[0][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,14] obj[c4d.ID_USERDATA,10] = track[1].GetName() track[1][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,11] track[1][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,12] track[1][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,9] obj[c4d.ID_USERDATA,15] = track[2].GetName() track[2][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,16] track[2][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,17] track[2][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,18] obj[c4d.ID_USERDATA,3] = track[3].GetName() track[3][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,20] track[3][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,21] track[3][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,22] obj[c4d.ID_USERDATA,24] = track[4].GetName() track[4][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,25] track[4][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,26] track[4][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,27] obj[c4d.ID_USERDATA,29] = track[5].GetName() track[5][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,30] track[5][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,31] track[5][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,32] obj[c4d.ID_USERDATA,34] = track[6].GetName() track[6][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,35] track[6][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,36] track[6][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,37] obj[c4d.ID_USERDATA,39] = track[7].GetName() track[7][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,40] track[7][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,41] track[7][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,42] obj[c4d.ID_USERDATA,44] = track[8].GetName() track[8][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,45] track[8][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,46] track[8][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,47] obj[c4d.ID_USERDATA,49] = track[9].GetName() track[9][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,50] track[9][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,51] track[9][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,52] obj[c4d.ID_USERDATA,54] = track[10].GetName() track[10][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,55] track[10][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,56] track[10][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,57] obj[c4d.ID_USERDATA,59] = track[11].GetName() track[11][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,60] track[11][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,61] track[11][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,62] obj[c4d.ID_USERDATA,64] = track[12].GetName() track[12][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,65] track[12][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,66] track[12][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,67] obj[c4d.ID_USERDATA,69] = track[13].GetName() track[13][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,70] track[13][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,71] track[13][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,72] obj[c4d.ID_USERDATA,74] = track[14].GetName() track[14][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,75] track[14][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,76] track[14][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,77] obj[c4d.ID_USERDATA,79] = track[15].GetName() track[15][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,80] track[15][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,81] track[15][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,82] obj[c4d.ID_USERDATA,84] = track[16].GetName() track[16][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,85] track[16][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,86] track[16][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,87] obj[c4d.ID_USERDATA,89] = track[17].GetName() track[17][c4d.CID_SOUND_ONOFF] = obj[c4d.ID_USERDATA,90] track[17][c4d.CID_SOUND_START] = obj[c4d.ID_USERDATA,91] track[17][c4d.CID_SOUND_NAME] = obj[c4d.ID_USERDATA,92] # outputs the current track name where playhead is traks = obj.GetCTracks() for trak in traks: start = trak[c4d.CID_SOUND_START] # get length # length is stored as a string; need to convert it to int length = trak[c4d.CID_SOUND_LENGTH] length = length[:-2] length = int(float(length)) fps = doc.GetFps() end = start + c4d.BaseTime(length, fps) # check if the current frame is within the range of the sound clip curTime = doc.GetTime() if curTime >= start and curTime < end: obj[c4d.ID_USERDATA,19] = trak.GetName() else: obj[c4d.ID_USERDATA,19] = "No Track" trak = trak.GetNext()
Also, with this code, I am getting the spinning beachball of death It must be trapped in the loop maybe?
@m_magalhaes Yeah since the ID’s of my userdata are all over the place, maybe I better just stick with writing them all out
I was trying to make it so it started with just one track, and have an add/remove button at the top that would create additional tracks. But this starts to get extremely confusing for me to wrap my head around, as I’m only just a beginner.
Thanks @s_bach, I really appreciate your help. I’m more of a motion designer, but wanted to tailor the scene I’m working on to make it easier.
HTML/CSS come really easy to me, but my brain just comes to a halt when I try and get my head around python
@m_magalhaes I am writing it in a python tag.
I should note that when it comes to programming, I’m not all that smart
@s_bach So something like this?
track = op.GetFirstCTrack() while track is not None: start = track[c4d.CID_SOUND_START] # get length # length is stored as a string; need to convert it to int length = track[c4d.CID_SOUND_LENGTH] length = length[:-2] length = int(float(length)) fps = doc.GetFps() end = start + c4d.BaseTime(length, fps) # check if the current frame is within the range of the sound clip curTime = doc.GetTime() if curTime >= start and curTime < end: print("Uses Track: " + track.GetName()) else: print("no hit")
I'm really struggling with wrapping my head around this