kcl

import

Import a CAD file.

For formats lacking unit data (such as STL, OBJ, or PLY files), the default unit of measurement is millimeters. Alternatively you may specify the unit by passing your desired measurement unit in the options parameter. When importing a GLTF file, the bin file will be imported as well. Import paths are relative to the current project directory. Note: The import command currently only works when using the native Modeling App.

import(file_path: String, options?: ImportFormat) -> ImportedGeometry

Examples

const model = import("tests/inputs/cube.obj")

Rendered example of import 0

const model = import("tests/inputs/cube.obj", { type: "obj", units: "m" })

Rendered example of import 1

const model = import("tests/inputs/cube.gltf")

Rendered example of import 2

const model = import("tests/inputs/cube.sldprt")

Rendered example of import 3

const model = import("tests/inputs/cube.step")

Rendered example of import 4

Arguments

  • file_path: String (REQUIRED)
  • options: ImportFormat - Import format specifier (OPTIONAL)
{
	type: "fbx",
} |
{
	type: "gltf",
} |
{
	// Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system.
	coords: {
	// Axis the front face of a model looks along.
	forward: {
	// Axis specifier.
	axis: "y" | "z",
	// Specifies which direction the axis is pointing.
	direction: "positive" | "negative",
},
	// Axis pointing up and away from a model.
	up: {
	// Axis specifier.
	axis: "y" | "z",
	// Specifies which direction the axis is pointing.
	direction: "positive" | "negative",
},
},
	type: "obj",
	// The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters.
	units: "cm" | "ft" | "in" | "m" | "mm" | "yd",
} |
{
	// Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system.
	coords: {
	// Axis the front face of a model looks along.
	forward: {
	// Axis specifier.
	axis: "y" | "z",
	// Specifies which direction the axis is pointing.
	direction: "positive" | "negative",
},
	// Axis pointing up and away from a model.
	up: {
	// Axis specifier.
	axis: "y" | "z",
	// Specifies which direction the axis is pointing.
	direction: "positive" | "negative",
},
},
	type: "ply",
	// The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters.
	units: "cm" | "ft" | "in" | "m" | "mm" | "yd",
} |
{
	type: "sldprt",
} |
{
	type: "step",
} |
{
	// Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system.
	coords: {
	// Axis the front face of a model looks along.
	forward: {
	// Axis specifier.
	axis: "y" | "z",
	// Specifies which direction the axis is pointing.
	direction: "positive" | "negative",
},
	// Axis pointing up and away from a model.
	up: {
	// Axis specifier.
	axis: "y" | "z",
	// Specifies which direction the axis is pointing.
	direction: "positive" | "negative",
},
},
	type: "stl",
	// The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters.
	units: "cm" | "ft" | "in" | "m" | "mm" | "yd",
}

Returns

ImportedGeometry - Data for an imported geometry.

{
	// The ID of the imported geometry.
	id: uuid,
	// The original file paths.
	value: [string],
}