Page 1 of 2 12 LastLast
Results 1 to 15 of 24

Thread: Accessing keys of a Curve Node

  1. #1

    Accessing keys of a Curve Node

    Hello Guys,
    I tried to google this up but couldn't find any reference, so the question is:
    How do I access envelopes/channels of a node, namingly the envelopes of a Curve node created inside the Displacement node editor?
    Is it possible at all?
    Thanks in advance for any answer.

  2. #2
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    36
    I think most if not all channel envelopes can be accessed through Python. But I might be wrong.
    If you can activate the envelope i think LWPython can access it, read it and manipulate it. I find it really tricky though.

    You will need to make use of these functions and classes:

    classes

    Code:
    lwsdk.LWInterfaceInfo()
    lwsdk.LWItemInfo()
    lwsdk.LWChannelInfo()
    lwsdk.LWEnvelopeFuncs()
    functions/ methods

    Code:
    lwsdk.LWInterfaceInfo().selected_items()
    lwsdk.LWItemInfo().chanGroup()
    lwsdk.LWChannelInfo().nextGroup()
    lwsdk.LWChannelInfo().channelName()
    LWEnvelopeFuncs() has about 21 methods to work with. With these you can read and manipulate the keys and tailor your script to your needs.

    The tricky part is getting to the value you want to manipulate, which in your case is the curve node envelope value. Using the lwsdk.LWItemInfo().chanGroup() and lwsdk.LWChannelInfo().nextGroup() is the key to travel down the subgroup list.

    Image

    Click image for larger version. 

