Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    How do I open a maxon::Url in the default web browser?

    Cinema 4D SDK
    s22 c++ macos maxon api classic api
    3
    7
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fwilleke80F
      fwilleke80
      last edited by fwilleke80

      Hi,

      I have a Maxon::Url, containing the following:
      file:///Applications/Maxon/Cinema 4D R22/plugins/myplugin/help/content/omyobject/omyobject.html#MYOBJECT_ATTRIBUTE.

      The Url was assembled in a PluginHelpDelegate:

      	maxon::Url url;
      	url.SetUrl(GeGetPluginPath().GetString(), true) iferr_return;
      	
      	url.Append("help"_s) iferr_return;
      	url.Append("content"_s) iferr_return;
      	url.Append(baseType.ToLower()) iferr_return;
      	url.Append(opType.ToLower() + ".html#"_s + property) iferr_return;
      

      The Url is correct, if I copy & paste it into Safari or Chrome, the page opens as expected.

      But trying to open it from within Cinema 4D, using GeOpenHTML(url.GetUrl()); just returns false. Why?

      Cheers,
      Frank

      www.frankwilleke.de
      Only asking personal code questions here.

      1 Reply Last reply Reply Quote 0
      • fwilleke80F
        fwilleke80
        last edited by

        Ah, I made it work like this:

        maxon::String urlStr = url.GetUrl();
        urlStr.Replace(" "_s, "%20"_s) iferr_return;
        
        ...
        
        GeOpenHTML(urlStr);
        

        But this replacement seems clumsy. Isn't there a function in the API to escape URLs?

        Cheers,
        Frank

        www.frankwilleke.de
        Only asking personal code questions here.

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          hi,

          the only way i found was using the old FilenameToURL witch is a static function that need a Filename and return a string.

          static maxon::Tuple<maxon::String, Int32> EscapeUrl(maxon::Url& url)
          {
          	Filename urlToEscape = MaxonConvert(url);
          	Int32 encoding;
          	maxon::String myUrlAsEscapedString = HtmlViewerCustomGui::FilenameToURL(urlToEscape, &encoding);
          	return { myUrlAsEscapedString, encoding };
          }
          
          
          static maxon::Result<void> pc12829_action(BaseDocument* doc)
          {
          	iferr_scope;
          	maxon::Url  myUrl {"file:////Applications/Maxon/Cinema 4D R2/plugins/myplugin/help/content/omyobject/omyobject.html#MY OBJCT_ATTRIBU TE"_s };
          
          	maxon::Tuple<maxon::String, Int32> convertedResult = EscapeUrl(myUrl);
          	
          	maxon::String myUrlAsEscapedString = convertedResult.GetFirst();
          	Int32 encoding = convertedResult.GetSecond();
          
          
          	ApplicationOutput("the url is @ and escaped is @ the url was escaped is @", myUrl, myUrlAsEscapedString, encoding == URL_ENCODING_ESCAPED);
          
          
          	return maxon::OK;
          }
          

          But your # will be transform to %23 so you have to be careful with that. But property is something that you can control and shouldn't have space there.

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • P
            PluginStudent
            last edited by

            Why not use IoShowInOS()? (didn't test it on macOS though).

            maxon::Url url { "file:///D:/_tests/test.html"_s };
            url.IoShowInOS(maxon::IOSHOWINOSFLAGS::OPEN_IN_EXPLORER) iferr_ignore("");
            

            See Url Manual.

            1 Reply Last reply Reply Quote 2
            • ManuelM
              Manuel
              last edited by

              @PluginStudent said in How do I open a maxon::Url in the default web browser?:

              Why not use IoShowInOS()? (didn't test it on macOS though).
              maxon::Url url { "file:///D:/_tests/test.html"_s };
              url.IoShowInOS(maxon::IOSHOWINOSFLAGS::OPEN_IN_EXPLORER) iferr_ignore("");

              See Url Manual.

              I was so focused on escaping the URL, thanks a lot @PluginStudent

              MAXON SDK Specialist

              MAXON Registered Developer

              1 Reply Last reply Reply Quote 0
              • fwilleke80F
                fwilleke80
                last edited by

                Oh, cool! I'll test that. Thank you!

                www.frankwilleke.de
                Only asking personal code questions here.

                1 Reply Last reply Reply Quote 0
                • fwilleke80F
                  fwilleke80
                  last edited by

                  Hmmmm, well, on the one hand this function is a nice thing: It really does do the escaping for me, so the spaces in the URL are correctly replaced with "%20".

                  But it does not handle anchors in a URL.

                  This URL works fine:
                  file:///Applications/Maxon/Cinema 4D R22/plugins/myplugin/help/content/omyobject/omyobject.html

                  But this URL is not opened, instead an error (code -43) is thrown:
                  file:///Applications/Maxon/Cinema 4D R22/plugins/myplugin/help/content/omyobject/omyobject.html#MYOBJECT_ATTRIBUTE

                  That is a pity.

                  www.frankwilleke.de
                  Only asking personal code questions here.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post