SOLVED GetDocumentPath() returning wrong path?

Hello,

I like to know the path to the document when the user does a "Save With Assets" command.

class MyObject : public ObjectData
{
    Bool MyObject::Message(GeListNode* node, Int32 type, void* data)
    {
        if (type == MSG_GETALLASSETS)
        {
            BaseDocument* pDoc = node->GetDocument();    // modified after initial post
            Filename fullDocPath = pDoc->GetDocumentPath() + pDoc->GetDocumentName();
        }
    }
}

Saving with assets the first time reports the correct path. Saving with assets a second time reports the previous path, which is wrong.

The doc says:
When “Save Project with Assets” is invoked, everything is moved to the new target directory. In this case all absolute paths must be converted to just filenames because the files are next to the document and the absolute paths are not needed anymore.
MSG_GETALLASSETS and MSG_MULTI_CLEARSUGGESTEDFOLDER

            AssetData *assetData = static_cast<AssetData*>(data);
            Filename myAsset = ...
            assetData->Add(myAsset.GetFile());

So I removed the path before adding assets to the assetData. But then the assets are not written to disk and Cinema4D pops up a message box complaining the assets cannot be found (IDS_PAI_CONSOLIDATE_QUESTION_LOCATION or IDS_TEXLACK). Why? What is my understanding is that the handler for MSG_MULTI_CLEARSUGGESTEDFOLDER should add the new path to my asset, not remove it because this was already done in MSG_GETALLASSETS?

I am using Cinema4D R21, but can also test on R23.

Kind Regards,
Chris

Hello @Chris-Chris,

thank you for reaching out to us. There are two problems with your approach I think, at least when I do understand you correctly. When you say:

I like to know the path to the document when the user does a "Save With Assets" command.

I would assume that with "the path to the document" you mean the path of the newly created document where all the assets have been localized, right? If that is the case, the line Filename fullDocPath = pDoc->GetDocumentPath() + pDoc->GetDocumentName(); is problematic. I also would assume pDoc is the document attached to your node you retrieved somewhere at an earlier point. Which is a bit risky, since there is no guratee that the NodeData::Message call is being made for the same document. But even if you would write it like this,

BaseDocument* pDoc = node->GetDocument();
Filename fullDocPath = pDoc->GetDocumentPath() + pDoc->GetDocumentName();

there would still be the problem that you do retrieve the file path of the document that the node is attached to (which could also be empty), not the file path of the document that is going to be saved.

Which brings us to the second problem. MSG_GETALLASSETS(Link) is being broadcasted in the context of collecting all information for saving a document with all assets. So, in the scope of that message the new file path is not yet defined. The message ID which seems more appropriate for your use case is MSG_DOCUMENTINFO_TYPE_SAVEPROJECT_AFTER, which is part of the DOCUMENTIFNO message family. This message is being broadcasted after the user has saved a document with all assets. The file path of the saved document is then embedded within the message data, which is of type DocumentInfoData (Link).

I hope this helps and answers your question. Because I am a bit lost about the second part of your posting. So if anything remains unclear, I will have to ask you to reiterate.

Cheers,
Ferdinand

Hello @ferdinand,

Thanks for answering. Yes, I have overseen to copy the line

BaseDocument* pDoc = node->GetDocument();

and will add it to the original posting. So the path to the currently saved document is not valid while saving, but after saving. Ok.

About the second part: I wonder where in code and why the QuestionDialog about complaining missing asset(s) while saving is triggered.

Screenshot (Link)

It might be in Cinema4D or in our plugin, but I can't find it for days. It appears directly after the message MSG_GETALLASSETS (Link) is done and before the next message comes in.

Kind Regards,
Chris

Hi @Chris-Chris,

ah, I understand now, sorry, should have understood that from the first posting, but somehow my brain blocked it :D. You got it a bit backwards if I do understand your first posting correctly. I am looking here especially at the last sentence of your first posting.

What is my understanding is that the handler for MSG_MULTI_CLEARSUGGESTEDFOLDER should add the new path to my asset, not remove it because this was already done in MSG_GETALLASSETS?

MSG_GETALLASSETS is meant to retrieve the full absolute paths of all assets of your plugin that need to be handled. Adding there a relative path will cause a reference error, because there is no relative file yet. After that Cinema will broadcast MSG_MULTI_CLEARSUGGESTEDFOLDER, so that you can turn the previously submitted absolute paths into relative ones, e.g., chopp everything of except the filename. There is an example in the documentation which shows the whole procedure.

Cheers,
Ferdinand

Hi @ferdinand,

Your explanation and the given example solved all problems. I don't know why I did not found that earlier.

Thanks,
Chris