UNSOLVED Force VertexMap display


You should not do this on an already inserted tag, the code I am showing above is as lined out very much in a grey area, or to be a bit more blunt, is a giant threading restriction violation. You should refrain from modifying the scene graph from outside of the main thread as much as you can, as this can introduce everything between odd behavior to outright crashes.

But I would say the singular insertion of the vertex map tag is somewhat safe. When you run into problems, you must defer all scene graph modifications, i.e., the insertion of that hidden tag, to the main thread. By for example using NodeData::Message to carry out something that before has been lined up by TagData::Execute.


I was creating the hidden VertexMap in the Init method of my plugin tag.
But my main problem, like I described, was that activating the hidden VertexMap tag would show the VertexMap parameters in the Attribute Manager, instead of the parameters of my plugin tag.

Hey @rui_mac,

But my main problem, like I described, was that activating the hidden VertexMap tag would show the VertexMap parameters in the Attribute Manager

I assume you mean here that the tag node was made the "active object" of the Attribute Manager, i.e., it had the same effect as if you called c4d.gui.ActiveObjectManager_SetObject on the hidden tag? This could be a side-effect of 'misbehaving' in a threaded environment, I assume you are in TagData::Execute, but it seems unlikely. Could you please share an executable example of your code, because otherwise it will be very hard for me to help you.


@ferdinand, here is a version of my code with all the stuff that is not important for this problem, removed. Although, I fully commented everything I removed.
I hope it is enough to spot the problem.

import c4d
import os
import sys
import math
import random

from c4d import gui,plugins,bitmaps,documents,utils,Matrix,BaseContainer
from c4d import threading

PLUGIN_ID = 1037312
CHECK_ID = 1037275
PLUGIN_NAME ="VertexMapMix"
url_access	= "vertexmapmix"

# define the IDs of the interface elements
VMM_ONOFF = 1000
VMM_ATOMS = 1002



VMM_SHOW = 2025


icon_edit = c4d.bitmaps.BaseBitmap()

# *******************************************************************************

class vertex_mm(plugins.TagData):

	old_selection	= 0
	old_pressed		= -1
	old_show 		= 1

	def Init(self,node):

		# in here I initialize all the GUI elements
		# ...

		# and in here I create the hidden VertexMap tag

		op = node.GetMain()
    	if not isinstance(op, c4d.PolygonObject): return True

			tags = op.GetTags()
			hidden_tag = None
			for tag in tags:
				if tag[c4d.ID_BASELIST_NAME] == "vmm_hidden":
					hidden_tag = tag

			if hidden_tag == None:
		return True

# *******************************************************************************

	def Message(self,node,type,data):

		if node==None: return True

		# this code would turn the display of the VertexMap values on or off,
		# depending on the state of a checkbok

			state =  node[VMM_SHOW]
			if state != self.old_show:
				self.old_show = state

				op = node.GetObject()
				if op.GetType() != 5100: return True

				tags = op.GetTags()
				hidden_tag = None
				for tag in tags:
					if tag[c4d.ID_BASELIST_NAME] == "vmm_hidden":
						hidden_tag = tag

				if hidden_tag == None:

				if state == 1:

		return True

# *******************************************************************************

	def Execute(self,tag,doc,op,bt,priority,flags):

		# here I do all the stuff that the plugin is supposed to do
		# at the end, in the list called w_array1, are all the values
		# to store in the hidden VertexMap tag, for display

		tags = op.GetTags()
		hidden_tag = None
		for tag in tags:
			if tag[c4d.ID_BASELIST_NAME] == "vmm_hidden":
				hidden_tag = tag

		if hidden_tag != None:

		# the "vertex_mix" is a visible VertexMap tag, where the values are also stored.
		# if it would be possible to make the VertexMap shading appear, simply by using
		# this visible VertexMap tag, I would be more than fine with this.
		# The problem, so far, is that I have to click this visible tag to make the
		# shading appear, and that makes all the parameters of my plugin Tag disapear
		# from the Attribute Manager.



# *******************************************************************************

# registration of the tag
if __name__=="__main__":

