Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline charlamb  
#1 Posted : 10 May 2023 23:44:05(UTC)
charlamb


Rank: Member

Groups: Registered
Joined: 02/06/2022(UTC)
Posts: 14
Brazil

Was thanked: 1 time(s) in 1 post(s)
Hi,

I was wondering if it is possible to auto load (a) file(s) with custom functions/constants @ start up of SM so to avoid having to write include statements every time.

Thanks very much in advance.

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 11 May 2023 13:32:22(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
You can't. But you can always make a template and run a copy on startup.

You can edit the bat file with a notepad to change the dafault paths and filenames. You can create several batch scripts to start different templates.

SMath Template 1.zip (1kb) downloaded 16 time(s).

Edited by user 11 May 2023 13:36:45(UTC)  | Reason: attachment

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 12/05/2023(UTC)
Offline Jean Giraud  
#3 Posted : 11 May 2023 15:23:52(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
You can write a single include with all functions collected.
Each function c/w applicable parameters/constants.
Once in blank document front ended of include,
call any indexed parametric function, plug new parameters/constants.
That's the way I fit model function to data sets.
Offline Kenny Lemens  
#4 Posted : 12 May 2023 19:02:25(UTC)
Kenny Lemens


Rank: Advanced Member

Groups: Registered
Joined: 11/01/2018(UTC)
Posts: 132
Man
United States
Location: Wisconsin

Was thanked: 58 time(s) in 37 post(s)
Greetings,

Originally Posted by: charlamb Go to Quoted Post
I was wondering if it is possible to auto load (a) file(s) with custom functions/constants @ start up of SM ...


One approach would be to create a 'template' file, where you get in the habit of opening it up as your first document of the day:

FORUM: https://en.smath.com/for...templates.aspx#post75364
Originally Posted by: carv Go to Quoted Post
Create an empty file with your template settings and set it as readonly, when you try to save Smath will ask you a new name.


Another technique would be to save your functions within a snippet file. While these functions are not loaded into SMath by default, you can access/insert the 'snippet' from the dynamic assistant to quickly insert these functions into your current worksheet (unlike include, a snippet will not reference the current version: it is not dynamic/relative and needs to be updated by a sheet to sheet basis where it was utilized if it comes time to update the functions in your snippet file)

WIKI: https://en.smath.com/wiki/Snippets.ashx
FORUM: https://en.smath.com/for...ecriptions.aspx#post3975
Originally Posted by: omorr Go to Quoted Post
... the "snipped" is like any other SMath file, but if you save it in the "snippet" folder you can insert into your existing worksheet via Snippet Manager (as collapsed area or not). Therefore, just make the *.sm file and pay attention on File=>Properties. There are two options "Summary" and "File [attributes]". What you put in the Summary - Title that will show as a snippet title ( I suppose that you did not put anything there and that is way the snippet description is the same as your file name - with *.sm added). What you put in the File attributes - Snippet shortcut - that name will appear in the Dynamic [Assistance[ (in order to insert in via Dynamic Assistance, if you like).



I did develop a solution to this dilemma, but it does not apply to functions: only numerical constants

Modify SMath "Entries" directly:
You have a file in your SMath install folder: 「C:\Program Files (x86)\SMath Studio\entries\Constants.xml」; if you look into it, this is where your gravitational constant is defined. I would advise you create your numerical constants in a similar fashion.

Since the XML files within this folder are system files, do not modify 「Constants.xml」 or 「Units.xml」 if you do not have the confidence to do so. With that being said, we do not need to edit these files; ANY xml file in the "entries" folder will be loaded upon startup, so just create a new XML file that matches the same scheme as 「Constants.xml」; but make sure not to redefine any constant/unit as that will be invalid, SMath will fail to startup (no error message will be provided, it will just fail to get past the loading SMath image.)

For example, copy and paste the following into Notepad, save it as an XML file in the folder: 「C:\Program Files (x86)\SMath Studio\entries\」
Code:
<?xml version="1.0" encoding="utf-8"?>
<entries lang:default="eng" xmlns="http://smath.info/schemas/entries/1.0" xmlns:lang="http://smath.info/schemas/entries/1.0">
  <constants>
    <!-- AWC Manual; Table M5.4-1 Average Specific Gravity and Weight Factor  -->
    <property dimension="613"><!-- in terms of [unitless] -->
      <add factor="0.50"  title="Density of Douglas Fir-Larch" >
        <synonym name="SG.douglas fir-larch" />
      </add>
      <add factor="0.42"  title="Density of Spruce-Pine-Fir (North)" >
        <synonym name="SG.spruce-pine-fir SG.SPF" />
      </add>
    </property>
    <add factor="0.00002304" connection="1/K" title="Coefficient of Expansion (Aluminum, Wrought); AISC 13th Edition - Table 17-11;  ΔL=L₀*ΔT*(α)" ><!-- in terms of [1/Δ°C] -->
      <synonym name="α.Aluminum˸ Wrought" />
    </add>
    <add factor="0.0000117" connection="1/K" title="Coefficient of Expansion (Mild Steel); AISC 13th Edition - Table 17-11;  ΔL=L₀*ΔT*(α)" ><!-- in terms of [1/Δ°C] -->
      <synonym name="α.Steel˸ Mild" />
    </add>
  </constants>
</entries>

As a crash course: factor is the numerical value, connection is unit, title is the description, and name is the constant/variable name within the sheet itself. NOTE: you can have several aliases for the same value, just separate each alias within the 'name' field by a space. Also, there are special characters like 「(」 and 「.」; you may need to experiment with your naming convention to get the variables to display correctly. Also note that this will create constants, so they will behave like units: they use the ' as the first character, and they show up as 'blue' text (not the black text of a variable).


The code/xml file above will generate (2) unitless variables that reference the correct 'dimension' property contained in 「Units.xml」, as well as (2) constants that manually map the connection to a respective unit (i.e. "1/K" for Coefficient of Expansion).
If SMath fails to start, there is an error in your XML file; correct the file until SMath is able to load. (Of course, you can always restore the contents of 'entries' to contain only the initial (2) files: 「Constants.xml」 or 「Units.xml」 to restore SMath capabilities.) Once implemented, you will notice these options in your dropdown. Other worksheets referencing this values will also reflect the real-time value as currently defined in the XML file (dynamic, not static).


I do have a similar technique for string/matrix constants, but it is more involved. However, I have yet to figure out how to trick SMath to consider a functions as a unit/constant.



May this be of Good Help;
⚜ Kenny Lemens, P.E. ᵂᴵ
"No matter where you go, there you are." -Buckaroo Banzai

Hotkeys: https://en.smath.com/for...rce.ashx?a=45771&b=2
Offline Jean Giraud  
#5 Posted : 13 May 2023 22:13:35(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: charlamb Go to Quoted Post
I was wondering if it is possible to auto load (a) file(s) with custom functions/constants @ start up of SM so to avoid having to write include statements every time.

All my Smath 4500 documents reside in a unique Directory.
If I open GenfitAlgoIncludeTestUpdated
@ the top of the document there is include("GenfitAlgoInclude.sm"Wink
At this point, the working document runs top to bottom,
fitting 7 data sets. Worked perfectly 6 months for the Originator.
As you download both in the same Download Directory,
simply open GenfitAlgoIncludeTestUpdated the working document.

Genfit Algo Include.sm (37kb) downloaded 7 time(s).
Genfit Algo Include Test UpDated.sm (139kb) downloaded 12 time(s).

Simply collect all your functions, all parametric of constants/parameters
Call the indexed one(s) of your choice ... update parameters/constants.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.