The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Redefine macro by appending new line
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 09/23/2005 :  10:04:20 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5SR5
Operating System: Win2000

Hi,

I'd like to be able to modify an existing macro by appending a new line at 'run time' eg

change
def Pete {
lines 1...n
}
to
def Pete {
lines 1..n
new line
}

simply doing something like
def pete {
type pete;
}

def pete {
pete;
type pete;
}

does horrible things like comand error or instant shutdown...

The issue here is that the macro is of the same name but could differ depending on the application but I will want to add the same line.

This would be really a useful way to add new functionality to old origin project files so any help would be appreciated.

Thanks,

Cheers,

pete

Mike Buess

USA
3037 Posts

Posted - 09/25/2005 :  09:16:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Pete,

I'm not surprised that your attempt to redefine a macro by calling itself has such dire consequences. Much safer to add a placeholder command in the original macro like this...

def pete {
type pete;
{pete2};
};

def pete2 {
type pete2;
};

The brackets around the pete2 call merely suppress the command error that would result if the pete2 macro was undefined.

Mike Buess
Origin WebRing Member
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 09/25/2005 :  1:29:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

Thanks for your reply! This method is useful and will help in a number of cases ie new apps and old apps where the code is unattached. (I wasn't aware of the use of a placeholder - maybe I spread a few around the code (eg post data input, post curve fit, post graph display, post results creation etc..) allowing for general modifications at a later date - I like this idea a lot. Something to think about thanks.

One case would still remain - old ops where the code is attached ie I can't insert a placeholder in these old saved opj files (attached files of). Any ideas or do you reckon I'm stuck here?

Q. Is there a way to list the code (eg as string) of a defined macro?

Maybe I need to consider an app to edit the attached code of old opj files. I can then (for cnf files) just rerun the whole file. This works manually (just tried) and I can save the new code. I just need a to find a way to do it via code.

Thanks again,

Cheers,

pete



Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/25/2005 :  3:54:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Pete,

"Placeholder" is my own ad hoc terminology for a function or object that might take on a number of forms or might even be absent. There's probably a more acceptable word for it. You can print a macro definition to the script window with 'def macroName' but I'm not aware of a way to redirect the definition to anything useful (like a string, file or even notes window). Of course if your macro runs a script file... def pete {run.file(pete.cnf)} ...you could edit that file with OriginC or FUM. However, that would probably require modifications to your old projects as well.

Mike Buess
Origin WebRing Member
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 10/05/2005 :  09:08:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Managed to use the file editing as described below. Does the job.


void show_file(string strfile = "htdr2001macros.cnf") // old macro file
{
string LTString;
string striFilename = GetAppPath() + strfile;
string stroFilename = GetAppPath() + "ftemp.cnf";
if(!DeleteFile(stroFilename)) {};
stdioFile ffo(stroFilename,file::modeCreate | file::modeReadWrite);

stdioFile ff;
bool bRet = ff.Open(striFilename, file::modeRead);
if(!bRet)
{
out_str("file not found!");
return;
}

string strTemp;
int CopyThis=0;
int CopyLine;
while(ff.ReadString(strTemp))
{
if((strTemp.Left(4).CompareNoCase("def ")==0)&&(CopyLine>1)) CopyThis=0;
if(strTemp.CompareNoCase("def displaygraphall {")==0) {
CopyThis=1;
}
if(CopyThis==1) {
//out_str(strTemp);
CopyLine++;
if(CopyLine!=1) {
ffo.WriteString(strTemp);
} else {
ffo.WriteString("def TempMacro {");
}
}
}

ff.Close();
ffo.WriteString("");
ffo.WriteString("def DisplayGraphall {");
ffo.WriteString("TempMacro;");
ffo.WriteString("run.section(Smilesjpg.ogs,\"AddImagesToGraph\");");
ffo.WriteString("};");
LTString="run ftemp.cnf";
out_str(LTString);
LT_execute(LTString);
//if(!DeleteFile(stroFilename)) {};
}


adds the line run.section(Smilesjpg.ogs,AddImagesToGraph); to the end of the displaygraphall macro and then reloads/redefines this macro.

Cheers,

pete

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000