Is there a way to programmatically script all objects associated with a given table? I know that in SQL management studio I can right click a table/trigger/key and script object as.... Is there a way to do this programmatically, given an object's name?

If so, is there a way to find all objects (primary keys, foreign keys, triggers) associated with a given table and script all of them programmatically?
This is a technique in C# using Server Management Objects - I don't know of a way to do it in pure T-SQL.