Creating an Xpresso node
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/10/2010 at 21:24, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Windows ;
Language(s) : PYTHON ;---------
I want to dynamically create an XPresso node which references the current active material (or some other object).Using the python code below successfully creates a node, but it seems to reference the object the Xpresso tag belongs to by default (Cube). The code tries to use SetLink to change the object reference to a material, however in the Xpresso editor it still references the original Cube object.
Any idea how to create a node which references a specific object?
Aside: I saw the note about using GetParameter rather than GetDataInstance, but Python doesn't seem to support that method.
_
_def main() :
# Get Node master for selected Xpresso tag
nm = doc.GetActiveTag().GetNodeMaster()# This creates a Xpresso reference node
# to the Cube object containing the active tag
node = nm.CreateNode(nm.GetRoot(), c4d.ID_OPERATOR_OBJECT)# prints out 'Cube' as the node link
print node.GetOperatorContainer()[c4d.GV_OBJECT_OBJECT_ID].GetName()# Attempt to reference the active material instead
con = node.GetOperatorContainer()
con.SetLink(c4d.GV_OBJECT_OBJECT_ID, doc.GetActiveMaterial())
node.SetOperatorContainer(con)# prints out 'Mat' as the node link
print node.GetOperatorContainer()[c4d.GV_OBJECT_OBJECT_ID].GetName()# Add the new node to root XGroup
nm.InsertLast(nm.GetRoot(), node)# Node is now added to XPresso but is still a reference to Cube
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/10/2010 at 01:18, xxxxxxxx wrote:
Hi Trelane, please try:
mat = doc.GetActiveMaterial() if mat==None: return node[c4d.GV_OBJECT_OBJECT_ID]=mat
Cheers, Seb
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/10/2010 at 07:55, xxxxxxxx wrote:
Sebastian, thank you for the quick response, that worked!
Another question if I may. The Layer shader is behaving strangely. I'm trying to get at the shaders within a layer, but iterating over the layer container causes c4d to crash! Here is some sample code that crashes:
Before running, create material with Layer shader in reflection channel and add some layers
def main() :
# Get the Layer shader object inside material
mat = doc.GetActiveMaterial()
if mat==None: return
layerShader = mat[c4d.MATERIAL_REFLECTION_SHADER]
if layerShader==None: return# Prints 'Layer' so everything is fine up to here
print layerShader.GetName()# layerShader is not iterable so display container
con = layerShader.GetDataInstance()
for k,v in con:
print k,v# crash!
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 29/10/2010 at 09:35, xxxxxxxx wrote:
Can you please post a file so I can reproduce the crash? Here everything works as expected.
Cheers, Sebastian