# Part¶

These are the generic properties every PART has. You can obtain a list of values of type Part using the LIST PARTS command.

structure Part
Members
Suffix Type Description
NAME String Name of this part
TITLE String Title as it appears in KSP
MASS Scalar Current mass of part and its resources
DRYMASS Scalar Mass of part if all resources were empty
WETMASS Scalar Mass of part if all resources were full
TAG String Name-tag if assigned by the player
CONTROLFROM None Call to control-from to this part
STAGE Scalar The stage this is associated with
CID String Craft-Unique identifying number of this part
UID String Universe-Unique identifying number of this part
ROTATION Direction The rotation of this part’s $$x$$-axis
POSITION Vector The location of this part in the universe
FACING Direction the direction that this part is facing
BOUNDS Bounds Bounding-box information about this part’s shape
RESOURCES List list of the Resource in this part
TARGETABLE Boolean true if this part can be selected as a target
SHIP Vessel the vessel that contains this part
GETMODULE(name) PartModule Get one of the PartModules by name
GETMODULEBYINDEX(index) PartModule Get one of the PartModules by index
MODULES List Names (String) of all PartModules
ALLMODULES List Same as MODULES
HASMODULE(name) Boolean True if the part has the named module in it, false if not.
PARENT Part Adjacent Part on this Vessel.
HASPARENT Boolean Check if this part has a parent Part
DECOUPLER Decoupler or String The decoupler/separator that will decouple this part when activated. None if no such exists.
SEPARATOR Decoupler or String Alias name for DECOUPLER
DECOUPLEDIN Scalar The stage number where this part will get decoupled. -1 if cannot be decoupled.
SEPARATEDIN Scalar Alias name for DECOUPLEDIN
HASPHYSICS Boolean Does this part have mass or drag
CHILDREN List List of attached Parts
Part:NAME
Access: Get only String

Name of part as it is used behind the scenes in the game’s API code.

A part’s name is the name it is given behind the scenes in KSP. It never appears in the normal GUI for the user to see, but it is used in places like Part.cfg files, the saved game persistence file, the ModuleManager mod, and so on.

Part:TITLE
Access: Get only String

The title of the part as it appears on-screen in the gui.

A part’s title is the name it has inside the GUI interface on the screen that you see as the user.

Part:TAG
Access: Get / Set String

The name tag value that may exist on this part if you have given the part a name via the name-tag system.

A part’s tag is whatever custom name you have given it using the name-tag system described here. This is probably the best naming convention to use because it lets you make up whatever name you like for the part and use it to pick the parts you want to deal with in your script.

WARNING: This suffix is only settable for parts attached to the CPU Vessel

This example assumes you have a target vessel picked, and that the target vessel is loaded into full-physics range and not “on rails”. vessels that are “on rails” do not have their full list of parts entirely populated at the moment:

LIST PARTS FROM TARGET IN tParts.

PRINT "The target vessel has a".
PRINT "partcount of " + tParts:LENGTH.

SET totTargetable to 0.
FOR part in tParts {
IF part:TARGETABLE {
SET totTargetable TO totTargetable + 1.
}
}

PRINT "...and " + totTargetable.
PRINT " of them are targetable parts.".

Part:CONTROLFROM()
Access: Callable function only None

Call this function to cause the game to do the same thing as when you right-click a part on a vessel and select “control from here” on the menu. It rotates the control orientation so that fore/aft/left/right/up/down now match the orientation of this part. NOTE that this will not work for every type of part. It only works for those parts that KSP itself allows this for (control cores and docking ports). It accepts no arguments, and returns no value. All vessels must have at least one “control from” part on them somewhere, which is why there’s no mechanism for un-setting the “control from” setting other than to pick another part and set it to that part instead.

Warning

This suffix is only callable for parts attached to the CPU Vessel

Part:STAGE
Access: Get only Scalar

the stage this part is part of.

Part:CID
Access: Get only String

Part Craft ID. This is similar to Part:UID, except that this ID is only unique per craft design. In other words if you launch two copies of the same design without editing the design at all, then the same part in both copies of the design will have the same Part:CID as each other. (This value is kept in the craft file and repeated in each instance of the vessel that you launch).

Part:UID
Access: Get only String

