cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Macro problem related to filenames - Isodraw

TimSharp
6-Contributor

Macro problem related to filenames - Isodraw

Does the document object get reset by "save"?

I have come across a strange clash between 2 of my macros.

One macro I have does the following:

define myDoc as document

define fullpath as string

fullpath = myDoc.path

fullpath returns the full pathname of the current document as I expect.

However, another macro I have seems to change the above so that fullpath only returns the file name without the full path.

I added 4 lines into another macro to save the current illustration with a new name and this is when the problem occurred

define file_name as element

file_name = stripExt(activeDoc.name)

file_name = (file_name + "-211.iso")

save file_name

This means that if I run the 1st macro on its own, no problem, but if I run the 2nd macro and then run the first again, it doesn't return the fullpath properly.

I presume there is a way round this if I knew more about the way the language works. Is it the "save" command that resets something?

5 REPLIES 5

Sounds like an odd situation, and if feels like I'm missing something. But, something that seems to be sticking out. When you are defining your variables as shown they are only valid for the life of that macro. Once the macro is done, the variable is cleared. You might want to look into defining some of your macros globally.

In regards to what you are seeing, I'm assuming these are not the entire macros (or at least I hope not as the first doesn't do anything). It almost seems like you might be using global variables and are accidently reusing one for a similar, but still different purpose (I've done this myself). My first step would be to look through and make sure you're not using the same variable twice.

TimSharp
6-Contributor
(To:thendricks)

Thanks for your help Trevor.

You are right that these are just fragments of macros - just the bits that cause the problems.

I thought global variables might be causing the problem at first, but I put a "gl_" prefix on all my globals so I'm pretty sure it's not one of those that's causing the problem. I only use globals when macros are referenced by other macros - in this case there is no connection between them.

Even if they were global variables, they are being re-created each time from supposedly unchangeable document properties so it looks like the document properties themselves are changing. I wondered if the save command could actually change document properties so that the path becomes just the save filename and the path itself is lost?

This is what's actually happening:

The first macro normally sets the fullpath, example "c:\users\tim\TP1057-101.iso"

But if I run the 2nd macro which saves the illustration down with a suffix, adding "-211" to the filename, then run the first macro again, fullpath becomes "TP1057-101-211.iso" - no path anymore.

If I close the illustration down and re-load it, the 1st macro works OK again, as though document properties are being changed in memory by the save command in the 2nd macro.

I'm still not 100% with the way IML works, but I presume defining MyDoc as document should enable me to read the attributes of the current illustration, and that these attributes should not be affected by any macro.

It's probably my lack of understanding of IML that's the problem - perhaps I should be interrogating the current filename from some other property?

This is something that may work ? just a thought

Macro Name

Define docname as String
Define path as String


path=stripFileName(activeDoc.path)
docname = stripExt(activeDoc.name)
Save path+docname+".iso" "Version_71"

End Macro

Macro New name

Define docname as String
Define path as String


path=stripFileName(activeDoc.path)
docname = stripExt(activeDoc.name)
Save path+docname+"-211"+".iso" "Version_71"

End Macro

In your first macro you should make sure that myDoc is not only defined but also assigned. E.g. with

myDoc = app.documents[1]

or

myDoc = app.activeDoc

If you call the SAVE command without a path or a relative path, the full path information will get lost as you suspected. To avoid that, always save with the full path. E.g. in your second macro with

file_name = stripExt(activeDoc.path)

file_name = (file_name + "-211.iso")

Nice catch! Feel foolish that I missed that.

Top Tags