Skip to content

Get Simulation Default Settings

This example demonstrates how to retrieve the default simulation settings for a specific G-Code. This is useful for understanding what parameters will be used when running a simulation, and for customizing those parameters as needed.

Create the following GraphQL query file, then run your language’s codegen tool to generate the types.

queries/DefaultSimulationSettings.graphql
query DefaultSimulationSettings($gcodeId: ID!) {
defaultSimulationSettings(gcodeId: $gcodeId) {
roomTemperature
stabilizedAirTemperature
nozzleTemperature
platformTemperature
fanSpeed
airTemperatureAboveBuildPlate
}
}

API Reference:

  1. Setup the client and configuration

    index.ts
    import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client";
    import { DefaultSimulationSettingsDocument } from "./queries/__generated/DefaultSimulationSettings.generated";
    // Load PAT from environment
    const PAT = process.env.PAT;
    if (!PAT) {
    throw new Error("PAT environment variable is required");
    }
    // Create Apollo Client
    const client = new ApolloClient({
    cache: new InMemoryCache(),
    link: new HttpLink({
    uri: "https://api.helioadditive.com/graphql",
    headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${PAT}`,
    },
    }),
    });
    // Replace with an actual G-Code ID from your account
    const GCODE_ID = process.env.GCODE_ID ?? "your-gcode-id";
    // Helper function to convert Kelvin to Celsius
    function kelvinToCelsius(kelvin: number): number {
    return kelvin - 273.15;
    }
  2. Fetch the default simulation settings

    Query the API to get the default settings for your G-Code.

    async function getSimulationDefaults(gcodeId: string) {
    console.log(`Fetching default simulation settings for G-Code: ${gcodeId}`);
    const { data } = await client.query({
    query: DefaultSimulationSettingsDocument,
    variables: { gcodeId },
    fetchPolicy: "no-cache",
    });
    const settings = data?.defaultSimulationSettings;
    if (!settings) {
    throw new Error("Failed to get default simulation settings");
    }
    return settings;
    }
  3. Display the settings

    Print the default settings in a readable format.

    function displaySettings(settings: any) {
    console.log("\nDefault Simulation Settings:");
    console.log("============================");
    console.log(`Room Temperature: ${settings.roomTemperature}K (${kelvinToCelsius(settings.roomTemperature).toFixed(1)}°C)`);
    console.log(`Stabilized Air Temperature: ${settings.stabilizedAirTemperature}K (${kelvinToCelsius(settings.stabilizedAirTemperature).toFixed(1)}°C)`);
    console.log(`Nozzle Temperature: ${settings.nozzleTemperature}K (${kelvinToCelsius(settings.nozzleTemperature).toFixed(1)}°C)`);
    console.log(`Platform Temperature: ${settings.platformTemperature}K (${kelvinToCelsius(settings.platformTemperature).toFixed(1)}°C)`);
    console.log(`Fan Speed: ${settings.fanSpeed}%`);
    console.log(`Air Temperature Above Build Plate: ${settings.airTemperatureAboveBuildPlate}K (${kelvinToCelsius(settings.airTemperatureAboveBuildPlate).toFixed(1)}°C)`);
    }
  4. Put it all together

    Combine all the steps and run the example.

    // Example usage
    getSimulationDefaults(GCODE_ID)
    .then((settings) => {
    displaySettings(settings);
    console.log("\nExample completed successfully!");
    })
    .catch(console.error);
  1. Create a .env.local file with your PAT and G-Code ID:

    Terminal window
    PAT="your-personal-access-token"
    GCODE_ID="your-gcode-id"
  2. Update the GCODE_ID with a valid G-Code ID from your account that is in READY status.

  3. Run the example:

    Terminal window
    bun run index.ts

You can use these default settings as a starting point and override specific values when creating a simulation:

import { CreateSimulationDocument } from "./mutations/__generated/CreateSimulation.generated";
// First, get the defaults
const defaults = await getSimulationDefaults(GCODE_ID);
// Then create a simulation with some overrides
const { data } = await client.mutate({
mutation: CreateSimulationDocument,
variables: {
input: {
gcodeId: GCODE_ID,
name: "my-simulation",
// Use defaults but override room temperature
roomTemperature: 298.15, // 25°C instead of default
// Other values will use G-Code defaults automatically
},
},
});