• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can we get the file path of the current document?

Guest
Nov 05, 2009 Nov 05, 2009

Copy link to clipboard

Copied

Hi,

     I want to store the current document file path into a string, I tried the  AIDocumentSuite, and 

AIAPI AIErr(* AIDocumentSuite::GetDocumentFileSpecification)(ai::FilePath &file) .

Its ended in prameter conversion error (c 2664). Can anyone guide me to get the current file path.

Thanks in advance

Sreejesh K V

TOPICS
SDK

Views

8.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Nov 06, 2009 Nov 06, 2009

ai::FilePath file;

AIErr error = sDocument->GetDocumentFileSpecification(file);

if (error != kNoError) {

  // there was a problem
}

Votes

Translate

Translate
Adobe
Guide ,
Nov 05, 2009 Nov 05, 2009

Copy link to clipboard

Copied

That sounds like the right call -- is the file unsaved? It might not have a file specification if its unsaved.

And as a tip: the error code can be decoded, though it doesn't always result in something useful. If you view it as hex and take each pair of digits (four pairs in all) and cast them to char, you'll spell out a four character code. It often indicates something more specific for an error than 'something went wrong'. If you look at the top of some headers, you'll see #defines for error codes like 'parm' or 't!nf'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 05, 2009 Nov 05, 2009

Copy link to clipboard

Copied

Hi,

     Now i am having problem with initialization of the "&file" in the GetDocumentFileSpecification();

AIAPI AIErr (*GetDocumentFileSpecification) ( ai::FilePath &file );

I searched in the samples provided with the SDK and i couldn't find the example for GetDocumentFileSpecification();

Can you give me some snippets regarding the  GetDocumentFileSpecification();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 06, 2009 Nov 06, 2009

Copy link to clipboard

Copied

ai::FilePath file;

AIErr error = sDocument->GetDocumentFileSpecification(file);