# Register the Tag
	icon = c4d.bitmaps.BaseBitmap()
	dir, file = os.path.split(__file__)
	icon.InitWith(os.path.join(dir, "res", "icon_vmm.tif"))
	icon_edit.InitWith(os.path.join(dir, "res", "edit.tif"))

	plugins.RegisterTagPlugin(id=PLUGIN_ID, str=PLUGIN_NAME, g=vertex_mm,
						 description="vertexmapmix", icon=icon,
	print("["+PLUGIN_NAME+" Tag - v"+PLUGIN_VERSION+"] by Rui Batista: Loaded")

Hello @rui_mac,

I will have a look tomorrow; I was busy today.


Hello @rui_mac,

So, I had a look at your code. It was unfortunately not executable in this form, even when I filled in some gaps like adding the necessary resources or re-indenting stuff. So, I cannot say many concrete things here, and only look at the general form.

I must also point out again, that this is a hack and not officially supported. If you chose to take this route instead of drawing the data yourself, possible side effects will be up to you to handle.

  • A general thing is that you seem to assume that Message, Init, and other methods to always run on the main thread. But there is no guarantee for that; when you want to carry out actions only allowed on the main thread, you must still check for being on the main thread. I however still think that adding a tag from a non-main thread was not your issue here.
  • This line in your Init is dangerous and might be the source for your problems, as you forcibly select the host object of your tag: op.SetBit(c4d.BIT_ACTIVE)
  • In general, you are also very generous with Message(c4d.MSG_UPDATE) calls. They are first of all here unnecessary for the flag changes and secondly also dangerous. I would never send messages to a node which is already part of the scene graph from threaded environment (you call op.Message(c4d.MSG_UPDATE) in multiple contexts).
  • Using the name of a node is a poor way of identifying a node, you should use UUIDs in Python.
  • I have provided below a TagData solution for your problem. This is quite a bit of busy work, especially when you want to properly clean up after yourself. This works fine for me.

if it would be possible to make the VertexMap shading appear, simply by using this visible VertexMap tag, I would be more than fine with this.

It would be the same, just iterate over the tags of the node hosting your tag and select whatever tags you want to select.


The result:
The plugin: pc14184.zip

The pyp file of the plugin:

"""Implements a tag which manages a hidden vertex map to draw data.
import c4d
import typing

class VertexMapMixData(c4d.plugins.TagData):
    """Implements a tag which manages a hidden vertex map to draw data.
    PLUGIN_ID: int = 1037312
    DRAWTAG_ID: int = 1060040

    PLUGIN_NAME: str = "VertexMapMix"
    PLUGIN_DESCRIPTION: str = "Tvertexmapmix"

    def __init__(self) -> None:
        """Initializes the instance, specifically its _hiddenDrawTags lookup table.
        self._hiddenDrawTags: dict[bytes: c4d.BaseTag] = {}

    def FlushHiddenTags(self, node: c4d.GeListNode) -> None:
        """Flushes the #_hiddenDrawTags cache and removes all the hidden tags from the hosting node.
        host: typing.Optional[c4d.BaseObject] = node.GetMain()
        if not isinstance(host, c4d.BaseObject):

        tag: c4d.BaseTag
        for tag in host.GetTags():
            if tag.GetType() != c4d.Tvertexmap:

            # This is a hidden drawing tag instance.
            uuid: typing.Optional[memoryview] = tag.FindUniqueID(VertexMapMixData.DRAWTAG_ID)
            if isinstance(uuid, memoryview):

        self._hiddenDrawTags = {}

    def GetHiddenDrawTag(self, node: c4d.PolygonObject) -> typing.Optional[c4d.VariableTag]:
        """Retrieves the hidden drawing tag on a polygon object.
        # Bail when #node is not a polygon object or not attached to a document.
        if (not isinstance(node, c4d.PolygonObject) or
                not isinstance(node.GetDocument(), c4d.documents.BaseDocument)):
            return None

        # Get the UUID of the polygon object so that we look up its hidden tag in the lookup.
        uuid: typing.Optional[memoryview] = node.FindUniqueID(c4d.MAXON_CREATOR_ID)
        if not isinstance(uuid, memoryview):
            return None

        # Check if there is already a cached hidden draw tag in dictionary of the plugin interface.
        hiddenTag: typing.Optional[c4d.BaseTag] = self._hiddenDrawTags.get(bytes(uuid), None)
        if isinstance(hiddenTag, c4d.BaseTag) and hiddenTag.IsAlive():
            return hiddenTag

        # Just for verbosity here to make clear that this can still return None.
        return None

    def SetHiddenDrawTag(self, node: c4d.BaseTag) -> None:
        """Creates the hidden drawing tag on a polygon object.
        # The host is not a polygon object or there is already a valid drawing tag on that host.
        if (not isinstance(node, c4d.PolygonObject) or
                isinstance(self.GetHiddenDrawTag(node), c4d.VariableTag)):

        # Flush the cache to remove any lingering tags and get the UUID of the polygon object so
        # that we cache the hidden draw tags.
        hostUuid: typing.Optional[memoryview] = node.FindUniqueID(c4d.MAXON_CREATOR_ID)
        if not isinstance(hostUuid, memoryview):

        # Start creating the new tag, for that we must be on the main thread.
        if not c4d.threading.GeIsMainThread():

        tag: c4d.VariableTag = c4d.VariableTag(c4d.Tvertexmap, node.GetPointCount())
        if not isinstance(tag, c4d.BaseTag):
            raise MemoryError("Could not allocate vertex map tag.")

        tag.AddUniqueID(VertexMapMixData.DRAWTAG_ID, bytes(True))
        tag.ChangeNBit(c4d.NBIT_OHIDE, True)

        # Put the tag in the lookup table.
        self._hiddenDrawTags[bytes(hostUuid)] = tag

    def Init(self, node: c4d.GeListNode) -> bool:
        """Called by Cinema 4D to initialize the node.
        self.InitAttr(node, c4d.BaseList2D, c4d.ID_SOURCE_DATA)
        self.InitAttr(node, bool, c4d.ID_DRAW_DATA)

        node[c4d.ID_SOURCE_DATA] = None
        node[c4d.ID_DRAW_DATA] = True

        # Attempt to create the tag, as all methods, Init is not guaranteed to be on the main thread.
        return True

    def Free(self, node: c4d.GeListNode) -> None:
        """Called by Cinema 4D when the node is about to be destroyed.

        Will remove all hidden tags on the node.

    def CopyTo(self, dest: c4d.plugins.NodeData, snode: c4d.GeListNode, dnode: c4d.GeListNode,
               flags: int, trn: c4d.AliasTrans) -> bool:
        """Called by Cinema 4D when a tag is being copied.

        Will remove all hidden tags on the source node, so that when a user drag-and_drops the tag 
        from object A to object B, object A is being cleaned up.
        return True

    def Message(self, node: c4d.GeListNode, type: int, data: object) -> bool:
        """Called by Cinema 4D to send messages to the node.

        We just use this here as something that is called often on the main thread. But there is
        no guarantee that this will run on the main thread, you were sending yourself a message, 
        MSG_UPDATE, to a node outside of the main thread in your TagData::Execute. Never assume
        Message to run on the main thread only.
        # Try to create the tag, could be throttled by picking a specific message ID which is
        # called often enough.
        return True

    def Execute(self, tag: c4d.BaseTag, doc: c4d.documents.BaseDocument, op: c4d.BaseObject,
                bt: c4d.threading.BaseThread, priority: int, flags: int) -> int:
        """Called by Cinema 4D to execute the tag.
        state: bool = tag[c4d.ID_DRAW_DATA]
        src: typing.Optional[c4d.VariableTag] = tag[c4d.ID_SOURCE_DATA]
        dst: typing.Optional[c4d.VariableTag] = self.GetHiddenDrawTag(op)

        # There is no source or destination tag we could write from or to.
        if not isinstance(src, c4d.VariableTag) or not isinstance(dst, c4d.VariableTag):
            return c4d.EXECUTIONRESULT_OK

        # Select or deselect the hidden tag.
        if tag[c4d.ID_DRAW_DATA]:

        # Determine of we should copy the data and then copy the data.
        if (src.GetType() != dst.GetType() or
                src.GetDataCount() != dst.GetDataCount()):
            return c4d.EXECUTIONRESULT_OK

        return c4d.EXECUTIONRESULT_OK

def RegisterPlugin() -> None:
    """Registers the plugin.
    if not c4d.plugins.RegisterTagPlugin(
            info=c4d.TAG_EXPRESSION | c4d.TAG_VISIBLE | c4d.TAG_MULTIPLE):
        raise RuntimeError(f"Failed to register: {VertexMapMixData}")

if __name__ == "__main__":

@ferdinand, thank you for the excellent advices.
I hope I can get home soon enough after work to clean up my code according to your advices and implement your solution.
Also, your advices will allow me to clean up some of my other plugins.
Thank you very much, once again.

Well, it kind of works. When I adjust parameters in the plugin tag, sometimes the Attribute Manager reverts to show "2 Elements [VertexMap,ThePluginName]"
I even tried with your plugin and, by twirling the Data Source parameter open and, for example, turning the Invert option on, the Attribute Manager stops showing the plugin parameters, and starts showing "2 Elements [VertexMap,VertexMapMax]"

Hello @rui_mac,

ah, okay, I understand what you mean. Yeah, that is a bit odd and also makes this solution not very viable. As I said before, this always was a hack. When I did this myself a few years ago, I think I never ran into this issue.

The underlying problem here is that the Attribute Manager is able to display a hidden tag as selected and the whole setup relies on the fact that hidden tags are being ignored in that context. It is also very erratic how this happens, when I for example click long enough on the Draw Data bool, the problem will also occur at some point and at the same time, it sometimes it does not happen 'inside' the vertexmap when I change a parameter there.

Since this seems to be tied to parameter writing events, you could try to switch off the hidden tag being selected before a parameter is being written and turn it back on after that. But that will become really complicated or even possible to do for 'buried' parameters changes, such as for example, changing something in a field driving a vertex map which is linked in the tag.

I will file this as a bug because the Attribute Manager should not be able to display hidden tags in single or multi-selections. In the meantime, I can only recommend using C++ and drawing things yourself or using CustomDataTagDisplayInterface, as this will be performant and is also guaranteed to work.


@ferdinand, thank you for the answer and explanation. I will try to find a compromise.
In the meanwhile, one can always select the tag, lock the Attribute Manager and click the VertexMap tag to display the result. Cumbersome, but it works.