• Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Hot Door CORE Forum All forums General discussion v
1 2 3 Next »
Third Party Plugins usage

 
  • 0 Vote(s) - 0 Average
Third Party Plugins usage
Rick Johnson
Offline

Senior Member

Posts: 259
Threads: 130
Joined: Jan 2014
Reputation: 0
#1
02-07-2018, 06:36 PM
This code seems to work, but can somebody tell me if I'm doing it correctly? Of course, I'll later add checks for whether the third party plugin (CADtools) is installed and its version is compatible. Also curious why the message() method returns an SPerr, returns another by reference, and d.SPCheck contains a third SPerr.

Code:
    hdi::core::Illustrator::ThirdPartyPluginMap otherPlugins;
    otherPlugins = HDI_CORE_ILLUSTRATOR->allPlugins();
    hdi::core::Illustrator::ThirdPartyPluginMap::iterator it = otherPlugins.find("Hot Door CADtools");
    // test "it" and bail if no pointer
    hdi::core::ThirdPartyPlugin* CTpi = it->second;
    std::string ctPIpath = CTpi->filePath(); // just to verify the plugin's pointer
    // check plugin version and bail if prior to 11.1.2
    hdi::ct::PublicMsgGetCurrentScaleData* data =
        (hdi::ct::PublicMsgGetCurrentScaleData*)
        HDI_CORE_ILLUSTRATOR->alloc(sizeof(hdi::ct::PublicMsgGetCurrentScaleData));
    data->d.self = HDI_CORE_PLUGIN->spPluginRef();
    data->layer = HDI_CORE_ILLUSTRATOR->currentDocument()->currentLayer()->aiLayerHandle();
    SPMessageData* SPdata = reinterpret_cast<SPMessageData*>(data);
    bool OKsoFar = CTpi->prepMessageData(*SPdata);
    SPErr SPmsgErr, SPresult;
    SPmsgErr = CTpi->message(hdi::ct::publicMsgCADtoolsCaller,
        hdi::ct::publicMsgGetCurrentScaleSelector, SPdata, SPresult);
    if (!SPmsgErr){
        // read data from CADtools and store somewhere
        double CTscaler CTscaler = data->scaler;
    }
    OKsoFar = CTpi->cleanMessageData(*SPdata);
    HDI_CORE_ILLUSTRATOR->free(data);
garrett
Offline

Super Moderator