if (error != kNoError) {

  // there was a problem
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 08, 2009 Nov 08, 2009

Copy link to clipboard

Copied

I am still not able to solve the problem, now its showing some link error

This is what i tried,

SPBasicSuite *fBasic = message->d.basic;

AIDocumentSuite *sFile;

fBasic->AcquireSuite (kAIDocumentSuite,kAIDocumentVersion, (const void **)&sFile);

ai::FilePath path;

AIErr error = sFile->GetDocumentFileSpecification(path);

-----------------------------------------------------------------------------------------

I am getting following errors

Error 1 error LNK2019: unresolved external symbol "public: __thiscall ai::FilePath::~FilePath(void)" (??1FilePath@ai@@QAE@XZ) referenced in function "long __cdecl goMenuItem(struct AIMenuMessage *)" (?goMenuItem@@YAJPAUAIMenuMessage@@@Z) menuHandler.obj

Error 2 error LNK2019: unresolved external symbol "public: __thiscall ai::FilePath::FilePath(void)" (??0FilePath@ai@@QAE@XZ) referenced in function "long __cdecl goMenuItem(struct AIMenuMessage *)" (?goMenuItem@@YAJPAUAIMenuMessage@@@Z) menuHandler.obj

Error 3 fatal error LNK1120: 2 unresolved externals ..\Output\Win\debug\MenuPlay.aip

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 09, 2009 Nov 09, 2009

Copy link to clipboard

Copied

It sounds like you're not including IAIFilePath.cpp in your project. It's in the illustratorapi folder.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 10, 2009 Nov 10, 2009

Copy link to clipboard

Copied

I have included the  IAIFilePath.cpp and its showing another link error.

Error 1 error LNK2001: unresolved external symbol _sAIFilePath iaifilepath.obj
Error 2 fatal error LNK1120: 1 unresolved externals ..\Output\Win\debug\MenuPlay.aip

I included some header files and some cpp files, i tried everything i know but i am still not able to solve the link error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 10, 2009 Nov 10, 2009

Copy link to clipboard

Copied

Basically, you're using a suite that's defined in a header but hasn't been 'officially' declared in a .c/cpp file. You need to find where all the other suites in your plugin are defined that way, and add a line like:

AIFilePathSuite* sAIFilePath = 0;

Also, I'm guessing there's a spot where you need to define it for load, which looks something like this:

kAIFilePathSuite, kAIFilePathSuiteVersion, &(**sAIFilePath),

That will appear in a list of other definitions that are simliar. Looking at the MarkedObjects sample plugin, if you're using one of those as a basis it appears the file is called something like (in this case) MarkedObjectsSuites.cpp. Any suite you use has to be included like this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

I have included the line "AIFilePathSuite* sAIFilePath = 0;" in iaifilepath.cpp, my project is running without error. and i am not getting the file path,

This is what i did for getting file path:

SPBasicSuite *fBasic = message->d.basic;

AIDocumentSuite *sFile;

fBasic->AcquireSuite (kAIDocumentSuite,kAIDocumentVersion, (

const void**)&sFile);

ai::FilePath path;

AIErr error = sFile->GetDocumentFileSpecification(path);

while debugging using break points its showing that the "error=0", i have saved the current file from the illustrator and its not showing the file path with in error. By using above code can i get the current file path in "error".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 11, 2009 Nov 11, 2009

Copy link to clipboard

Copied

You've lost me. An error of zero means it worked (kNoErr == 0). The result should be in path, not error. If path is empty, it might be because the file hasn't been saved yet. I think I've said before that if the file isn't saved I don't think its possible to get a path (which makes sense).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 12, 2009 Nov 12, 2009

Copy link to clipboard

Copied

Now i am getting error = 0, and some address value in path variable , i do belive that i can get the windows native file path from the path variable.

should i use any other function to fetch the path in windows native form?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 12, 2009 Nov 12, 2009

Copy link to clipboard

Copied

That's the internal handle to the file path object. They use this a lot, it avoids a number of problems.

If you look at IAIFilePath.hpp you'll find a bunch of methods like GetFilename(), GetFullPath(), etc. These get you ai::UnicodeString objects, which would look very similar to the ai::FilePath object if you look at them in the debugger. Again, you'll have to look at IAIUnicodeString.hpp to find methods that get you values out in a form you'd expect (I think c_str() is the typical one on IAIUnicodeString).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 13, 2009 Nov 13, 2009

Copy link to clipboard

Copied

thanks for your instant reply, could you please tell me how call the GetFilename();, which suite i have to use for calling the GetFilename()?. I tried to call GetFilename() , and its not going in right direction. Can have some sample call?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2009 Nov 13, 2009

Copy link to clipboard

Copied

Back to your original code, it would something like this:

ai::UnicodeString pathString = path.GetFullPath();

std::string foobar = pathString.as_UTF8();

const char* foo = foobar.c_str();

Pick your poison for how you want to use it at that point.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

Hi,

i just tried

ai::UnicodeString pathString = path.GetFullPath();

std::string foobar = pathString.as_UTF8();

const char* foo = foobar.c_str();

while debbugging the control is not going through these lines.

Should i include any headers than the following?

#include "IllustratorSDK.h"
#include <AIURL.h>
#include "common.h"
#include "menuHandler.h"
#include "AIMenuGroups.h"
#include "stringUtils.h"
#include "plugindlg.h"
#include "SDKDef.h"
#include "SDKAboutPluginsHelper.h"
#include "AIDocument.h"
#include "AIFilePath.h"
#include "SPFiles.h"
#include "stdio.h"
#include <iostream>
#include "string.h"
#include "iaiunicodestring.h"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 16, 2009 Nov 16, 2009

Copy link to clipboard

Copied

If the control is skipping those lines than either build failed (should be pretty obvious though) or you something else is going on. Sometimes it might be you have two copies of the plugin running, or maybe the debugger has bugged out (rare, but I've had it happen). The first is easy to check -- just go to the plugins folder and double-check. And you should be able to tell if it actually built or not.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 17, 2009 Nov 17, 2009

Copy link to clipboard

Copied

I have checked the plugin folder, their is only one plugin . And the build is successfull.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 17, 2009 Nov 17, 2009

Copy link to clipboard

Copied

The debugger would only skip those lines for two reasons that I know:

1) The code isn't actually in the binary being debugged

2) The code was stripped out by the compiler as an optimization

