Hi Maxime - thank you very much for the response, and I'm glad to hear you're considering it for the future.
Freelance Plugin Developer
Posts made by dskeith
I'm trying to work with doc.StartPickSession(callback, multi) and I'm running into some questions.
Trying this simple code...
import c4d from c4d import gui def OnPick(active, multi): print "active: ", active print "multi: ", multi # Main function def main(): doc.StartPickSession(OnPick, multi=True) # Execute main() if __name__=='__main__': main()
I'm able to start a multi-object pick session, but once I double-click to complete it, I get this error:
TypeError: OnPick() takes exactly 2 arguments (3 given)
After a bit of detective work, it seems that adding a
mysteryvariable to my callback function
def OnPick(mystery, active, multi):fixes the error. When I run this:
import c4d from c4d import gui def OnPick(mystery, active, multi): print "mystery: ", mystery print "active: ", active print "multi: ", multi # Main function def main(): doc.StartPickSession(OnPick, multi=True) # Execute main() if __name__=='__main__': main()
I get this console output:
mystery: 0 active: [<c4d.BaseObject object called 'Cube/Cube' with ID 5159 at 0x00000290184D2B90>, <c4d.BaseObject object called 'Cube.1/Cube' with ID 5159 at 0x00000290184D2130>, <c4d.BaseObject object called 'Cube.2/Cube' with ID 5159 at 0x00000290184D2170>] multi: True
After a bit more detective work, it seems that
0if I complete the pick-session by double-clicking, and it's
1if I press
Escto finish the pick session.
- What is the
mysteryvariable, and what is it actually returning.
- Is there a way to trigger a multi-pick session where the user doesn't have to hold down shift/ctrl to select multiple elements?
- I'm noticing some weirdness in terms of which objects are selected in the Editor/Viewport after a pick session (especially if I end it by pressing
Esc). What messages/redraws do I need to call after a pick session? Do I need to handle undo or will C4D?
- What is the
RE: Documentation Plugin
Really cool Kent! Thank you for sharing.
- Does your plugin provide any sort of automation for adding "Show Help" links in C4D to specific parameters?
- Automatically fill in the image Alt-Text for the linked command icons with the name of the command/parameter.
- Auto List Parameters: Add a list of every parameter in a plugin's dialog/description so that we can easily document elements and see what isn't yet documented.
Forum Index CSS Styling
I know that design is subjective, but I'd like to request that you change the CSS styling of the topic headings from
Capitalize. At least from my perspective, it's much easier to read and scan for topics of interest when each word is clearly broken up with spacing & sizing.
I believe this is the CSS selector:
RE: R20 Script State Function
- Only passing True, False and c4d.CMD_ENABLED|c4d.CMD_VALUE will effect the icon state correct? it can't be done outside of the state() function?
Yes. You may be able to perform calculations elsewhere and store a state value in the document's container that you access in the
state()method, but I don't believe you can change the state elsewhere.
- I noticed when I put a print function inside of the state() function it seemed to loop endlessly? if I use this code:
Yes, it's "looping" every time the Cinema 4D interface updates/redraws.
state()function is seemingly run every time Cinema 4D's interface is redrawn. It's really there for determining whether a command that requires an object be selected is enabled or not. As it's run so frequently, any code you put in there could slow down all of C4D, so ensure that your state check is actually important, and if so, do your check as quickly as possible.
For example, a script that prints the name of the selected object should only be enabled when an object is selected.
"""Name-en-US: Echo Name Description-en-US: Opens a message dialog with the name of the selected object. """ import c4d from c4d import gui def state(): """Gray out icon if no objects are selected, or more than one object is selected. """ # `op` is a variable provided by C4D that represents the selected object. # I'm not certain, but I think this is faster than call doc.GetActiveObject() # but it will return `False` if more than one object is selected. if op is not None: return c4d.CMD_ENABLED else: return False def main(): """Open a dialog with the selected object's name. """ if op is None: return active_obj_name = op.GetName() gui.MessageDialog("You selected: " + active_obj_name) if __name__=='__main__': main()
RE: Python Effectors
Took a second look. It seems that you're trying to iterate on a list that doesn't exist.
. This likely happens because the instanced effector can't access the MoData of the other cloner that's been instanced (or something like that). I've taken the liberty of reworking your code to be a bit more error-tolerant:
import c4d from c4d.modules import mograph as mo def main(): # Retrieve User Inputs EB = op[c4d.ID_USERDATA,2] linked = op[c4d.ID_USERDATA,1] if linked is None: return True md = mo.GeGetMoData(op) if md is None: return True linked_md = mo.GeGetMoData(linked) if linked_md is None: return True md_count = md.GetCount() if not md_count: return True linked_md_count = linked_md.GetCount() if not linked_md_count: return True # If counts don't match between cloners, use the smaller number. clone_count = min([md_count, linked_md_count]) colors = md.GetArray(c4d.MODATA_COLOR) if colors is None: return linked_colors = linked_md.GetArray(c4d.MODATA_COLOR) if linked_colors is None: return for i in xrange(clone_count): colors[i] = linked_colors[i] + (linked_colors[i] * c4d.Vector(EB)) md.SetArray(c4d.MODATA_COLOR, colors, True) return True if __name__=='__main__': main()
But looking at your scene I'm not sure you'll get the result you want trying to colorize one cloner with a cloner object it's cloning.