for anyone who wants to do something similar to this, I decided to tackle only the second part where I apply the desired geo node network to all selected meshes and then sets the BldgHeight property, taking the value from the name of the object as described above:
for target in bpy.context.selected_objects:
if target.type == 'MESH':
#get rid of any exiting modifiers
target.modifiers.clear()
#make the new GeoNodes modifier
modifier = target.modifiers.new("BuildingNode", "NODES")
#get the building Node Tree
node = bpy.data.node_groups["building"]
#then set it
modifier.node_group = node
then to set a property in a geo node modifier you need to get the identifier for the property then you can set it:
#get the IDs for inputs
BldgHeightID = node.inputs["BldgHeight"].identifier
SeedID = node.inputs["RandomSeed"].identifier
PropID = node.inputs["PropDensity"].identifier
#set BldgHeight to something random when we dont know the height
modifier[BldgHeightID] = random.randint(4, 50)
#use some random value for inputs
modifier[SeedID] = random.randint(0, 5000)
modifier[PropID] = random.uniform(0.3, 0.8)
Here you see me getting the identifiers for inputs called BldgHeight, RandomSeed and PropDensity.
Finally to get something in the name of an object then set it into an input you need to do the following:
#get a reference of the object name, useful later
name = target.name
if "height" in name:
#get the number in the object's name
HeightName = name.strip("height=")
f = float(HeightName)
i = int(f)
#put that number into BldgHeight
modifier[BldgHeightID] = i
So the whole script i used is the following, it is very specific to what i want it to do but i hope it helps people out there!
import bpy
import random
for target in bpy.context.selected_objects:
if target.type == 'MESH':
#get rid of any exiting modifiers
target.modifiers.clear()
#make the new GeoNodes modifier
modifier = target.modifiers.new("BuildingNode", "NODES")
#get the building Node Tree
node = bpy.data.node_groups["building"]
#then set it
modifier.node_group = node
#get the IDs for inputs
BldgHeightID = node.inputs["BldgHeight"].identifier
SeedID = node.inputs["RandomSeed"].identifier
PropID = node.inputs["PropDensity"].identifier
#set BldgHeight to something random when we dont know the height
modifier[BldgHeightID] = random.randint(4, 50)
#use some random value for inputs
modifier[SeedID] = random.randint(0, 5000)
modifier[PropID] = random.uniform(0.3, 0.8)
#get a reference of the object name, useful later
name = target.name
if "height" in name:
#get the number in the object's name
HeightName = name.strip("height=")
f = float(HeightName)
i = int(f)
#put that number into BldgHeight
modifier[BldgHeightID] = i
else:
if "levels" in name:
#get ID for ModuleHeight
ModHeightID = node.inputs["ModuleHeight"].identifier
#get ModuleHeight
ModHeight = modifier[ModHeightID]
#get the level number
LevelName = name.strip("building:levels=")
f2 = float(LevelName)
#get BldgHeight by ModuleHeight * level number, converting to int then apply it
modifier[BldgHeightID] = int(f2 * ModHeight)