The first was what I was having you check the build success & for another plugin.One more thing to try (and this is kind of dumb) is to force it to compile that specific file. Not build the project, but actually compile that file. That or just hit 'Rebuild All' on the project. Maybe there's an out of date object file somewhere that's just not getting rebuilt properly.

If that's not the case, I'm guessing it has to be that the code is being stripped out for some reason. Try adding some debugging printf()s around the code, dump some text to the console. At this point its not an AI SDK problem, it's a general coding problem.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 25, 2009 Nov 25, 2009

Copy link to clipboard

Copied

Hi,

     I am getting the file specification for the current file, and I am not able to get the path from the file path object.

This is what i have tried!

if

(message->menuItem == g->MyPlugin) {

SPBasicSuite *fBasic = message->d.basic;

AIDocumentSuite *sFile;

SPBasicSuite *pBasic = message->d.basic;

AIFilePathSuite *fFile;

ai::UnicodeString pathString;

std::string foobar;

const char* foo;

fBasic->AcquireSuite (kAIDocumentSuite,kAIDocumentVersion, (

const void**)&sFile);

ai::FilePath path;

ai::UnicodeString pstring;

AIErr error = sFile->GetDocumentFileSpecification(path);

//AIErr errr= fFile->GetFullPath(path, true ,pstring);

ai::UnicodeString mypath = path.GetFullPath();

std::string mystring= mypath.as_UTF8();

const char* fullpath=mystring.c_str();

while debugging after the line "AIErr error = sFile->GetDocumentFileSpecification(path);" its showing the message " their is no source code for the current location" , I am getting the error =0 , it means i am getting the file specification in "path". am i right? or their is any mistake in my code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 26, 2009 Nov 26, 2009

Copy link to clipboard

Copied

It sounds like the GetFilePathSpecification() call crashed. Are you sure sFile was populated correctly? Initialize it to zero and then check it after your Acquire -- if its still zero, that would explain the crash.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 30, 2009 Nov 30, 2009

Copy link to clipboard

Copied

     I have checked the sFile, its working properly, i think i am having problem with the line "std::string foobar = pathString.as_UTF8() ;"., please find the attached screen shot. There is any other method to fetch the file pah from the path object?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 30, 2009 Nov 30, 2009

Copy link to clipboard

Copied

Its a little hard to tell, but the object looks okay. Is it possible the filepath actually is the empty string? Has the file you're checking been saved yet? If it hasn't been, I believe it returns the empty string as the result.


From what I can see, the way you're pulling the path out of the ai::FilePath object is correct. If there's a problem, its in how the file path object is being populated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 02, 2009 Dec 02, 2009

Copy link to clipboard

Copied

     I have saved the file, and the changes made on the file are persist after the system restart. so i can make sure that the the save operation is taking place correctly. I tried to print the vale of "path", still now i am not able to do that. while debugging i am getting the address "  0x07e97600" in path. I am not able to find out the error. Can i have any sample code which return the file path correctly?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 02, 2009 Dec 02, 2009

Copy link to clipboard

Copied

The hex address is the internal pointer to the object used by AI -- that won't tell you if its working or not. That doesn't mean its working or not working, it will always look like that. You can't debug into the ai::FilePath object unfortunately.


You just have to get the file path object and check the return value on the GetFileSpecification() call. If that returned kNoErr, the file path object is probably fine. I've posted code before that should pull the file path out -- if that's not working, I don't know why. It works for me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 18, 2009 Dec 18, 2009

Copy link to clipboard

Copied

I have checked the return value of  GetFileSpecification() call it is returning the  kNoErr, and  i am still not able to fetch the file path.

i am working as unpriviliaged user , should i need administrator account to create plugins in SDK. please guide me

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines