0
$\begingroup$

I cannot find any documentation for the existing CollectionProperty methods.

Regardings properties, generally i find .../bpy.props.html helpful, but it doesn't have any method declarations. Usually with other properties this isn't necessary, as they just give me a value of a regular python type that I know - like StringProperty which yields a string.

With a CollectionProperty this is different: it gives me some sort of collection, I can iterate over it, but it is not a simple python structure. There is the official doc of .../bpy.types.CollectionProperty.html, but it lacks documentation for the add and remove methods (it never mentions them).

Related Question: Remove from CollectionProperty

Apparently there is also a move method: CollectionProperty - change item's index

Are there anydocs out there?

P.S. digging through the blender source (of some cloned repo, because I like browsign github) I found this: https://github.com/dfelinto/blender/blob/master/source/blender/python/intern/bpy_props.c#L3029

However I cannot find any hints in there with respect to the existing methods.

$\endgroup$
  • $\begingroup$ nah, pardon my french but the example is rather weak. It doesn't show how to remove things from the collection, or how to add already existing instance ... $\endgroup$ – IARI Jul 18 '18 at 8:48
  • 3
    $\begingroup$ Bloody French. This one sums it up well too Also using autocomplete in py console. There is no argument that the docs are a little lacking. $\endgroup$ – batFINGER Jul 18 '18 at 8:50
  • $\begingroup$ thx, but that still doesn't show me, how to add an element to a collectionproperty that already exists - I can only call the add() method and Blender will create some new instance. Also: do you really have to iterate over the whole list to clear it? ... That's not exactly a nice api, if that is all ... isn't there at least a place in the source code that somehow shows me, what methods are really exposed on that type? $\endgroup$ – IARI Jul 18 '18 at 9:02
  • 1
    $\begingroup$ Consider. collection.clear() may not have been available at the time of writing that answer. IMO a question like "How to copy a collection item?", or something with CRUD in the title... would be a far more productive route than bemoaning "The docs aren't perfect" $\endgroup$ – batFINGER Jul 18 '18 at 12:13
  • $\begingroup$ The documentation is open source too. Submit a patch or ask something we can solve @IARI $\endgroup$ – brockmann Jul 18 '18 at 12:28
2
$\begingroup$

You are right about the documentation. The Python Console is your friend here. It offers autocomplete "intellisense" when you hit CtrlSpace after a . or a (:

enter image description here

You get the methods documentation from the source if there is one. In CollectionProperty case there is none:

enter image description here

The traceback error gives another hint:

enter image description here

If this does not help you search google, this site, blenderartists or your favorite blender python blogs for the functions you are interested in for more info or code examples. Since you now know what is available and what you are after, this should give better results than searching just for documentation.

If that still fails, chances are that you are after something only couple of people in the world know. You can look into the source code where you find bpy_props.c and then you dig. If you don't get too far the best bet in this case is to contact developers on official channels (mail, IRC) and ask there.

$\endgroup$
  • $\begingroup$ Docs to me are the last resort for when I can't nut it out with the console. Nice when there are good docs (example) tho. $\endgroup$ – batFINGER Jul 18 '18 at 12:11
  • $\begingroup$ I haden't used the Blender-builtin console, since I generally prefer to write code in a single place, but I will check that out. seems like a very good solution to the problem of the lack of proper docs. $\endgroup$ – IARI Jul 18 '18 at 12:55
  • $\begingroup$ with your post and some more google I have found this: docs.blender.org/api/2.79/bpy.types.bpy_prop_collection.html $\endgroup$ – IARI Jul 18 '18 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.