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
 "exist" function with a workbook/graph long name
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ds755

57 Posts

Posted - 08/30/2018 :  07:19:07 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 2018
Operating System: Windows 8.1

Hello,

Is there any way to use the "exist" function with the workbook long names? (The short names are way too short to be useful to me.)

The following code gives 0, even though the workbook exists (and is activated):

exist(page.longname$)=

Hideo Fujii

USA
1582 Posts

Posted - 08/30/2018 :  09:43:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi ds755,

There should be better way, but at least this may let you work around...
Supposing any existing workbook has a column, so try this:
range rhello=["hello"]!col(1);
exist(rhello)=;
==>exist(rhello)=1
range rbye=["bye"]!col(1);
exist(rbye)=;
==>exist(rbye)=0
This seems working in my Origin 2018b. How about in your version?

--Hideo Fujii
OriginLab
Go to Top of Page

Chris D

428 Posts

Posted - 08/30/2018 :  10:38:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

It seems it is not possible to use long name with exist function. It may be related to the fact that multiple windows can have the same long name or perhaps it was just never implemented for long names.

Maybe you can provide a bit more info about why you are using the function- there may be an alternate way to achieve what you want.



Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

ds755

57 Posts

Posted - 08/30/2018 :  2:01:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hideo and Chris,

Hideo: Indeed, this works, but not if I replace "hello" with a string variable.

To both: Basically, my filenames contain metadata separated by a delimiter (e.g. sample_conditions_experiment-time_scanNo... The script then detects these metadata and plots these files using the corresponding template (one template for every combination of sample conditions experiment time etc...).

The "exist" function is used to detect if this plot already exists. If yes, then the conditions are similar and the data are plotted in the existing plot. If not, then a new plot is created.

I have already programmed this using the short name, but it is just too short... The character limitation of the short name is the problem.


P.S. I do not understand why the short name exists. All the programming should be done through the long name, which should be unique for each file.
Go to Top of Page

Chris D

428 Posts

Posted - 08/30/2018 :  3:37:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, the following code snippit will search the project for a workbook whose long name matches a search string. It will then activate that book and stop searching. If more than one book with same long name exists, it will activate the first created book with that long name.

You can adapt it to your needs.

It uses a combination of the document command (doc): https://www.originlab.com/doc/LabTalk/ref/Document-cmd#-e_object_.7Bscript.7D.3B_Execute_the_given_script_for_all_objects
and Substitution notation: https://www.originlab.com/doc/LabTalk/guide/Substitution-Notation#Worksheet_Information_Substitution

string strToFind$ = "a_b_c";

doc -e W {
	string strLN$ = %(%H, @PL);
	if (strLN$ == strToFind$)
	{
		win -a %H;
		break;
	}
}


The reason short name exists is because each object (window, columns, etc) MUST have some sort of unique identifier within it's context. Because long names do not have to be unique at all, they don't serve to uniquely identify a given object. Technically these objects can have a UID which is an integer identidifer but that gets more complicated to deal with because it is really more of an internal Origin thing.

I hope this helps.

Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 08/31/2018 :  09:37:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi ds755,

> Indeed, this works, but not if I replace "hello" with a string variable.

This seems working:
vhello$="hello";
vbye$="bye";
range rvh=["%(vhello$)"]!col(1);
range rvb=["%(vbye$)"]!col(1);
exist(rvh)=;
==>exist(rvh)=1
exist(rvb)=;
==>exist(rvb)=0

Also, you can first get the Book's unique universal identifier (UID) with the long name, then
convert back to the Book with short name using functions range2uid and uid2name, respectively.
For example:
vhello$="hello";
vbye$="bye";
exist(%(uid2name(range2uid(["%(vhello$)"]))$))=;
==>2
exist(%(uid2name(range2uid(["%(vbye$)"]))$))=;
==>0
This uid method works also for the graph window. (It returns 3 when it exists.)

https://www.originlab.com/doc/LabTalk/guide/LT-objs
https://www.originlab.com/doc/LabTalk/ref/Range2uid-func
https://www.originlab.com/doc/LabTalk/ref/Uid2name-func

Hope this helps.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 08/31/2018 5:16:32 PM
Go to Top of Page

ds755

57 Posts

Posted - 09/01/2018 :  5:29:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hideo and Chris,

Hideo's recommendation with the UID helped solve the problem. Neat trick! Now I can check if things exist via the long name.

Thanks a lot to both of you.
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