Space Engineers

Space Engineers

175 ratings
EasyAPI
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
34.084 KB
Jan 22, 2015 @ 12:44am
Nov 6, 2018 @ 6:18pm
58 Change Notes ( view )

Subscribe to download
EasyAPI

Description
EasyAPI makes writing powerful scripts a breeze by providing a simple query API to find and manipulate blocks, inventories, properties, and actions. It also allows you to schedule events so that a function gets called when the event occurs. Below is an overview of how easy things are in EasyAPI. There are many more examples in the documentation.

See the EasyAPI Documentation guide for a tutorial and the full documentation of the API.

I have created a GitHub repository for EasyAPI. You can find it at https://github.com/rockyjvec/EasyAPI

The Change Notes tab lists what was added in the latest updates.

Easy Commands

The Easy Commands feature provides a way for people to quickly do things to their ship just using arguments to a PB without doing any programming.

To use this feature, just add EasyAPI to a PB (Programmable Block), and then run the pb with an argument that starts with EasyCommand followed by the command you want to run.

For example, you could put the following as the argument when the PB is run on a button panel:
EasyCommand Blocks.OfTypeLike("Door").ApplyAction("Open_Off");

That command will close all the doors on your ship when the button is pressed. There are tons of block filters and actions built in to easyapi. You can find a (mostly) complete list in the documentation. Just search for "filters" or "actions". Leave a comment below if you need help.


Easy Arguments

Want to toggle all your lights when a button is pressed? It only takes the code below. Just put the PB Run action on any button or cockpit action key you want and use "ToggleLights" for the argument.

Code for toggling lights when button panel button or cockpit key pressed.
public class Example : EasyAPI { public void toggleLights() { Blocks.OfTypeLike("Light").ApplyAction("OnOff"); } public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { On("ToggleLights", toggleLights); } }

Easy Inventory Management

Want to clean all your assembler input inventories by moving all stone to your cargo containers?
Blocks.OfType("Assembler").Items().InInventory(0).OfType("Stone").MoveTo(Blocks.OfTypeLike("Cargo Container"));

Get the number of construction components in all your large cargo containers:
int NumConstructs = Blocks.OfType("Large Cargo Container").Items().OfType("Construct").Count();


Easy Block Actions

To turn off all the Spotlights on your ship that have "Front" in their names:
Blocks.OfType("Spotlight").NamedLike("Front").Off();

Actions specific to a block are also supported. Let's say you want to make all the sound blocks on your ship play at once:
Blocks.OfType("Sound Block").ApplyAction("PlaySound");


Easy Setting/Getting Block Properties

This example syncs the gravity field width, height, and depth of all the gravity generators on your ship. If you change one of those properties in "Gravity Generator 1" the new value will automatically get copied to the rest of them:
public class Example : EasyAPI { public void UpdateGravGens() { EasyBlocks AllGravGens = Blocks.OfType("Gravity Generator"); EasyBlocks SourceGravGen = AllGravGens.Named("Gravity Generator 1"); Single Height = SourceGravGen.GetProperty<Single>("Height"); Single Width = SourceGravGen.GetProperty<Single>("Width"); Single Depth = SourceGravGen.GetProperty<Single>("Depth"); AllGravGens.SetProperty<Single>("Height", Height); AllGravGens.SetProperty<Single>("Width", Width); AllGravGens.SetProperty<Single>("Depth", Depth); } public Example(IMyGridTerminalSystem grid, IMyProgrammableBlock me, Action<string> echo, TimeSpan elapsedTime) : base(grid, me, echo, elapsedTime) { Every(1 * Seconds, UpdateGravGens); } }

Easy to Learn

A tutorial, lots of examples, and the full documentation are available in my EasyAPI Documentation guide. I keep adding new features and examples.

Add-On Modules

These are extra features that are designed to work with EasyAPI
  • EasyMenu - Design menus to control your ship's systems.
  • EasyLCD - This is currently included in the EasyAPI script.
If you have designed an add-on module, let me know in the comments below and I'll add it to this list.

Make your own scripts and mods

Please feel free to use and include this script in your own Steam Workshop scripts/mods.

Collaborate to make it better!

I have created a GitHub repository for EasyAPI. You can find it at https://github.com/rockyjvec/EasyAPI

Have an idea that you would like to see implemented in EasyAPI? Feel free to fork EasyAPI and implement your feature or make a suggestion in the comments or discussions below.

Thanks!

I would like to thank the following people for their contributions to EasyAPI:
  • Bush Tucker Man
  • LukeStrike
Popular Discussions View All (12)
33
Jun 16, 2016 @ 10:17am
PINNED: List of features to add
rockyjvec
8
Jun 12, 2016 @ 7:53pm
Alert status system
Aaron Tigan
7
Apr 8, 2015 @ 11:25pm
All In One Life Support System
Aaron Tigan
597 Comments
Delta99 Jun 20, 2021 @ 8:14pm 
I think the author is long gone
jbo96 Jun 20, 2021 @ 7:21pm 
any updates to this?
Delta99 Feb 23, 2020 @ 6:53pm 
Post it up on pastebin or something maybe
tismoj Feb 15, 2020 @ 11:16am 
Hi, I may have fixed the errors but I haven't any existing scripts that use this yet since I only came across this today and I just wanted to use it so I tried to fix it. could someone please verify this for me?

It should get rid of the errors but a lot of deprecation warnings still remain I just wanted to try this API first, and hopefully, someone else could verify that it still works on their existing code

Just replace the very long last line, the one with the minified library code with this:
<I tried to paste the very long line here but it exceeded the 1000 char limit>

Any suggestion as to how I could send the fix for everyone here?
gaimi.darai Apr 17, 2019 @ 2:57pm 
This is now returning Check Code error:

42/19765, There is no argument that corresponds to the required formal parameter 'items' of MyInventory.GetItems
LukeStrike Nov 7, 2018 @ 5:29am 
Works pretty fine again, thanks Rock ;)

In my example https://steamcommunity.com/workshop/filedetails/discussion/379297410/357288572132613477/ everything goes well :)

LKS
Delta99 Nov 6, 2018 @ 9:40pm 
Nice to see you back in action rockyjvec. I had to fix this myself a few months back.
rockyjvec  [author] Nov 6, 2018 @ 6:19pm 
Fixed the compile error.
Delta99 Jul 21, 2018 @ 12:57pm 
Looks like this is broke now. Any plans for updating?
zmiller1 Jul 30, 2017 @ 8:52am 
Does this still work?