Notifications
Clear all

[Closed] Solved – SDK utility plugin – save\load parameters

I’m writing a utility plugin with the SDK, but it’s giving me a hard time figuring out how to store some data in the scene with it.

I’ve already written everything else (modifiers and other things, they work fine with paramblocks and such), but I cannot figure out how to
properly store variables with the utility plugin. The GUI itself (buttons and such) works already, I just need to store the string and read it back in
when the scene is loaded and utility is selected (I’ll read it on ‘init’…).

The utility is my interface for a exporter, so I need to store folder \ file path and other parameters.
Has anyone of you done this with a utility plugin and the SDK?

7 Replies

We do lots of utility plugins and use ini files to store any data we use. But if we need to save for scene, we save to the file properies

the “proper” way would be to use app data using Interface::GetScenePointer() you can then use

Animatable::GetAppDataChunk
Animatable::AddAppDataChunk
Animatable::RemoveAppDataChunk
Animatable::ClearAllAppData

etc

Thanks! I will look into this.
I’ll post my solution when I’m done so that others can learn this too.

Edit: wrapped the code now… missed a / on my initial reply.
Here’s what I did and it works for what I needed.

Save the result of a ‘browse’ button to the scene:
(the number ‘7’ in the ‘add \ remove appdata chunk’ is just a index that I chose.).


case IDC_BROWSE:
    {
        TCHAR    folderName[MAX_PATH] = { 0 };

        GetCOREInterface()->ChooseDirectory(GetCOREInterface()->GetMAXHWnd(), L"Browse for output folder", folderName, NULL);
        if (_tcscmp(folderName, _T("")) == 0) {
            // Cancel
            return FALSE;
        }
        SetDlgItemText(hWnd, IDC_EDIT_PATH, folderName);

        Animatable *anim = GetCOREInterface()->GetScenePointer();
        int size = (int)((_tcslen(folderName) + 1) * sizeof(TCHAR));
        TCHAR *buf = (TCHAR*)MAX_malloc(size);
        _tcscpy(buf, folderName);

        anim->RemoveAppDataChunk(
            UtilityPlugin_CLASS_ID,
            UTILITY_CLASS_ID,
            7);

        anim->AddAppDataChunk(
            UtilityPlugin_CLASS_ID,
            UTILITY_CLASS_ID,
            7,
            (DWORD)size, buf);
        break;
    }

Load the data back in (i do this during ‘init’):


    Animatable *anim = GetCOREInterface()->GetScenePointer();
    AppDataChunk *ad =
        anim->GetAppDataChunk(
            UtilityPlugin_CLASS_ID,
            UTILITY_CLASS_ID,
            7);
    if (ad)
    {
        SetDlgItemText(hWnd, IDC_EDIT_PATH, (TCHAR*)ad->data);
    }


“[“code”]”
“[”/code”]”

remove quotes


case IDC_BROWSE:
    {
        TCHAR    folderName[MAX_PATH] = { 0 };

        GetCOREInterface()->ChooseDirectory(GetCOREInterface()->GetMAXHWnd(), L"Browse for output folder", folderName, NULL);
        if (_tcscmp(folderName, _T("")) == 0) {
            // Cancel
            return FALSE;
        }
        SetDlgItemText(hWnd, IDC_EDIT_PATH, folderName);

        Animatable *anim = GetCOREInterface()->GetScenePointer();
        int size = (int)((_tcslen(folderName) + 1) * sizeof(TCHAR));
        TCHAR *buf = (TCHAR*)MAX_malloc(size);
        _tcscpy(buf, folderName);

        anim->RemoveAppDataChunk(
            UtilityPlugin_CLASS_ID,
            UTILITY_CLASS_ID,
            7);

        anim->AddAppDataChunk(
            UtilityPlugin_CLASS_ID,
            UTILITY_CLASS_ID,
            7,
            (DWORD)size, buf);
        break;
    }


Load the data back in (i do this during 'init'):

    Animatable *anim = GetCOREInterface()->GetScenePointer();
    AppDataChunk *ad =
        anim->GetAppDataChunk(
            UtilityPlugin_CLASS_ID,
            UTILITY_CLASS_ID,
            7);
    if (ad)
    {
        SetDlgItemText(hWnd, IDC_EDIT_PATH, (TCHAR*)ad->data);
    }

you should probably add RegisterNotification() handlers for NOTIFY_FILE_POST_OPEN && NOTIFY_SYSTEM_POST_RESET so your dialog updates correctly on scene changes and resets.

Thanks Klvnk, that was my next thing to fix. I’ll get that done tomorrow I hope.