Name:	Screen Shot 2017-03-19 at 02.14.10.png 
Views:	30 
Size:	11.8 KB 
ID:	136309

    Object.CurveNode.CurveRed.Key.Value


    you will need to loop through 3 subgroups in this example:

    Code:
    SelectedObject = lwsdk.LWInterfaceInfo().selected_items()
    
    for x in range(0, len(SelectedObject)):
    	channelGroup = lwsdk.LWItemInfo().chanGroup(selectedObject) #object
    	channelGroup = lwsdk.LWChannelInfo().nextGroup(channelgroup, None) #subgroup CurveNode
    	channelGroup = lwsdk.LWChannelInfo().nextGroup(channelgroup, None) #subgroup CurveRed
    	channelGroup = lwsdk.LWChannelInfo().nextGroup(channelgroup, None) #subgroup Key
    	channel = lwsdk.LWChannelInfo().nextChannel(channelgroup, None) #subgroup Value
    	channelName = lwsdk.LWChannelInfo().channelName(channel)
    	
    	while channel != None:
    		channelName = lwsdk.LWChannelInfo().channelName(channel)
    		
    		if channelName == "Value":
    			# your magical script here
    			
    		channel = lwsdk.LWChannelInfo().nextChannel(channelgroup, channel) #subgroup Value

    Hope this gets you on the right track.

  3. #3
    Thanks a lot, I give it a try.

  4. #4
    I can reach now the Curve node inside the displacement. I want to control the Curve keys using a few Nulls so I don't have to setup expressions

    Code:
    def findEnv(self, itemType):
    		id = lwsdk.LWItemInfo().first( itemType, None )
    		groupID = lwsdk.LWItemInfo().chanGroup( id )
    		parent = None
    		while groupID:
    			if groupID != None:
    				groupName = str ( lwsdk.LWChannelInfo().groupName(groupID) )  #group name
    				print ("groupID: " +  groupName)
    				if 'Curve' in groupName:
    					print 'Curve node'
    					chan = lwsdk.LWChannelInfo().nextChannel(groupID,parent)
    					while chan:
    						channelName = lwsdk.LWChannelInfo().channelName(chan)
    						nextchan = lwsdk.LWChannelInfo().nextChannel(groupID, chan)
    						print("channelName:" + channelName)
    						chan = nextchan
    					
    			nextid = lwsdk.LWChannelInfo().nextGroup(groupID,parent) 
    			parent = groupID
    			groupID = nextid
    
    					
    		chinfo = lwsdk.LWChannelInfo()
    		chan = chinfo.nextChannel(groupID, None)
    		while chan:
    			channelName = chinfo.channelName(chan)
    			nextchan = chinfo.nextChannel(groupID, chan)
    			print("channelName:" + channelName)
    			chan = nextchan

  5. #5
    Quote Originally Posted by bazsa73 View Post
    I want to control the Curve keys using a few Nulls so I don't have to setup expressions
    What do you mean? How would you control the envelope without an expression? And further control specific keyframes?
    My opinions and comments do not represent those of my employer.
    www.ernestpchan.com
    www.zazzle.com/gopuggo

  6. #6
    Quote Originally Posted by ernpchan View Post
    What do you mean? How would you control the envelope without an expression? And further control specific keyframes?
    I dont want to write for each frigging key in the curve an expression. I want one master expression which handles all the keys in the curve.

  7. #7
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    36
    Quote Originally Posted by bazsa73 View Post
    I dont want to write for each frigging key in the curve an expression. I want one master expression which handles all the keys in the curve.
    If I understand correctly, you would like to attach an expression the old-fashioned way (in the Expressions tab in the Graph Editor) to all selected keys in a single-shot? I don't really see any information how to attach expressions directly to the expressions tab in the graph editor. But than again you can write clever code in python to do all this. But there are no examples of this. It's up to you i think to come up with something like that, Told you it was tricksy

  8. #8
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    36
    If I understand correctly, you would like to attach an expression the old-fashioned way (in the Expressions tab in the Graph Editor) to all selected keys in a single-shot?
    Correction: sorry i meant, expressions get attached to channels not keys.

  9. #9
    Quote Originally Posted by Diepgroen View Post
    If I understand correctly, you would like to attach an expression the old-fashioned way (in the Expressions tab in the Graph Editor) to all selected keys in a single-shot? I don't really see any information how to attach expressions directly to the expressions tab in the graph editor. But than again you can write clever code in python to do all this. But there are no examples of this. It's up to you i think to come up with something like that, Told you it was tricksy
    I tell you my problem first which has started this whole issue. I do this video mapping on a building, it is very wide.
    I build geometry on the existing geometry from several parts and I use DPkit part move on it to do different motion graphic stuff. I control the parts via Curve nodes.
    Typically one curve contains 4 keys at least and each key has a position and a value envelope. That's already 8 things to control. I want to write a script which handles
    this for me. Let's say some sort of master plugin which evaluates on a per frame basis and adjusts the keys accordingly.

  10. #10
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    36
    Quote Originally Posted by bazsa73 View Post
    I tell you my problem first which has started this whole issue. I do this video mapping on a building, it is very wide. I build geometry on the existing geometry from several parts and I use DPkit part move on it to do different motion graphic stuff. I control the parts via Curve nodes.
    Typically one curve contains 4 keys at least and each key has a position and a value envelope. That's already 8 things to control. I want to write a script which handles this for me. Let's say some sort of master plugin which evaluates on a per frame basis and adjusts the keys accordingly.
    Quote Originally Posted by bazsa73 View Post
    I tell you my problem first which has started this whole issue. I do this video mapping on a building, it is very wide.
    I build geometry on the existing geometry from several parts and I use DPkit part move on it to do different motion graphic stuff. I control the parts via Curve nodes. Typically one curve contains 4 keys at least and each key has a position and a value envelope. That's already 8 things to control. I want to write a script which handles this for me. Let's say some sort of master plugin which evaluates on a per frame basis and adjusts the keys accordingly.
    I won't be much help to you at my level of coding, sorry.

    At least we know now that it's not about the Expressions Tab and attaching literal LWExpressions via Python. Because i think that part was not possible to my knowledge. But at least you got the channel you where looking for. Hope you can figure it out. If you do, let us know how you solved this problem.

  11. #11
    Quote Originally Posted by Diepgroen View Post
    I won't be much help to you at my level of coding, sorry.

    At least we know now that it's not about the Expressions Tab and attaching literal LWExpressions via Python. Because i think that part was not possible to my knowledge. But at least you got the channel you where looking for. Hope you can figure it out. If you do, let us know how you solved this problem.
    Thanks for your efforts dude. Maybe this is just way too difficult issue to deal with but I dont give up on it. Thanks again.

  12. #12
    I can reach the channel but I can't figure out how to attach the expression to it. Darn.
    In order to test this script one needs to create a deformational nodal setup for any object on the Deform tab under node editor adding a Curve node.
    In this case the Alpha channel is used so tick its envelopes, any of them will be ok. 1 is enough.

    Code:
    import sys
    import lwsdk
    import random
    import math
    
    __author__     = "Bazsa"
    __date__       = "2017"
    __copyright__  = "Bazsa"
    __version__    = "0.1b"
    __maintainer__ = "Bazsa"
    __email__      = "info@visionsupreme.net"
    __status__     = "beta"
    __lwver__      = "11"
    serverClasses = {   lwsdk.LWCAMERA_HCLASS:          'CameraHandler', \
                        lwsdk.LWCUSTOMOBJ_HCLASS:       'CustomObjHandler', \
                        lwsdk.LWDISPLACEMENT_HCLASS:    'DisplacementHandler', \
                        lwsdk.LWIMAGEFILTER_HCLASS:     'ImageFilterHandler', \
                        lwsdk.LWINSTANCER_HCLASS:       'InstancerHandler', \
                        lwsdk.LWITEMMOTION_HCLASS:      'ItemMotionHandler', \
                        lwsdk.LWLIGHT_HCLASS:           'LightHandler', \
                        lwsdk.LWOBJREPLACEMENT_HCLASS:  'ObjReplacementHandler'   }
    
    	
    class addexpr(lwsdk.IGeneric):
    	
    	def __init__(self, context):
    		super(addexpr, self).__init__()
    		#LWGeneric -------------------------------------------
    		itemType = lwsdk.LWI_OBJECT
    		id = lwsdk.LWItemInfo().first( itemType, None )
    
    		groupID = lwsdk.LWItemInfo().chanGroup( id )
    		prev = None
    
    		chinfo = lwsdk.LWChannelInfo()
    
    		subgroup = chinfo.nextGroup(groupID,prev)
    		
    		while subgroup:
    			if subgroup != None:
    				groupName = str ( chinfo.groupName(subgroup) )  #group name
    				print ("groupID: " +  groupName)
    				if 'Curve' in groupName:
    					curveprev = None
    					subgroupID = subgroup
    					curvesubgroup = chinfo.nextGroup(subgroupID,curveprev)
    					while curvesubgroup:
    						if curvesubgroup != None:
    							groupName = str ( chinfo.groupName(curvesubgroup) )  #group name
    							print ("subgroupID: " +  groupName)
    							
    							if 'Alpha' in groupName:
    								alphaprev = None
    								alphagroupID = curvesubgroup
    								alphasubgroup = chinfo.nextGroup(alphagroupID,alphaprev)
    								while alphasubgroup:
    									if alphasubgroup != None:
    										groupName = str ( chinfo.groupName(alphasubgroup) )  #group name
    										print ("subgroupID: " +  groupName)
    										chan = lwsdk.LWChannelInfo().nextChannel(alphasubgroup,None)
    										if chan != None:
    											channelName = lwsdk.LWChannelInfo().channelName(chan)
    											print("channelName:" + channelName)
    											channelEnvelope =lwsdk.LWChannelInfo().channelEnvelope(chan)
    											cmd = "GE_CreateExpression " + "chExpr " + "([csild.Position.X])"  
    											lwsdk.command(cmd)
    											cmd = "GE_AttachExpression " + "PalaceWindowsOnly:Layer2.Curve (1).Alpha.Key (1).Pos" + " chExpr"
    											#cmd = "GE_AttachExpression " + str(channelEnvelope) + " chExpr"
    											lwsdk.command(cmd)
    									alphasubgroup = chinfo.nextGroup(alphagroupID,alphasubgroup)
    							
    						curvesubgroup = chinfo.nextGroup(subgroupID,curvesubgroup)
    
    				
    				prev = groupID
    				groupID = subgroup
    				subgroup = chinfo.nextGroup(groupID,prev)
    				
    		
    		# while groupID:
    			# if groupID != None:
    				# groupName = str ( lwsdk.LWChannelInfo().groupName(groupID) )  #group name
    				# print ("groupID: " +  groupName)
    				
    			# nextid = lwsdk.LWChannelInfo().nextGroup(previous,groupID) 
    			# previous = groupID			
    			# groupID = nextid
    			
    			# chan = lwsdk.LWChannelInfo().nextChannel(groupID,None)
    			# while chan:
    				# channelName = lwsdk.LWChannelInfo().channelName(chan)
    				# print("channelName:" + channelName)
    				# nextchan = lwsdk.LWChannelInfo().nextChannel(groupID, chan)
    				# chan = nextchan
    	
    	# cmd = "GE_CreateExpression " + "fasz " + "([csild.Position.X])"  
    	# lwsdk.command(cmd)
    	# cmd = "GE_AttachExpression " + "PalaceWindowsOnly:Layer2.Curve(1).Alpha.Key(2) " + "fasz"
    	# lwsdk.command(cmd)
    	
    # def recursiveChannelWalk(parent,groupID):	
    		# while groupID:
    			# if groupID != None:
    				# groupName = str ( lwsdk.LWChannelInfo().groupName(groupID) )  #group name
    				# print ("groupID: " +  groupName)
    				
    			# groupID = lwsdk.LWChannelInfo().nextGroup(parent,groupID) 
    				
    		# parent = lwsdk.LWChannelInfo().groupParent(groupID)	
    		# recursiveChannelWalk(parent,groupID)	
    
    
    ServerTagInfo = [
    	( "addexpr", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
    	( "addexpr", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
    	( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
    	]
    
    ServerRecord = { lwsdk.GenericFactory("addexpr", addexpr) : ServerTagInfo }
    Last edited by bazsa73; 03-26-2017 at 03:37 AM. Reason: error in code

  13. #13
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    36
    Quote Originally Posted by bazsa73 View Post
    I can reach the channel but I can't figure out how to attach the expression to it. Darn.
    In order to test this script one needs to create a deformational nodal setup for any object on the Deform tab under node editor adding a Curve node.
    In this case the Alpha channel is used so tick its envelopes, any of them will be ok. 1 is enough.
    That's good progress Bazsa! I had it all wrong ofcourse. You can indeed attach Expressions.

    GE_CreateExpression sname sexpression
    GE_AttachExpression schannelname sexpressionname
    GE_AttachExpressionID xchannelid sexpressionname

    Your commands are not recognising the Expressions?
    Last edited by Diepgroen; 03-26-2017 at 06:31 AM. Reason: end qoute tag missing

  14. #14
    Quote Originally Posted by Diepgroen View Post
    That's good progress Bazsa! I had it all wrong ofcourse. You can indeed attach Expressions.

    GE_CreateExpression sname sexpression
    GE_AttachExpression schannelname sexpressionname
    GE_AttachExpressionID xchannelid sexpressionname

    Your commands are not recognising the Expressions?
    Cheers,
    Dude, it works on an ordinary Camera.Position.X channel like a charm. I just run the script and I see the dot in the graph editor indicating
    that a script has been attached to it. But this uncommon Curve node key envelope channel just doesn't behave in a similar manner. Is it due to the spaces in the name?
    Just can't get my head around it. Darn.

  15. #15
    Registered User Diepgroen's Avatar
    Join Date
    Jul 2016
    Location
    Amsterdam
    Posts
    36
    Quote Originally Posted by bazsa73 View Post
    Cheers,
    Dude, it works on an ordinary Camera.Position.X channel like a charm. I just run the script and I see the dot in the graph editor indicating
    that a script has been attached to it. But this uncommon Curve node key envelope channel just doesn't behave in a similar manner. Is it due to the spaces in the name?
    Just can't get my head around it. Darn.
    You are almost there, man! You got at least the Camera.Position.X to work. If you are not reaching the value of the curve node is because of a typo in the name. Because you are putting the literal name yourself it might be incorrect somehow. Don't know for sure. But looking at the image i posted before there is a double dot (..) in the name.

    Might that be causing trouble?
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Screen Shot 2017-03-19 at 02.14.10.png 
Views:	27 
Size:	11.8 KB 
ID:	136350  

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •