Got a Sample Plugin Built, But Can't Call from Daz Script [SOLVED]

bigD3dbigD3d Posts: 63

Hello all,

thanks to answers in prior posts and reading others here on the site I have made baby steps towards making a plugin. Please note, I haven't coded anything but javascript in a long long time and while I have coded java a decade ago, it's been even longer since I last touched c++. I haven't used any IDE other than Eclipse in that time. So please forgive me up front if I get terminology wrong in regards to Windows and Visual Studio.

My steps so far over the past several days:

  • Downloaded the Daz SDK and looked through both the SDK and Qt docs to get a good idea of what's there. Confirmed I should be able to do what I need to for my project.
  • Downloaded Visual Studio 2010 Express and many extra updates and installers per some posts here.
  • Spent a day or two not getting any of it to work or get the plugins built, mostly due to not being to set the Configuration Manager to have an x64 option.
  • Uninstalled Visual Studio 2010 Express, the SP1, and any Microsoft SDK I had installed as part of that effort.
  • Installed Visual Studio 2019 Community and picked every c++ option available during the install
  • Loaded the SDK samples.sln where it prompted me to change two items related to Visual Studio 2010; I selected the Windows 10 SDK and another option (sorry I forget what it was, but the value had something like v142 in it)
  • Opened the Configuration Manager and saw there were x64 options so changed the values for Release to x64 in all the sample projects
  • Right clicked AFirstPlugin project, hit build and saw that it looked to have worked.
  • Located the sdk_afirstplugin.dll in the <daz install dir>\exec\Release\x64\plugins
  • Copied the dll into <daz install dir>\DAZ 3D\DAZStudio4\plugins directory and started Daz Studio
  • Dropped down the Edit menu and confirmed the 'Hello' option. Selected it and got the "Helo, World" dialog and additional dialogs when hitting Accept and Reject buttons

For my project I wanted to confirm that I could call code in a plugin from my Daz Script project. I see that the class DzAFirstPluginAction is public, so from the Script IDE I entered:

var afpa = new DzAFirstPluginAction();

afpa.executeAction();

and hit the Execute button. I was very happy to see the dialog open and work just as it had from the Edit menu. This confirms to me I can do what I was hoping in regards to making a plugin to handle low level QImage pixel by pixel manipulations and be able to call that from my Daz Scripting project.

I started by trying to copy the solution and project names into a new solution, then manually renaming the .cpp files, .h files, etc. I honestly can't recall what all I did other than royally screw everything up. I thought I had a whole different solution, but after renaming everything I could find in all the files there were still references to AFirstPlugin and nothinig would build. I decided to delete everything as it looked like not only had I messed up my new solution but also the original Samples.sln. So I deleted everything and re-installed the full SDK, samples, and Docs from scratch.

Right now as I put this post out I'm back to the the point where I verified the AFirstPluginAction dll builds and runs correctly in Daz.

In order to not repeat my Visual Studio Solution/project debacle I hope someone here can help guide or point me to the best and/or easiest way to make a new Solution and/or Project so that all the references, configurations, etc. are all there without stomping all over the initial sample code? Do I make a new project in the samples.sln itself? Or do I somehow copy or Save As the solution into something new and remove all the sample projects but one - and then somehow rename or refactor that?

Also, this may or may not be a seperate question, but I didn't see any obvious way to rename/refactor across the project. I saw a reference in googling to ctrl-r, ctrl-r but that does nothing in Visual Studio for me.

As always, any help and guidance is greatly appreciated!

 

 

Post edited by bigD3d on

Comments

  • bigD3dbigD3d Posts: 63
    edited August 2020

    Ok, a positive step forward, but still have a strange problem...

    I have a solution and a project that is outside of the Samples.sln solution and AFirstPlugin project.

    I have coded my header and class to a point where both no longer produce errors (yeah for slowly learning c++)

    I have updated every file in my project and compared it to the AFirstPlugin project, changing values within properties, configuration settings, etc. from afirstpluginaction.

    At this point my project builds ( I think ) as it gives this:

    1&gt;------ Build started: Project: MyPlugin, Configuration: Release x64 ------<br /> 1&gt;Mocing &quot;myplugin&quot;...<br /> 1&gt;Qt: Untested Windows version 6.2 detected!<br /> 1&gt;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(234,5): warning MSB8065: Custom build for item &quot;myplugin.h&quot; succeeded, but specified output &quot;e:\daz 3d\my daz 3d library\dazstudio4.5+ sdk\myproject\myplugin\myplugin_moc.cpp&quot; has not been created. This may cause incremental build to work incorrectly.<br /> 1&gt;myplugin.cpp<br /> 1&gt;pluginmain.cpp<br /> 1&gt;myplugin_moc.cpp<br /> 1&gt;Generating Code...<br /> 1&gt;&nbsp; &nbsp;Creating library E:\DAZ3D\exec\Release\x64\plugins\sdk_myplugin.lib and object E:\DAZ3D\exec\Release\x64\plugins\sdk_myplugin.exp<br /> 1&gt;sdk_myplugin.exp : warning LNK4070: /OUT:myplugin.dll directive in .EXP differs from output filename &#39;E:\DAZ3D\exec\Release\x64\plugins\sdk_myplugin.dll&#39;; ignoring directive<br /> 1&gt;MyPlugin.vcxproj -&gt; E:\DAZ3D\exec\Release\x64\plugins\sdk_myplugin.dll<br /> 1&gt;Done building project &quot;MyPlugin.vcxproj&quot;.<br /> ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    But when I go to the output folder E:\DAZ3D\exec\Release\x64\plugins there are zero new files there. I see the sdk_afirstplugin.dll that I made earlier in the day. I have searched my entire E: drive and none of these files .dll, .exp, or .lib exist.

    I'm sure I must be missing something still somewhere in a config or one of my files i've edited.

    Any help is greatly appreciated!

     

    Post edited by bigD3d on
  • bigD3dbigD3d Posts: 63
    edited August 2020

    Another update:

    so i'm an idiot and found that in the output dir I left out the space where 'DAZ3D' should have been 'DAZ 3D' in my path. Not sure why the full drive search missed it...

    But, on to the next issue...

    As noted in the original post when I use from a Daz Script the original plugin for AFirstPluginAction 

    var afpa = new DzAFirstPluginAction();

    afpa.executeAction();

    it works fine. But... when I copy my new plugin in the same directory, launch Daz, and make a script with this:

    var inputImg = new Image(&quot;&lt;path to an image&gt;&quot;);

    var myplugin = new MyPlugin();

    var outputImg = myplugin.doCoolThing(inputImg);

    I get a message:

    TypeError: Result of expression 'myplugin.doCoolThing' [undefined] is not a function.

    In myplugin.h and myplugin.cpp I have copied the code exactly as it was in the sample, the only differences I see is I inherit from DzBase instead of DzEditAction, I have no member variables, and i'm returning a QImage object for doCoolThing().

    Again, any help on where to look would be great.

     

    Post edited by bigD3d on
  • bigD3dbigD3d Posts: 63
    edited August 2020

    Well,

    it seems I managed to solve all my current issues. If you have had any of the same issues getting started I hope my journey today, and these posts, help you out.

    The final two pieces of the puzzle were found in the QT docs.

    1) Your class needs to have the Q_OBJECT modifier and the class you inherit from needs to set a name. For myplugin class I had previously inherited from DzBase and instead inherited DzElement as it's constuctor took the name parameter easier. See the doc section below:

    https://doc.qt.io/qt-5/qtscript-index.html#making-a-qobject-available-to-the-script-engine

    2) Add Q_INVOKE modifier to your header file at your function declaration. After adding the Q_INVOKABLE modifier to my header file I was able to get my class function to work from Daz Script.

    https://doc.qt.io/qt-5/qtscript-index.html#making-c-class-member-functions-available-in-qt-script

    ------------------ HEADER CODE SNIPPET ---------------

    class MyPlugin: public DzElement {

    Q_OBJECT // needed by MOC

    public:

    MyPlugin();

    public:

    Q_INVOKABLE virtual void testMsg(); // Place Q_INVOKABLE in front of the function

    };

    ------------------ CLASS CODE SNIPPET ---------------

    #include <QtGui/QMessageBox>

    #include "dzapp.h"

    #include "dzmainwindow.h"

    #include "dzelement.h"

    #include "myplugin.h"

     

    MyPlugin::MyPlugin() :

    DzElement("mypluginName") // giving the object the name so it can be called from Daz Script

    {  /** Base object  **/  }

    void MyPlugin::testMsg()

    {

    QMessageBox msgBox;

    msgBox.setText("Hello From MyPlugin!");

    msgBox.exec();

    }

    ------------------ DAZ SCRIPT FROM Scripting IDE ---------------

    var m = new MyPlugin();

    m.testMsg();  // Pops up the message box! woot woot!

    Post edited by bigD3d on
Sign In or Register to comment.