Navigation

    • Register
    • Login
    • Search
    1. Home
    2. bentraje
    B

    bentraje

    @bentraje

    15
    Reputation
    686
    Posts
    378
    Profile views
    1
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    bentraje Follow

    Best posts made by bentraje

    RE: LINK EFFECTORS TO CLONERS

    Hi,

    Not quite directly a revision of your code but this should help you get started.

    import c4d
    from c4d import gui
    
    # Main function
    def main():
        cloner = doc.SearchObject("Cloner") # Assuming there is already a Cloner Mograph Object 
        plain_effector = doc.SearchObject("Plain")# Assuming there is already a Plain Effector Object 
    
        effector_list = c4d.InExcludeData()
        effector_list.InsertObject(plain_effector, 1)
    
        cloner[c4d.ID_MG_MOTIONGENERATOR_EFFECTORLIST] = effector_list
        c4d.EventAdd()
    
    
    # Execute main()
    if __name__=='__main__':
        main()
    
    posted in Cinema 4D SDK •
    RE: How to detect a new light and pram change?

    @Dunhou
    I fork that redshift light manager last time.
    https://github.com/bentraje/c4d_redshift_light_lister

    I just change the minimum for it to work on the latest C4D versions.
    It works on C4D 2023, last time I check, and on RS 3.5, but not all parameters are fully supported since I didn't refactor that much.

    2002c62c-f3a1-4565-9dd7-4136add8ceba-image.png

    posted in Cinema 4D SDK •
    RE: requirenments for building Cinema 4D extension

    Cinema4D can accommodate plug-ins written in C++ or Python. However, it only accept scripts written in Python.

    posted in General Talk •
    RE: Developing .obj sequence exporter for selected objects

    Probably not that helpful but there is an existing script for the C4D OBJ Sequence Exporter
    https://richh.co/c4d-native-obj-sequence-export-no-plugins/

    posted in Cinema 4D SDK •
    RE: Disable a tag from Python

    Hi @blieque

    You can do is the Basic>Enable Checkbox in every object.
    If you drag it to the console, the parameter is [c4d.ID_BASEOBJECT_GENERATOR_FLAG]

    posted in Cinema 4D SDK •
    RE: Modify the Default Untitled Python Script

    Thanks Adam for the confirmation.
    I'll just send it for Maxon Suggestion for now.

    Thanks!

    posted in Cinema 4D SDK •
    RE: Get/Fetch Node from an Existing Xpresso Tag

    Thanks @m_adam. Works as expected.
    My bad, I was looking at the documentation hierarchy erroneously (i.e c4d > modules > graphview > GvNode)

    Just a note: I think the if Multiply: line is supposed to be if isMultiply:.

    Thanks again. Have a great day ahead!

    posted in Cinema 4D SDK •
    RE: Get the Button GadgetID Directly Under the Mouse?

    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)
    
    posted in Cinema 4D SDK •
    RE: Content Browser Like Navigation?

    @r_gigante

    Thanks for the reference.
    For anyone trying to achieve the same,
    here is a sample file.
    https://www.dropbox.com/sh/z1lzyphp8qnt9kw/AAB2P5gNo16IHafgc6xPEsy4a?dl=0

    Thanks again for @zipit for the help.

    posted in Cinema 4D SDK •
    RE: Copy, Paste, Flip X a Pose Morph Target?

    @m_magalhaes @zipit

    I managed to flip the mesh (not necessarily a pose morph target since I'd have to know the API).
    Anyhow, here is a demo of it working:
    https://www.dropbox.com/s/bh4p26s4m9qwljw/c4d272_flip_miror_mesh.mp4?dl=0

    Here is wip script. It only works if the x-axis is dead set on 0.
    Also, it is slow since it has to loop within a loop.

    import c4d
    from c4d import gui
    
    
    # Main function
    def main():
        neutral_geo = doc.SearchObject('neutral_geo')
        posed_geo = doc.SearchObject('posed_geo')
        neutral_world_matrix = neutral_geo.GetMg()
        posed_world_matrix = posed_geo.GetMg()
        
        neut_lcl_pnts = neutral_geo.GetAllPoints()
        neut_gbl_pnts = [point * neutral_world_matrix for point in neut_lcl_pnts]
        
        posed_lcl_pnts = posed_geo.GetAllPoints()
        posed_gbl_pnts = [point * posed_world_matrix for point in posed_lcl_pnts]
            
        match_pnts = []
        left_pnts = []
        right_pnts = []
        
        for idx, point in enumerate(neut_gbl_pnts):
            if point[0] == 0.0: # ignore points at the world x axis
                continue
            
            if point[0] > 0.0:
                left_pnts.append((idx,point))
            
            if point[0] < 0.0:
                right_pnts.append((idx,point))
                
        
        for left in left_pnts:
            for right in right_pnts:
                if left[1][1] == right[1][1]: # check if Y pos match
                    if left[1][2] == right[1][2]: # check if Z pos match
                       if left[1][0] == -1 * (right[1][0]):# check if X pos are inverse
                           match_pnts.append((left[0],right[0]))
            
            
        for pnt in match_pnts:
            
            reversed_left = posed_lcl_pnts[pnt[1]]
            reversed_left[0] = reversed_left[0] * -1
            reversed_right = posed_lcl_pnts[pnt[0]]
            reversed_right[0] = reversed_right[0] * -1
            
            
            posed_geo.SetPoint(pnt[0], reversed_left)
            posed_geo.SetPoint(pnt[1], reversed_right)
            
        posed_geo.Message(c4d.MSG_UPDATE)
         
        c4d.EventAdd()
    
    # Execute main()
    if __name__=='__main__':
        main()
    
    posted in Cinema 4D SDK •

    Latest posts made by bentraje

    Release API for Modifying Camera Selection on Render Queue

    Hi,

    AFAIK, it is not possible to change the camera selection after adding it to the render queue.
    So you have to do the following through script:

    1. Change to Camera A
    2. Save Document
    3. Add to Render Queue
    4. Change to Camera B
    5. Save Document
    6. Add to Render Queue
      etc etc

    It works but the setback is on saving document. I have a 1GB ish document file and it takes a lot of time to save the document and doing it everytime I want to add a camera to queue (through scripting) is just painful.

    Is there away to just expose that camera parameter on render queue dialogue? So I don't have to save every document for every camera.

    Regards,
    Ben

    posted in Cinema 4D SDK •
    RE: Unsolo a Node?

    @m_adam

    Thanks. Works as expected!

    posted in Cinema 4D SDK •
    RE: Unsolo a Node?

    Hi @ferdinand

    Yes, I'm referring to that script.
    Is there a corresponding UNSOLO script?

    posted in Cinema 4D SDK •
    Unsolo a Node?

    Hi,

    The sample script provides a way to solo a node.
    But how do I exactly unsolo it?

    Or is it just possible to iterate through all the nodes. And just manually brute force it myself.

    Something like this. And just call it a day.

    for node in node_list:
         node.solo = False
    

    Regards,
    Ben

    posted in Cinema 4D SDK •
    RE: List All Nodes With No Filter?

    RE: Yes, GraphModelHelper.ListAllNodes requires at least one attribute to be set in the data dictionary.

    Gotcha. Thanks for the clarification.
    Anyway, the suggested alternative (i.e. write a separate iterator) still works as expected. Same as before.

    posted in Cinema 4D SDK •
    List All Nodes With No Filter?

    Hi,

    I created a thread before on listing all nodes but it is limted to having a filter property.

    I tried using an empty dictionary but it errors.

    I just want to have a list of all the nodes in a given graph/material (like what doc.GetMaterials() does) and perform my own filtering later on.

    Is this possible?

    posted in Cinema 4D SDK •
    RE: Relative File Path Not Recognize by Plug-in?

    @spedler @ferdinand

    Thanks for the response! Just checked the documentation, can't use GeGetPluginPath(). Per documentation, it does not behave the same with as C++. So I ended up using the __file__ method.

    Works as expected. Thanks for the illustration code!

    posted in Cinema 4D SDK •
    RE: Run a GUI Dialog AFTER C4D Launches not BEFORE?

    @ferdinand

    Thanks for the response.

    With the illustration code you provided, I misunderstood the documentation. Thanks for the clarification.

    Basically, I thought the

    PluginMessage/RegisterPlugin functions should be method (i.e. they should be under the class of the plugin data, command data etc).

    They actually live outside the classes.

    It now works as expected.
    Thanks! 🙂

    posted in Cinema 4D SDK •
    RE: Run a GUI Dialog AFTER C4D Launches not BEFORE?

    @ferdinand

    Ah gotcha. There is no way around it as again I don't want to initialize the plug-ins at all until the UI + check works out.

    Anyway, having the the GUI dialog before C4D launches is not bad.
    I was just wondering if I can do it after without initializing all the plugins.

    posted in Cinema 4D SDK •
    Relative File Path Not Recognize by Plug-in?

    Hi,

    I have a plug-in directory that goes like this:

    myPlugin.pyp
    config.json
    

    In my pyp file, I have this code block

    import json
    
    json_file = r"config.json"
    with open(json_file, "r") as f:
    	data = json.load(f)
    

    but it gives me an error of FileNotFoundError:[Errno 2] No such file or directory: 'config.json

    Is there a way around this?

    posted in Cinema 4D SDK •