Itoo Software Forum

Forest Pack => Forest Pro (*) => Topic started by: monomon on February 01, 2018, 08:12:31 AM

Title: Problem setting distmap by script
Post by: monomon on February 01, 2018, 08:12:31 AM
Hi, I am trying to set a ForestPack instance's distribution map with a python script in 3ds max and I am having problems with it.

First, I create a MaxPlus.Bitmap in which I load an existing file from disk. Then, a MaxPlus.BitmapTex and set my bitmap on it. Finally, I set this BitmapTex on the "distmap" property of Forestpack.

When the script completes, the forest appears empty (though the distmap button in the sidebar indicates my distmap).
If I now manually click to reselect the map from the material editor it works!  ???
I am not sure what changes when I do this, like some weird conversions or setting missing properties... or do I just need to trigger some kind of update?

Here's example code:
Code: [Select]
BMM_GRAY_8 = 3  # 8-bit grayscale bitmap.
# Bitmap open mode flags

node_name = "forest_flowers"
conf = {
    "width": 32,
    "height": 32,
    "name": "bla" + str(random.randint(1, 15000))

def create_bitmaptex(bm, conf):
    bt = MaxPlus.Factory.CreateDefaultBitmapTex()
    # wtf, isUIAction has to be true for Display to work...
    bt.SetMapName(bm.GetStorage().GetBitmapInfo().GetName(), True)
    return bt

def load_bitmap(bmpath, conf):
    width = conf["width"]
    height = conf["height"]

    storage = MaxPlus.Factory.CreateStorage(BMM_GRAY_8)

    info = storage.GetBitmapInfo()
    info.SetName(conf["name"] )

    storage.Allocate(info, BMM_OPEN_R)
    bm = MaxPlus.BitmapManager.Load(info)
    return bm

def add_to_current_library(mat):

    forest_pack = MaxPlus.INode.GetINodeByName(node_name)

    # use one of the forestpack distmaps for example
    bmpath = os.path.join(
        "Program Files (x86)",
        "Itoo Software",
        "Forest Pack Pro",

    print("bitmap path", bmpath)
    bm = load_bitmap(bmpath, conf)
    print("bitmap", bm)

    bt = create_bitmaptex(bm, conf)
    print("bitmaptex", bt)



    # The value of distmap is now of type MaxPlus.Texmap
    print("distmap value", forest_pack.Object.GetParameterBlock()\

except Exception as e:

As an aside, initially I wanted to make this work with procedurally generated bitmaps, but that failed worse - manual reselection did not fix it, (I am guessing) because the bitmap's in-memory storage doesn't persist.
Title: Re: Problem setting distmap by script
Post by: iToo on February 02, 2018, 09:56:41 AM
Hi, unfortunately i cannot help you with Python scripts, because i'm not familiar with this language (we use exclusively C++ and a little of Maxscript).

But changing a texture map from MaxScript seems to work fine. I did this:

- I create a FP object, and assign a texture map of type "Bitmap" to Distribution->Map.
- Then i change the bitmap, setting $Forest001.distmap.filename with the route of the bitmap, and FP is updated correctly.

Please note i use a texture map (Distribution->Map), not a bitmap directly (Distribution->Bitmap). The bitmap slot was not designed to be changed programatically.

I don't know if your Python script is correct, or if it's necessary some specific process to update the bitmap.
Title: Re: Problem setting distmap by script
Post by: monomon on February 02, 2018, 12:10:40 PM
Thank you for the response!

The Python api seems to work a bit differently. There is no filename property of the distmap, it can only reference either a TexMap object or a Bitmap (via SetMap and SetBitmap).

I just solved my issue, so I'll post the below for the benefit of others:

After some digging, it turned out a BitmapTex has a SetMapName method, which actually expects a filename, making it a bit of a misnomer.
Alternatively, it also worked if I first created an Asset with the bitmap path and set that on the texture using SetMap.

It seems that SetBitmap is useless, also as reported by (
(that's using the c++ api)
Pity, because it seemed to match my use case better.
Therefore, I suspect there is no chance of applying generated in-memory bitmaps...

This part of the max api is confusing, and the documentation is somewhat scant.

Thank you again.

A bit of example code that works:
Code: [Select]
import os

bmpath = os.path.join(
    "Program Files (x86)",
    "Itoo Software",
    "Forest Pack Pro",

tex = MaxPlus.Factory.CreateDefaultBitmapTex()

node = MaxPlus.INode.GetINodeByName("forest_flowers")
Title: Re: Problem setting distmap by script
Post by: iToo on February 02, 2018, 03:23:24 PM
Thanks for the information ! It may be useful for other users.