• Dialog Freezes when checking for Message()

    Cinema 4D SDK r21 python
    12
    0 Votes
    12 Posts
    1k Views
    B
    Thanks @m_adam. First time using the c4d.DrawViews(). It works as expected. Thanks for the introduction.
  • Get the Button GadgetID Directly Under the Mouse?

    Cinema 4D SDK r21 python
    11
    0 Votes
    11 Posts
    2k Views
    B
    Hi @m_adam Thanks for the patience. Your suggestions and reminders works are greatly appreciated. I guess the confusion stems mainly on my part because I posted slightly two different codes. You were responding to my initial post but I was thinking with the code from the succeeding post(the one in the rar file). Totally my bad. Anyhow, here is the working code (using the initial post) which works as I expected: import c4d class ColorButton(object): def __init__(self): self.width = None self.height = None self.color = None self.color = None self.btn_id = None self.menu_list = None def create(self, dlg, w, h, color, btn_id): self.width = w self.height = h self.color = color self.btn_id = btn_id bmp_color = c4d.bitmaps.BaseBitmap() bmp_color.Init(w, h) for y in xrange(w): for x in xrange(h): bmp_color.SetPixel(x, y, color[0], color[1], color[2]) bcBitmapButton = c4d.BaseContainer() bcBitmapButton[c4d.BITMAPBUTTON_BUTTON] = True bmp_btn = dlg.AddCustomGui(self.btn_id, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_CENTER | c4d.BFV_CENTER, w, h, bcBitmapButton) bmp_btn.SetImage(bmp_color, True) def create_menu(self): self.menu = c4d.BaseContainer() for menu_item in self.menu_list: counter = 0 IDM_MENU = c4d.FIRST_POPUP_ID + counter self.menu.InsData(IDM_MENU, menu_item) counter += 1 class MyDialog(c4d.gui.GeDialog): def __init__(self): self.btn_id_list = [] self.class_btn_id_dict = {} def CreateLayout(self): red_button = ColorButton() red_button.create(self, w=50,h=50,color=(255,0,0), btn_id=6000) red_button.menu_list = ['Menu1', 'Menu2', 'Menu3'] self.btn_id_list.append(red_button.btn_id) self.class_btn_id_dict[6000] = red_button blue_button = ColorButton() blue_button.create(self, w=50,h=50,color=(0,0,255), btn_id=7000) blue_button.menu_list = ['Menu4', 'Menu5', 'Menu6', 'Menu7'] self.btn_id_list.append(blue_button.btn_id) self.class_btn_id_dict[7000] = blue_button green_button = ColorButton() green_button.create(self, w=50,h=50,color=(0,255,0), btn_id=8000) green_button.menu_list = ['Menu8', 'Menu9'] self.btn_id_list.append(green_button.btn_id) self.class_btn_id_dict[8000] = green_button return True def IsPositionOnGadget(self, gadgetId, x, y): # Be sure that the windows is opened, # in our case since we call it in BFM_INTERACTSTART it's ok buttonData = self.GetItemDim(gadgetId) if not buttonData["x"] < x < buttonData["x"] + buttonData["w"]: return False if not buttonData["y"] < y < buttonData["y"] + buttonData["h"]: return False return True def function_to_determine_gadgetId_under_mouse_cursor(self, x, y): for gadgetId in self.btn_id_list: if self.IsPositionOnGadget(gadgetId, x, y): return gadgetId def Message(self, msg, result): if msg.GetId() == c4d.BFM_ADJUSTSIZE: self._x = msg[3] # Retrieve Y size of the GeDialog self._y = msg[4] # Retrieve Y size of the GeDialog # We are on the main thread here elif msg.GetId() == c4d.BFM_INTERACTSTART: c4d.StopAllThreads() state = c4d.BaseContainer() self.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSERIGHT, state) if state.GetInt32(c4d.BFM_INPUT_VALUE) == True: x = state.GetInt32(c4d.BFM_INPUT_X) y = state.GetInt32(c4d.BFM_INPUT_Y) g2l = self.Global2Local() x += g2l['x'] y += g2l['y'] gadgetId = self.function_to_determine_gadgetId_under_mouse_cursor(x=x,y=y) if gadgetId in self.btn_id_list: if self.IsPositionOnGadget(gadgetId=gadgetId, x=x, y=y): button_class = self.class_btn_id_dict[gadgetId] button_class.create_menu() l2s = self.Local2Screen() print str(x+l2s['x']) + " :: " + str(y+l2s['y']) self.KillEvents() res = c4d.gui.ShowPopupDialog(cd=self, bc=button_class.menu, x=x+l2s['x'], y=y+l2s['y']) return True return c4d.gui.GeDialog.Message(self, msg, result) if __name__ == "__main__": dlg = MyDialog() dlg.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=20304050)
  • 0 Votes
    8 Posts
    2k Views
    B
    Ok. I figured it out. The ID was wrong. It was supposed to be 465001634 -b
  • Identify when scene is rendering (Redshift)

    Cinema 4D SDK python
    6
    0 Votes
    6 Posts
    1k Views
    rsodreR
    @wen I was trying to do the same the past days. I could'nt figure out how to detect if Redshift IPR is enabled, but I found some relevant RS Ids. The 1038666 command opens the IPR window, but as far as I know there's no way to get the dialog instance to call IsOpen() The 1036752 CoreMessage is sent during IPR renders, but without any additional parameters (PAR1/PAR2). Not sure if there's something else we can extract from that message. What I ended up doing is adding a bool to my plugin to enable IPR features, but would be good to enable automatically.
  • Undo for GeDialog (GUI)?

    Cinema 4D SDK r21 python
    4
    0 Votes
    4 Posts
    541 Views
    B
    @blastframe @m_magalhaes Thanks for the response and the confirmation that Undo is not included in the GeDialog(GUI). That said the supplied code works on my use case. Thanks again!
  • Issue with registering a ToolData

    Cinema 4D SDK
    3
    0 Votes
    3 Posts
    711 Views
    a_blockA
    Hi Maxime, thanks a lot! Both are valid solutions for me. Very helpful. Cheers
  • Quick Tab Radio for GeDialog?

    Cinema 4D SDK r21 python
    4
    0 Votes
    4 Posts
    721 Views
    B
    @r_gigante Thank you for the response and especially for the alternative code (first time to see a line with msg[c4d.BFM_ACTION_VALUE]. Both code works as expected.
  • Add Commands to ShowPopupDialog

    Cinema 4D SDK r21 python
    7
    0 Votes
    7 Posts
    1k Views
    B
    @m_adam Thanks for further clarification. @Ashton_FCS_PluginDev 's code works but I guess I'll just use the result of the ShowPopupDialog to trigger commands, as I added in the previous code.
  • Creating Class for Buttons Returns None

    Cinema 4D SDK r21 python
    5
    0 Votes
    5 Posts
    566 Views
    B
    @m_adam Ah. Gotcha. Thanks for the clarification and link.
  • Get mode (object, face, edge, point) with python

    Cinema 4D SDK python
    4
    1
    0 Votes
    4 Posts
    905 Views
    W
    Thanks Sebastian.
  • Command() does not honor Dynamic Lists/Variable

    Cinema 4D SDK r21 python
    9
    0 Votes
    9 Posts
    974 Views
    B
    When you presented the order of execution of __init__(), CreateLayout and InitValues. That makes total sense especially the 2.2.1 when it resets to an empty list. Thanks for the clarification!
  • Drag&Drop an image in a gui field

    Cinema 4D SDK r20 python
    5
    1
    0 Votes
    5 Posts
    1k Views
    D
    @pim I'm trying to figure out how you did this. Could you please share a sample code of this example? I'm trying to get the full path of an image by dragging it into a edit text field... Cheers
  • How to Generate Dynamic Functions?

    General Talk r21 python
    3
    0 Votes
    3 Posts
    662 Views
    B
    Gotcha. Thanks for the code and confirmation. For my code, it's not really a simple printing the ID. Each ID corresponds with a separate function/script. I guess I'll just store them in a separate list. Separate ID list and separate function script list. Then execute them by matching index.
  • Retrieving Link from Hyperfile

    Cinema 4D SDK python sdk
    3
    1
    0 Votes
    3 Posts
    496 Views
    ?
    Thank you @r_gigante for the reply! Sorry if the intent is unclear: this self-contained script was something I came up with last night to demonstrate an issue I'm having in my plugin which is too many scripts to post to the forums. Since the user can't select an object after the script is running, I added that catch to make sure an object was selected to show what was going wrong. My Goal I am trying to save a link to a scene object and its matrix to a hyperfile so the user can load the hyperfile in another session and restore the link to the object so that I can apply the saved matrix. I don't need the object itself. Update I updated the original script's GetLink() method to pass a reference to the active document, but that did not solve the issue.
  • Cant select newly created Instance

    Cinema 4D SDK python
    7
    0 Votes
    7 Posts
    1k Views
    esanE
    @blastframe Ok was able to retrofit your version to get what I wanted, a bit of guesswork in here, but got the result im after lol import c4d from c4d import gui def createInstance(): obj = op.GetDown() inst = c4d.BaseObject(c4d.Oinstance) # created Instance with Base Object inst[c4d.INSTANCEOBJECT_LINK] = obj # set Instance's reference link # set the name using the object passed to the function inst[c4d.ID_BASELIST_NAME] = "%s Instance"%obj[c4d.ID_BASELIST_NAME] return inst # return the Instance instance def AddLongDataType(obj): # create User Data Container named Picker if obj is None: return bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_LONG) bc[c4d.DESC_NAME] = "Picker" doc.AddUndo(c4d.UNDO_CHANGE, obj) obj.AddUserData(bc) c4d.EventAdd() def setQuickTab(obj, inst, data): # change User Date container to type Cycle, populate with Children Names descid = data[0][0] bc = data[0][1] children = obj.GetChildren() # Build new cycle options container dynamically cycle = c4d.BaseContainer() for i,child in enumerate(children): cycle.SetData(i, child.GetName()) bc[c4d.DESC_CYCLE] = cycle doc.AddUndo(c4d.UNDO_CHANGE, obj) # Set modified description data container inst.SetUserDataContainer(descid, bc) def main(doc): obj = doc.GetActiveObject() if (obj == None): gui.MessageDialog("Please select the Root of the Assets you wish to Instance.") return doc.StartUndo() inst = createInstance() doc.InsertObject(inst) AddLongDataType(inst) data = inst.GetUserDataContainer() setQuickTab(obj, inst, data) doc.AddUndo(c4d.UNDO_NEW, inst) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main(doc)
  • Dragging an object from a treeview

    Cinema 4D SDK r20 python
    4
    1
    0 Votes
    4 Posts
    697 Views
    P
    Thanks, sounds a bit complicated, so I have to give it some thoughts. For now, it is enough. -Pim
  • Treeview and Right Click

    Cinema 4D SDK python r20
    3
    1
    0 Votes
    3 Posts
    449 Views
    P
    @mp5gosu said in Treeview and Right Click: RemoveData() Great, thanks.
  • Right Click Contextual Menu on a Button?

    Cinema 4D SDK r21 python
    3
    0 Votes
    3 Posts
    739 Views
    B
    @m_adam Works as expected! Thanks again for the sample code, makes everything clear.
  • Free Form GUI Design Layout?

    Cinema 4D SDK r21 python
    5
    0 Votes
    5 Posts
    718 Views
    B
    @r_gigante Thanks for the response. Unfortunately, I still can't read C++ codes at the moment. Is there a python equivalent of that page? I can't seem to see one. There is a page for that but it's like a dictionary. It does not contain any sample codes like in C++ If it does not exist, do you have any C++ with an equivalent Python page in the documentation? I'll just to interpolate them as much as possible. ########################## I also checked the Github sample and it does contain a GeUserArea sample But the button part is still in GeDialog. Is it possible to make the GeUserArea part to be clickable like a button?
  • 0 Votes
    3 Posts
    1k Views
    r_giganteR
    Hi jhpark, thanks for reaching out us. Aside from the notes left by @blastframe - thanks dude for the remarks - I think it's worthy, thinking of a more generic scene, to mention the need BaseDocument::ExecutePasses() to be sure that everything is actually evaluated before querying the scene rather than the EventAdd() which serves a different scope. This function is responsible to execute the scene evaluation and, consequently to be sure that, moving from a frame to another, all the items in the scene reflect the changes imposed by the frame switch. The approach used by @blastframe actually operates on CTracks and key but, although this approach works fine for your specific case, when more evaluation dependencies are created in the scene you could easily end up in unexpected results. The code could then look like frames_count = 10 # [Set] frames counter for f in range(0, frames_count): doc.SetTime(c4d.BaseTime(f, doc.GetFps())) # evaluate the scene doc.ExecutePasses(None, True, True, True, c4d.BUILDFLAGS_NONE) obj = doc.SearchObject('Cube') # get object position x = int(obj.GetMg().off.x) y = int(obj.GetMg().off.y) z = int(obj.GetMg().off.z) # get object color r = int(obj[c4d.ID_BASEOBJECT_COLOR].x * 255) g = int(obj[c4d.ID_BASEOBJECT_COLOR].y * 255) b = int(obj[c4d.ID_BASEOBJECT_COLOR].z * 255) print("Frame = " + str(f) + ", (X,Y,Z) = " + str(x) + "," + str(y) + "," + str(z) + ", RGB = " + str(r) + "," + str(g) + "," + str(b))