Posts: 248
Threads: 24
Joined: Nov 2013
Reputation: 1
#2
02-08-2018, 03:42 PM
This looks correct to me (but I haven't run it or anything).

As the docs state for the ThirdPartyPlugin::message() method, the returned SPErr is for errors regarding sending the message, whereas the return-by-reference SPErr is for errors given by the third-party plugin itself. I can't comment as to Adobe's original intention with the SPMessageData::SPCheck member.
Rick Johnson
Offline

Senior Member

Posts: 259
Threads: 130
Joined: Jan 2014
Reputation: 0
#3
03-11-2018, 02:50 PM
So far this code is working fine for me. The first time it fetches CADtools' info there's a lag of about 2 seconds, although subsequent requests are pretty instantaneous. Is this normal?
Rick Johnson
Offline

Senior Member

Posts: 259
Threads: 130
Joined: Jan 2014
Reputation: 0
#4
06-20-2020, 11:32 AM
I wonder if something has changed in CORE 0.7.4 because now if I get CADtools settings with this code, my plugin crashes on quit (a NULL address) sometime after the plugin's shutdown function. I only know that the error happens with CADtools 11 on Mac AI 2019, since that's the only CADtools install I have. Also, HDI_CORE_ILLUSTRATOR->allPlugins() takes about 40 seconds to run! I'll share my code in case it's useful to someone else.

Here's a struct in globals to store the CT settings:


Code:
struct ctSettingsStruct{
    bool enabled; // does the user choose to access CADtools settings
    std::string scaleName;
    double scaler;
    double fromValue;
    std::string fromUnits;
    std::string relationship;
    double toValue;
    std::string toUnits;
    std::string axoName;
    double rotation;
    double tilt;
    double angleA;
    double angleB;
    bool foreshorten;
    double xScaler, yScaler, zScaler;
};
ctSettingsStruct ctSettings;

Here's the function to retrieve the CADtools settings:

Code:
bool axo::Plugin::getCTdata(){
    if (HDI_CORE_ILLUSTRATOR->documentCount() == 0){
        return false;
    }
    if (!globals.ctSettings.enabled)
        return false;
    bool gotIt = false;
    long ctVers(0); // for storing CADtools version no.
    this->CTlabel.setText("Finding CADtools plugin...");
    this->CTdlg.show();
    this->CTdlg.update();
    // note: the floating dialog CTdlg does not display :-/
    // Some notice for the user would be helpful because the next line takes about 40 seconds to run!
    hdi::core::Illustrator::ThirdPartyPluginMap otherPlugins;
    otherPlugins = HDI_CORE_ILLUSTRATOR->allPlugins();
    hdi::core::Illustrator::ThirdPartyPluginMap::iterator it = otherPlugins.find("Hot Door CADtools");
    if (it == otherPlugins.end())
        it = otherPlugins.find("HDICADtools");
    if (it == otherPlugins.end()){
        globals.ctSettings.enabled = false;
       hdi::core::alerts::error("CADtools plugin cannot be found");
        this->CTdlg.hide();
        return false;
    }
    hdi::core::ThirdPartyPlugin* CTpi = it->second;

    this->CTlabel.setText("Connecting with CADtools...");
    hdi::ct::PublicMsgGetVersionData* ctVersData = (hdi::ct::PublicMsgGetVersionData*) HDI_CORE_ILLUSTRATOR->alloc(sizeof(hdi::ct::PublicMsgGetVersionData));
    ctVersData->d.self = HDI_CORE_PLUGIN->spPluginRef();
    SPMessageData* SPdata = reinterpret_cast<SPMessageData*>(ctVersData);
    SPErr SPmsgErr, SPresult;
    bool OKsoFar = CTpi->prepMessageData(*SPdata);
    if (OKsoFar){
        SPmsgErr = CTpi->message(hdi::ct::publicMsgCADtoolsCaller, hdi::ct::publicMsgGetVersionSelector, SPdata, SPresult);
        if (!SPmsgErr && !SPresult && ctVersData->success){
            gotIt = true;
            ctVers = (ctVersData->major*10000) + (ctVersData->minor * 100) + ctVersData->revision;
            gotIt = (ctVers >= 110102);
        }
       else{
           gotIt = false;
           hdi::core::alerts::message("This version of CADtools cannot export its settings");
       }
    }
    OKsoFar = CTpi->cleanMessageData(*SPdata);
    HDI_CORE_ILLUSTRATOR->free(ctVersData);
    if (!OKsoFar || !gotIt) {
        globals.ctSettings.enabled = false;
        if (this->CTdlg.visible()) this->CTdlg.hide();
        return false;
    }
    
    this->CTlabel.setText("Getting CADtools settings...");
    hdi::ct::PublicMsgGetCurrentScaleData* ctScaleData = (hdi::ct::PublicMsgGetCurrentScaleData*) HDI_CORE_ILLUSTRATOR->alloc(sizeof(hdi::ct::PublicMsgGetCurrentScaleData));
    ctScaleData->d.self = HDI_CORE_PLUGIN->spPluginRef();
    ctScaleData->layer = HDI_CORE_ILLUSTRATOR->currentDocument()->currentLayer()->aiLayerHandle();
    SPdata = reinterpret_cast<SPMessageData*>(ctScaleData);
    OKsoFar = CTpi->prepMessageData(*SPdata);
    if (OKsoFar){
        SPmsgErr = CTpi->message(hdi::ct::publicMsgCADtoolsCaller, hdi::ct::publicMsgGetCurrentScaleSelector, SPdata, SPresult);
        if (!SPmsgErr & !SPresult && ctScaleData->success){
            gotIt = true;
            globals.ctSettings.enabled = true;
            globals.ctSettings.scaleName = ctScaleData->name;
            globals.ctSettings.scaler = ctScaleData->scaler;
            globals.ctSettings.fromValue = ctScaleData->fromValue;
            globals.ctSettings.fromUnits = ctScaleData->fromUnits;
            globals.ctSettings.toValue = ctScaleData->toValue;
            globals.ctSettings.toUnits = ctScaleData->toUnits;
            globals.ctSettings.relationship = ctScaleData->relationship;
        }
        else {
            gotIt = false;
            globals.ctSettings.scaleName = "Unavailable";
            globals.ctSettings.scaler = 1;
            globals.ctSettings.fromValue = 1;
            globals.ctSettings.fromUnits = "?";
            globals.ctSettings.toValue = 1;
            globals.ctSettings.toUnits = "?";
            globals.ctSettings.relationship = "=";
        }
    }
    OKsoFar = CTpi->cleanMessageData(*SPdata);
    HDI_CORE_ILLUSTRATOR->free(ctScaleData);
    if (!OKsoFar || !gotIt) {
        globals.ctSettings.enabled = false;
        if (this->CTdlg.visible()) this->CTdlg.hide();
        return false;
    }

    this->CTlabel.setText("Applying CADtools settings...");
    hdi::ct::PublicMsgGetCurrentAxoViewData* ctAxoData = (hdi::ct::PublicMsgGetCurrentAxoViewData*) HDI_CORE_ILLUSTRATOR->alloc(sizeof(hdi::ct::PublicMsgGetCurrentAxoViewData));
    ctAxoData->d.self = HDI_CORE_PLUGIN->spPluginRef();
    SPdata = reinterpret_cast<SPMessageData*>(ctAxoData);
    OKsoFar = CTpi->prepMessageData(*SPdata);
    if (OKsoFar){
        SPmsgErr = CTpi->message(hdi::ct::publicMsgCADtoolsCaller, hdi::ct::publicMsgGetCurrentAxoViewSelector, SPdata, SPresult);
        if (!SPmsgErr && !SPresult && ctAxoData->success){
            gotIt = true;
            globals.ctSettings.enabled = true;
            globals.ctSettings.axoName = ctAxoData->name;
            globals.ctSettings.rotation = ctAxoData->rotation;
            globals.ctSettings.tilt = ctAxoData->tilt;
            globals.ctSettings.angleA = ctAxoData->angleA;
            globals.ctSettings.angleB = ctAxoData->angleB;
            globals.ctSettings.foreshorten = ctAxoData->foreshorten;
            if (ctVers >= 110106) { // version 110106 (11.1.6) needed for scalers for axes
                globals.ctSettings.zScaler = ctAxoData->fsA; // right
                globals.ctSettings.xScaler = ctAxoData->fsB; // left
                globals.ctSettings.yScaler = ctAxoData->fsC; // vertical
            }
            else {
                globals.ctSettings.xScaler = globals.ctSettings.yScaler = globals.ctSettings.zScaler = 0.8165;
            }
        }
        else { // enter isometric values as default
            gotIt = false;
            globals.ctSettings.axoName = "Unavailable";
            globals.ctSettings.rotation = 45;
            globals.ctSettings.tilt = 35.2644;
            globals.ctSettings.angleA = 30;
            globals.ctSettings.angleB = 30;
            globals.ctSettings.foreshorten = 0.8165;
            globals.ctSettings.xScaler = globals.ctSettings.yScaler = globals.ctSettings.zScaler = 0.8165;
        }
    }
    
    OKsoFar = CTpi->cleanMessageData(*SPdata);
    HDI_CORE_ILLUSTRATOR->free(ctAxoData);
    if (!OKsoFar || !gotIt) {
        globals.ctSettings.enabled = false;
        if (this->CTdlg.visible()) this->CTdlg.hide();
        return false;
    }
    this->applyCTdata();
    if (this->CTdlg.visible()) this->CTdlg.hide();
    return gotIt;
}

Also note that the strings for scale name, from units, and to units are only returned for custom user scales, not for the built in architectural or engineering scales. I hope it's helpful for others. Comments, of course, are welcome.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

Linear Mode
Threaded Mode