Copy link to clipboard
Copied
Hi everybody,
I'm currently working on an old plugin for the company i'm working. I never have done something with InDesign before so i guess that is one of the main problems ^^. The Plugin was originally developed for CS 2 and was first ported to CS3 and now to CS4. The code is neither commented nor is the person that wrote the plugin still available (hurray for me ^^). The new port is running, but it still misses a feature that was, at least in cs2, functional but never used so it didnt got ported.
The plugin uses preferences to store persistent data and according to that data highlight some text or dont highlight it. The problem i cant fix now, is that the plugin cant instanciate the preferences to store the data.I posted the first code that tries to get a new instance of the preferences and fails. I looked throught the sdk-sample, but they use a different way to get and set the preferences. So the main question is: Is it still possible to set/get preferences like the following, or do i need to do it somehow differenly?
bool16 dhPrintMarkUtils::GetTagShown()
{
IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
if (doc != nil)
{
InterfacePtr<IDHPrintMarkPrefs> iPrefs(doc->GetDocWorkSpace(), UseDefaultIID());
if (iPrefs != nil)
return iPrefs->GetTagShown();
}
return kFalse;
}
The Preferencesclass is as follows:
#include "VCPluginHeaders.h"
// Interfaces:
#include "IPMStream.h"
//General:
#include "CPMUnknown.h"
// Project:
#include "dhPrintMarkID.h"
#include "dhPrintMarkPrefs.h"
class dhPrintMarkPrefs : public CPMUnknown<IDHPrintMarkPrefs>
{
public:
dhPrintMarkPrefs(IPMUnknown* boss);
virtual ~dhPrintMarkPrefs();
virtual bool16 GetTagShown ();
virtual void SetTagShown (bool16 tagHilited);
virtual void ReadWrite(IPMStream* s, ImplementationID prop);
private:
bool16 fTagHilited;
};
I dont quite know what else is relevant, so if you could please drop a note what else i should provide, i will glady post it.
Thank you very, very much for answers! (I'm kinda desperate on this topic ^^).
Grettings,
Daishy
Copy link to clipboard
Copied
Hi Daisy,
I see that your persitent data is on your WorkSpace, in your .fr file is there something like this
AddIn
{
kWorkspaceBoss,
kInvalidClass,
{
/** Implementation of IXDocBkOptions
@see XDocBkOptions
*/
IID_IXDOCBKOPTIONS, kXDocBkOptionsImpl,
}
},
So The Set and Get function should work properly, maybe something goes worng where GetTagShown is called
Thanks,
Jelle
Copy link to clipboard
Copied
Hi,
I just checked the .fr and i only got 3 AddIn-Statements, non of them have something to do with the preferences (at least non of the names suggest it ^^). I will check that out if i'm back at work and try adding a new AddIn-Statement.
For the second Part:
bool16 dhPrintMarkUtils::GetTagShown()
{IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
if (doc != nil){
InterfacePtr<IDHPrintMarkPrefs> iPrefs(doc->GetDocWorkSpace(), UseDefaultIID());
if (iPrefs != nil)
return iPrefs->GetTagShown();
}
return kFalse;
}
The function is called correclty (i can put some debug outputs at the top), the doc is != nil but the iPrefs variable is nil. If i put an else to the if(iPrefs) != nil and print an error in that case, the error is printed on each call.
Thanks for the answer, i will try it as soon as possible an post back the result.
Greetings,
Daishy
Copy link to clipboard
Copied
1. The preferences is stored on the WorkSpace Boss, so it must be part of the Add-In in the resource file:
AddIn
{
kWorkspaceBoss,
kInvalidClass,
{
IID_PREFS, kPrefsPrstImpl,
}
},
2. You need the implementation to be persistent. The programming guide and the examples are very good on this subject. But a few hints:
Copy link to clipboard
Copied
Hi again,
First of all, thanks for the help so far. Unfortunately it still isnt working and i think i followed your hints and the sdk-sample
Now i tried to reimplement a new set of preferences (the class is attached to this post). Im currently only trying to read the settings, not change it. The first time GetTagShown() is called, is from a gui-element checking a check-box based on the result of the method (a document is open). But i get the not created message. Any more tipps on what i might change? Thanks for your time and answers in advance !
bool16 dhPrintMarkUtils::GetTagShown()
{
IDocument *doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
if(doc != nil)
{
InterfacePtr<IdhPrintmarkPreferences> iPrefs2(doc->GetDocWorkSpace(), UseDefaultIID());
if(iPrefs2 != nil) CAlert::ErrorAlert("Created!");
else CAlert::ErrorAlert("not created");
}
}
In my Factorylist.h i got
REGISTER_PMINTERFACE(dhPrintmarkPreferences, kdhPrintmarkPreferencesImpl)
in my id.h:
DECLARE_PMID(kInterfaceIDSpace, IID_PREFERENCES, kDHPrintMarkPrefix + 7)
DECLARE_PMID(kImplementationIDSpace, kdhPrintmarkPreferencesImpl, kDHPrintMarkPrefix+23)
And to my .fr file i added (at toplevel)
resource IgnoreTask(1)
{
kImplementationIDSpace,
{
kdhPrintmarkPreferencesImpl,
}
}
and in the part starting with "resource ClassDescriptionTable(kSDKDefClassDescriptionTableResourceID)" i added
AddIn
{
kWorkspaceBoss,
kInvalidClass,
{
IID_PREFERENCES, kdhPrintmarkPreferencesImpl,
}
},
Copy link to clipboard
Copied
Hi again,
First of all, thanks for your tips! Unfortunately it still isnt working 😕
I tried reimplementing a new preferences class (i attached the source to it, so it wont take up that much space). I followed all your tipps and the sdksample (at least i hope so).I only try to read the preferences so far, not change it or write it. The following function is called from a gui element
trying to check a checkbox based on the result the method is giving (true oder false). But i get the not created message.
Am i stil doing something wrong? Once again thanks for your help and time!
Edit: I tried uploading the files, but it seems thats not allowed. So i put them in a pastebin:
bool16 dhPrintMarkUtils::GetTagShown()
{
IDocument *doc = Utils<ILayoutUIUtils>()->GetFrontDocument();
if(doc != nil)
{
InterfacePtr<IdhPrintmarkPreferences> iPrefs2(doc->GetDocWorkSpace(), UseDefaultIID());
if(iPrefs2 != nil) CAlert::ErrorAlert("created");
else CAlert::ErrorAlert("not created");
}}
To the ID.h i added:
DECLARE_PMID(kInterfaceIDSpace, IID_PREFERENCES, kDHPrintMarkPrefix + 7)
DECLARE_PMID(kImplementationIDSpace, kdhPrintmarkPreferencesImpl, kDHPrintMarkPrefix+23)
To the factorylist.h i added:
REGISTER_PMINTERFACE(dhPrintmarkPreferences, kdhPrintmarkPreferencesImpl)
To the .fr i added (on toplevel):
resource IgnoreTask(1)
{
kImplementationIDSpace,
{
kdhPrintmarkPreferencesImpl,
}
}
And to the resource ClassDescriptionTable(kSDKDefClassDescriptionTableResourceID) part:
AddIn
{
kWorkspaceBoss,
kInvalidClass,
{
IID_PREFERENCES, kdhPrintmarkPreferencesImpl,}
},
Copy link to clipboard
Copied
You need to write a command, that transfers the data into the workspace database. You should also add a version number to your persistent data, so that you can later extend your preferences with more parameters and safely read them. Reading more than what is stored in an InDesign database, causes InDesign to crash.
Any since you are rewriting the general preferences, you might consider moving the general preferences into a file outside InDesign. This way you avoid having data stored in general InDesign, so that if InDesign crashes, your preferences will not be affected.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now