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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Can you read from a text file in macros?

TimSharp
12-Amethyst

Can you read from a text file in macros?

I have a macro that writes filenames to a text file using fwrite.

However, I don't want repeats, so want to check that the filename doesn't already exist in the text file before writing it.

I use the fwrite command but can't find a corresponding read command. Is this possible within the macros?

11 REPLIES 11

I'd look into the batch command. You could run it checking if your currently held value existed in the file. Issues with this idea that you should be aware of is that each time you write a value you'll be reading the file over again. Probably not much of a performance hit for smaller lists, but could have some noticeable issues if you're lists are long.

Another approach might be to first write your value to a variable. You'd have to do a comma delimited string, but this should suffice. You could then search the string before writing your text file. If it exists, don't write. If you look into this route, take into consideration character limitations of variables (I believe 256).

Thanks for giving me more ideas - hopefully they will help.

Yes I was wondering what the overhead might be. I have each drawing name being put into a text file and another text file that puts macro names in as they are run - intention to check which macros are being used by illustrators. So far, the files are small so there doesn't seem to be any effect on speed, but I'll see how it goes in a week or two - I might have to disable them, or have it create a new file every day.

Adding to a text file shouldn't show a reduction in performance. It's only if you want to read the values to check for duplicates.

I implemented a similar tracking element on 2-26-09. It tracks some of our macros (not all) and has been running since. It keeps the user name, macro name, illustration, and date/time it was run. At this point there are 34,692 lines in it. No one has said a word about performance degredation.

Again, no need to worry about size other than when you are trying to check if an entry already exists.

I wondered whether it would slow down just writing to the file, but I guess your 34,692 line file is proof that it doesn't! Not worth having it de-dupe them if it will slow it down.

I'd already taken the step of creating separate files for each illustrator and a new file each day (all held in the central directory on the server so it's easy to find them). I'm still pondering if I should add further information. Currently I only write the macro name except for the CGM macro where I write the illustration name as well (this is run when the drawing is complete).

I started logging about 3/4 of the top level macros this morning and there are nearly 300 lines in the useage files already. In general, macros are used much more frequently than I had thought and several I thought were redundant are used regularly. Also it shows me that one illustrator has not used the CGM macro all day - presumably insisting on opening the dialogue boxes every time he saves a drawing.

I should be able to estimate how much we've saved with the macros - perhaps I should include a typical 'seconds saved' figure in the files so that at some later date these can be totted up.

Using the log file really helped us when we started. We ran into an illustrator, as you have, that did not use the macros. Utilizing the log we were able to address this with the illustrator and track that the change had been made in their process.

As you can infer, I also wrote the user name out. Because of this I couldn't use the fwrite command. I actually use a launch command which runs a quick echo line to a file. It does have the drawback that a command window pops-up, but it has also allowed us to see who last touched a file.

Yes I think this will help us. I was a little worried that it might seem like snooping on people but I think it will be really useful, and my work is logged as well.

I'm not sure what you mean by not being able to use the fwrite command for usernames.

All I meant by not being able to use the fwrite command because of the username is that I found no one to find out the current user within IsoDraw. There was nothing like the %username% variable available in Windows command prompt or similar environment variable. If you find something, please post it as I'd be interested in updating my coding.

We don't get the username, only a location for the macro files, but the principle should work for a username as well.

It's just a little .ism file that resides on each computer containing a single macro to set the location:

global gl_prefs_path_variable as float

macro set_prefs_path_variable NOT_IN_MENU

gl_prefs_path_variable = "X:\Illustrators Info\ISODraw Config Files\Tim Sharp\"

end macro

Of course this file is different on each computer, but having it separate means I don't overwrite it each time I update other macros.

Running this macro from another macro creates the global variable that is then used to store our macro useage files in the correct location.

Do you use PrefsPath.txt to keep all macros in a central location? We had to use PTC support to find out about it, but it helps me a lot in maintaining the macros.

I haven't heard of the PrefPaths.txt file. Can you elaborate?

My current method (just updated since the new year) is to maintain all the macros in a network folder. Each user computer just has a shortcut to this path in their macro folder. IsoDraw will follow the shortcut and then picks up the macros.

Up until this setup I had a VB/CMD hybrid system in which a VB script in the user startup folder would kick off a network CMD file. The CMD would then clear the users macros folder and then reload from the network folder. Worked pretty well except that some users were not rebooting their computers for sometimes weeks. The shortcut method allows me to roll out an update instantaneously.

I might learn something from you here (again).

From what you said, you probably already use something like the prefspath.txt file, though yours sounds like it does what we originally wanted!

We don't have network access back to user computers here, so whenever I updated the macros, I had to physically go to each user computer and update them while the illustrator was at lunch, or knock them off for a couple of minutes. PTC told us how to use a PrefsPath.txt file to redirect all Isodraw customisations to a central network location.

The prefspath.txt file is placed in each computer's Isodraw directory (e.g. c:\documents and settings\SharpT\Application Data\PTC\IsoDraw)

All it contains is a just a reference to where the Isodraw preferences and macros are stored for that user.

For example mine is "X:\Illustrators Info\ISODraw Config Files\Tim Sharp\"

Isodraw reads prefspath.txt and then loads all preferences and macros from that central Network location - and saves Preferences there again.

We have a separate directory for every Isodraw computer because if they all used the same one, each user would overwrite a common preferences file when they exited Isodraw.

Each time the macros change, I have to update them for every user, but because they are all together, it's a lot easier than having to go to everyone's computer to do it.

However, if I understand properly what you say, you can do this within the macros directory and it only tells Isodraw where to look for the macros, not the Preferences files?

How do you put the shortcut in your macro folder - is it just a text file like PrefsPath.txt that Isodraw looks in automatically?

If this works, I could have the macros in 1 central directory like you and not have to update them all individually.

I still had the setup for deleting and replacing macros and preferences on each users computer. So, I just changed it so it copies over a generic shortcut (literally a windows shortcut .lnk file) to the network location.

In regards to preferences, I still replace those each reboot. It makes my life easier. Most of our users are 101 users and thus don't know much beyond the toolbar and the macros (which are still provided in a toolbar). By pirating their preference files (both toolbar and general preferences) I've been able to control output and screen appearance (we all have the same machines).

User customization got to be a headache when we used Illustrator in the past. Each person had their own shortcuts and tools setup. I couldn't do anything I did on my computer as a shortcut because it would not match. We couldn't share macros because we might overwrite each others previous settings. I know that it irritates some of our users, but the benefits have calmed them down.

Thanks for the info on the txt file! Learn something new every day.

Announcements

Top Tags