{"id":16441,"date":"2021-07-22T02:23:54","date_gmt":"2021-07-22T06:23:54","guid":{"rendered":"http:\/\/blog.originlab.com\/?p=16441"},"modified":"2021-07-22T02:51:35","modified_gmt":"2021-07-22T06:51:35","slug":"how-to-create-an-app-using-an-x-function","status":"publish","type":"post","link":"https:\/\/blog.originlab.com\/ja\/how-to-create-an-app-using-an-x-function","title":{"rendered":"How to create an App using an X-Function"},"content":{"rendered":"<h4><strong>\u306f\u3058\u3081\u306b<\/strong><\/h4>\n<p>X-Function provides a framework for building Origin tools. Using X-Function, we can only focus on the function details and the code, and don\u2019t have to be concerned about the tool\u2019s GUI. The ease of use makes X-Function an attractive approach to creating Apps.<\/p>\n<p>In this blog post, I will show you how to create an App using X-Function. I will present the process of creating an app and continuing to develop an app.<\/p>\n<p>I will assume that you already know how to create an X-Function. But if you are unfamiliar with that, documentation is available <a href=\"https:\/\/www.originlab.com\/doc\/X-Function\/guide\">online<\/a>.<\/p>\n<h4><strong>Getting Started<\/strong><\/h4>\n<p>The first step in creating an app is to get the components of an app ready. The absolute necessary components of an Origin app include:<\/p>\n<p style=\"padding-left: 40px;\">(1) Code files<\/p>\n<p style=\"padding-left: 40px;\">(2) A 32 * 32 pixel PNG file for the App icon<\/p>\n<h5><em>Creating \/ Downloading the X-Function<\/em><\/h5>\n<p>In this blog, we will include an X-Function as a code file. This X-Function will perform the task of copying data from one column to another. We can:<\/p>\n<ul>\n<li>Create the X-Function following the <a href=\"https:\/\/www.originlab.com\/doc\/X-Function\/guide\/Creating-a-Simple-X-Function\">tutorial<\/a>.<\/li>\n<\/ul>\n<p style=\"padding-left: 40px;\">or<\/p>\n<ul>\n<li>Download the <a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/July15_TrainingFiles_MyApp.zip\">zip file<\/a> to achieve the X-Function directly.<\/li>\n<\/ul>\n<h4><strong>Creating a Folder and Adding Files<\/strong><\/h4>\n<h5><em>Creating a Folder<\/em><\/h5>\n<p>The next step is to create a folder for the App.<\/p>\n<p style=\"padding-left: 40px;\">(1) Open <strong>Code Builder<\/strong>, go to <strong>Workspace<\/strong> tab that is by default docked to the left side, you will see a folder named <strong>Apps<\/strong>.<\/p>\n<p style=\"padding-left: 40px;\">(2) To create the folder for a new App, right-click on the <strong>Apps<\/strong> and select <strong>New<\/strong>, and then rename this new folder to the name of the App, for example, name it &#8220;My App&#8221;.<\/p>\n<h5><em>Adding Files<\/em><\/h5>\n<p>At this point, we can add the components mentioned above to the App folder.<\/p>\n<p style=\"padding-left: 40px;\">(1) Right-click on &#8220;My App&#8221; folder and select <strong>Add Files\u2026<\/strong><\/p>\n<p style=\"padding-left: 40px;\">(2) Browse to select the icon and the X-Function (OXF file), and click <strong>Open<\/strong> button to add them to the current folder.<\/p>\n<p style=\"padding-left: 40px;\"><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16485 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_1.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_1.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_1-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_1-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<h4><strong>Packaging and Installing an App<\/strong><\/h4>\n<h5><span style=\"color: #333333;\"><em>Packaging an&nbsp;App<\/em><\/span><\/h5>\n<p>Now we can package the App into an OPX file.<\/p>\n<p style=\"padding-left: 40px;\">(1) Again in <strong>Workspace<\/strong> tab of <strong>Code Builder<\/strong>, right-click on the folder \u201cMy App\u201d and select <strong>Generate\u2026<\/strong> to open <strong>Package Manager<\/strong>.<\/p>\n<p style=\"padding-left: 40px;\">(2) In <strong>Package Manager<\/strong>, edit the required fields as illustrated below. The most important field is Launch Script. That is a single-line LabTalk script that will run when the icon is clicked in the App Gallery. In this case, we will type the script <code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">CopyCol -d;<\/code>.&nbsp;<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16486 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_2.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_2.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_2-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_2-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<blockquote>\n<p><strong>Note<\/strong>: &#8220;CopyCol&#8221; is the name of the X-Function, while &#8220;-d&#8221; is an <a href=\"https:\/\/www.originlab.com\/doc\/LabTalk\/guide\/XF-Execution-Options\">X-Function execution option<\/a> for bringing up the dialog of the X-Function.<\/p>\n<\/blockquote>\n<p style=\"padding-left: 40px;\">(3) Once all of the fields have been properly filled in, we can select the menu <strong>File<\/strong> of <strong>Package Manager<\/strong> to save the OPX file.<\/p>\n<blockquote>\n<p>For a more detailed look at <strong>Package Manager<\/strong>, see <a href=\"https:\/\/www.originlab.com\/doc\/Origin-Help\/FileShare-Pack-OPX\">this page<\/a>.<\/p>\n<\/blockquote>\n<h5><span style=\"color: #333333;\"><em>Installing the new App<\/em><\/span><\/h5>\n<p>Once saved, the OPX can be dragged into Origin to install the App. When first installed, there will be a prompt to replace the existing files. It is okay to select <strong>Replace All. <\/strong><\/p>\n<p>Upon installation, a new icon will be added to Apps Gallery. We can click the icon to launch the App.<a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16488 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_3.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_3.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_3-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_3-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16506 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_8.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_8.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_8-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_8-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<h4>Updating the App<\/h4>\n<h5><span style=\"color: #333333;\"><em>Updating the X-Function<\/em><\/span><\/h5>\n<p>We will probably want to continue developing the App by adding or changing the code files.<\/p>\n<p>Let\u2019s suppose that we would like to add a new option to the dialog to sort the output column, and we are going to use <strong>X-Function Builder<\/strong> to improve the X-Function CopyCol.<\/p>\n<p style=\"padding-left: 40px;\">(1) First, right-click on the App icon and select <strong>Show in Folder<\/strong>. That is the location where Origin stores the files of the App, so remember it.<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16490 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_4.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_4.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_4-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_4-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p style=\"padding-left: 40px;\">(2) Open<strong> X-Function Builder<\/strong>, and click <strong>Open<\/strong> button and select the X-Function CopyCol from the App Folder mentioned above.<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16492 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_5.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_5.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_5-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_5-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p style=\"padding-left: 40px;\">(3) Right-click on the <strong>Variables<\/strong> list and select <strong>Add Variable. <\/strong>Change the name, label, and other values of the new variable as illustrated below:<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16493 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_6.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_6.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_6-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_6-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p style=\"padding-left: 40px;\">(4) Click <strong>Code Builder<\/strong> button and modify the code of main function to:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ocol = icol;\nif(1 == sort)\n    ocol.Sort();\nelse if(2 == sort)\n    ocol.Sort(SORT_DESCENDING);\n<\/pre>\n<p style=\"padding-left: 40px;\">(5) After this, compile and return to <strong>X-Function Builder, <\/strong>then save the X-Function by clicking <strong>Save<\/strong> button.<\/p>\n<h5><em>Updating the OPX File<\/em><\/h5>\n<p>Now, we can update the OPX file with the latest changes.<\/p>\n<p style=\"padding-left: 40px;\">(1) In <strong>Code Builder<\/strong>, right-click again on the <strong>App<\/strong> folder in the <strong>Workspace<\/strong> tab and select <strong>Generate\u2026<\/strong>.<\/p>\n<p style=\"padding-left: 40px;\">(2) All the fields are already filled with the last-used values. Generally, we can just increment the version number and save the OPX file.<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16498 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_7.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_7.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_7-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_7-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p style=\"padding-left: 40px;\">(3) After regenerating the opx file, we don\u2019t have to reinstall the App. Origin will automatically help to change. We can just click the icon to launch the App and enjoy the new App.<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16507 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_9.png\" alt=\"\" width=\"768\" height=\"432\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_9.png 768w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_9-300x169.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_9-16x9.png 16w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n\n\n<p class=\"wp-block-paragraph\"><\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction X-Function provides a framework for building Origin tools. Using &hellip; <\/p>","protected":false},"author":4811,"featured_media":16543,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[102],"tags":[132,133,134],"class_list":["post-16441","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-other","tag-apps","tag-x-function","tag-opx"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7DvU2-4hb","jetpack_likes_enabled":true,"jetpack_featured_media_url":"https:\/\/blog.originlab.com\/wp-content\/uploads\/2021\/07\/20210716_11.png","post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/16441","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/users\/4811"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/comments?post=16441"}],"version-history":[{"count":65,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/16441\/revisions"}],"predecessor-version":[{"id":18190,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/16441\/revisions\/18190"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/media\/16543"}],"wp:attachment":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/media?parent=16441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/categories?post=16441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/tags?post=16441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}