Part Universal ID. All parts have a unique ID number. Part’s uid never changes because it is the same value as stored in persistent.sfs. Although you can compare parts by comparing their uid it is recommended to compare parts directly if possible.

Part:ROTATION
Access: Get only Direction

The rotation of this part’s X-axis, which points out of its side and is probably not what you want. You probably want the Part:FACING suffix instead.

Part:POSITION
Access: Get only Vector

The location of this part in the universe. It is expressed in the same frame of reference as all the other positions in kOS, and thus can be used to help do things like navigate toward the position of a docking port.

Part:FACING
Access: Get only Direction

The direction that this part is facing, which is also the rotation that would transform a vector from a coordinate space where the axes were oriented to match the part, to one where they’re oriented to match the world’s ship-raw coordinates.

Part:BOUNDS
Access: Get only Bounds

Constructs a “bounding box” structure that can be used to give your script some idea of the extents of the part’s shape - how wide, long, and tall it is.

It can be slightly expensive in terms of CPU time to keep calling this suffix over and over, as kOS has to perform some work to build this structure. If you need to keep looking at a part’s bounds again and again in a loop, and you know that part’s shape isn’t going to be changing (i.e. you’re not going to extend a solar panel or something like that), then it’s better for you to call this :BOUNDS suffix just once at the top, storing the result in a variable that you use in the loop.

More detailed information is found on the documentation page for Bounds.

Part:MASS
Access: Get only Scalar

The current mass or the part and its resources. If the part has no physics this will always be 0.

Part:WETMASS
Access: Get only Scalar

The mass of the part if all of its resources were full. If the part has no physics this will always be 0.

Part:DRYMASS
Access: Get only Scalar

The mass of the part if all of its resources were empty. If the part has no physics this will always be 0.

Part:RESOURCES
Access: Get only List

list of the Resource in this part.

Part:TARGETABLE
Access: Get only Boolean

true if this part can be selected by KSP as a target.

Part:SHIP
Access: Get only Vessel

the vessel that contains this part.

Part:GETMODULE(name)
Parameters: name – (String) Name of the part module PartModule

Get one of the PartModules attached to this part, given the name of the module. (See Part:MODULES for a list of all the names available).

Part:GETMODULEBYINDEX(index)
Parameters: index – (Scalar) Index number of the part module PartModule

Get one of the PartModules attached to this part, given the index number of the module. You can use Part:MODULES for a list of names of all modules on the part. The indexes are not guaranteed to always be in the same order. It is recommended to iterate over the indexes with a loop and verify the module name:

local moduleNames is part:modules.
for idx in range(0, moduleNames:length) {
if moduleNames[idx] = "test module" {
local pm is part:getmodulebyindex(idx).
DoSomething(pm).
}
}

Part:MODULES
Access: Get only List of strings

list of the names of PartModules enabled for this part.

Part:ALLMODULES

Same as Part:MODULES

Part:HASMODULE(name)
Parameters: name – (String) The name of the module to check for Boolean

Checks to see if this part contains the PartModule with the name given. If it does, this returns true, else it returns false. (If HASMODULE(name) returns false, then this means an attempt to use GETMODULE(name) would fail with an error.)

Part:PARENT
Access: Get only Part

When walking the tree of parts, this is the part that this part is attached to on the way “up” toward the root part.

Part:HASPARENT
Access: Get only Boolean

When walking the tree of parts, this is true as long as there is a parent part to this part, and is false if this part has no parent (which can only happen on the root part).

Part:DECOUPLER
Access: Get only Decoupler or String

The decoupler/separator that will decouple this part when activated. None if no such exists.

Part:SEPARATOR
Access: Get only Decoupler or String

Alias name for DECOUPLER

Part:DECOUPLEDIN
Access: Get only Scalar

The stage number where this part will get decoupled. -1 if cannot be decoupled.

Part:SEPARATEDIN
Access: Get only Scalar

Alias name for DECOUPLEDIN

Part:HASPHYSICS
Access: Get only bool

This comes from a part’s configuration and is an artifact of the KSP simulation.

For a list of stock parts that have this attribute and a fuller explanation see the KSP wiki page about massless parts.

Part:CHILDREN
Access: Get only List of Parts

When walking the tree of parts, this is all the parts that are attached as children of this part. It returns a list of zero length when this part is a “leaf” of the parts tree.