Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

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

Guest
Nov 05, 2009 Nov 05, 2009

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
10.8K
Translate
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
}

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

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'.

Translate
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

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();

Translate
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

ai::FilePath file;

AIErr error = sDocument->GetDocumentFileSpecification(file);

if (error != kNoError) {

  // there was a problem
}

Translate
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

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

Translate
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

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

Translate
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

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.

Translate
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

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.

Translate
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

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".

Translate
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

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).

Translate
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

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?

Translate
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

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).

Translate
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

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?

Translate
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

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.

Translate
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

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"

Translate
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

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.

Translate
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

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

Translate
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

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.

Translate
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

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?

Translate
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

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.

Translate
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

     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?

Translate
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

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.

Translate
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

     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?

Translate
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

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

Translate
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

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

Translate
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