0
$\begingroup$

My desire is to illustrate dates of sales for townhouses by changing the visible material (changing colors, or changing Shaders, etc). The order of what houses sold when are out of sequence; it's real-world dates I'm using and the time scale is one frame to one day.

I have 98 houses and 98 dates spread wildly over three years. I see tons of tutorials for changing colors, etc. based on the location of an empty, but I know too little about AN to make the leap from that to what I need which would tie a list of "dates" (frames) to Objects to trigger a material change or Mix.

$\endgroup$
  • $\begingroup$ Can you post some example text of what the dates look like? Do you have a method to correlate each date to each house? (eg, is each house a separate named object, and you have a name for each date?) Ways to attach the dates to the objects, is the first problem. The rest may be quite an open-ended question with many solutions/steps. A first suggestion would be using basic scripting (copy/paste operator calls) in a for-loop to set each object's pass index to the numerical value of the date. Or add keyframes directly via script. Not sure AN makes that part any easier. $\endgroup$ – acro Aug 27 '19 at 5:23
  • $\begingroup$ ex. December 20, 1972 address 7865 sold (all data entered by hand). Correlation method is what killed me when I originally asked. Suddenly remembered Key:Value in Python (Lists, Dictionaries and ... something). AN can do this? Searched AN Docs finding Loops and also wondered if the answer begins with that - Setting an object's pass index seems important but scripting keyframes seems more accurate. Those are useful tips! $\endgroup$ – HelloHiHola Aug 27 '19 at 13:38
  • $\begingroup$ The 'object pass id' was just an example of a property you could set per object which you can then read as a numerical value in the node tree (i.e. via an Object Attribute node). I could write up an answer showing how to script-convert those dates to keyframe numbers and set a keyframe on an object based on that, if that would help? The main problem seems to be how to set the data somewhere in-scene. After you have the frame number readable in-scene you can use AN to do anything you like with it, right? (Also, to be clear, are you on Blender 2.79b for this?) $\endgroup$ – acro Aug 27 '19 at 23:59
1
$\begingroup$

Here's one possible way to go about converting your date data into something you can utilize in Animation Nodes or elsewhere.

  1. Paste the below script into a new text block in Blender's text editor.
  2. Paste your date / address list into the triple-quoted text block of the 'houseData' variable. I've followed your example format. The below is assuming you have an object named eg '7865' for every house, already added to your scene. (inserting / creating those 98 objects in a script loop is outside the scope of your question as written, so apologies for not covering that here).

Note: The script is splitting the date from the address using the word 'address' just as you wrote it, but feel free to change the format with any short separator as needed, and just edit the entry.split("address") part accordingly if you do.

  1. Run the script (alt-p in the text editor or press the Run Script button).
import bpy
from datetime import datetime

housedata = """
December 20, 1972 address 7865
January 31, 1973 address 1234
March 6, 1971 address 9999


"""

# The chosen start date will correspond to timeline frame 0...
startDate = datetime(1970, 3, 1)    # (yyyy, mm, dd) -> 1st March 1970

dateformat = "%B %d, %Y"
# Format codes are explained in the table here:
# https://docs.python.org/3.7/library/datetime.html#strftime-strptime-behavior

# separate the text lines, discard blanks:
entries = [e for e in housedata.splitlines() if e]

# Now, we set pass_index on all objects named as whatever came after
# 'address' in the text list above.
for entry in entries:
    dateTxt, addressTxt = [t.strip() for t in entry.split("address")]
    date = datetime.strptime(dateTxt, dateformat)
    datediff = date - startDate
    dayNum = datediff.days

    houseObject = bpy.data.objects[addressTxt]
    houseObject.pass_index = dayNum

# Note: pass_index is 0 by default.

  1. Now in Animation Nodes, you can read each Object's pass index using an Object Attribute Input node with the value pass_index in its entry field. Using a Time Info node will give you the current frame, and a Compare will let you see if those match.

animation nodes diagram of using object pass_index attribute

The rest is a matter of setting up a list/loop node to run over all the objects in question, instead of selecting one specific object as I've done in this example screenshot. That part should be well covered by the Animation Nodes documentation.

| improve this answer | |
$\endgroup$

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.