Skip to content

PluginEdit

Type

PluginEdit modifies the edit place inside an operator's Execute via ctx.Edit. World edits form one undo step and roll back if Execute returns false or errors; Select and SetCamera apply after Execute succeeds, outside the undo step.

Create

Method
Create(class: string, props: {[string]: any}?, parent: Entity?) -> Entity

Create takes (class, props, parent), adds a new entity of class under parent (or the place root when nil), and returns it. In props, Frame copies the world pose of an entity.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.add_marker",
    Label = "Add Marker",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        edit:Create("Part", { Name = "Marker", Position = ctx.Camera.Pivot })
        return true
    end,
})

Copy

Method
Copy(inst: Entity, props: {[string]: any}?) -> Entity

Copy duplicates inst under the same parent without children, scripts, decals, attachments, or welds, and returns the copy.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.stack",
    Label = "Stack Copy",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        local part = ctx.Selection[1]
        if part then
            local pos, size = part.Position, part.Size
            if pos and size then
                edit:Copy(part, { Position = pos + Vector3.new(0, size.Y, 0) })
            end
        end
        return true
    end,
})

Set

Method
Set(inst: Entity, name: string, value: any) -> ()

Set assigns inst[name] = value, moving descendants and welded parts on pose changes the same way Studio does.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.anchor",
    Label = "Anchor Selected",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        for _, part in ctx.Selection do
            edit:Set(part, "Anchored", true)
        end
        return true
    end,
})

Reshape

Method
Reshape(part: Entity, size: vector, position: vector) -> ()

Reshape sets part's size and world center while keeping children and welded parts at their world poses.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.slab",
    Label = "Make Slab",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        for _, part in ctx.Selection do
            local size, pos = part.Size, part.Position
            if size and pos then
                edit:Reshape(part, Vector3.new(size.X, 1, size.Z), pos)
            end
        end
        return true
    end,
})

AddAccessory

Method
AddAccessory(character: Entity, assetId: string, sha256: string?) -> (Entity?, string?)

AddAccessory takes (character, assetId, sha256?), loads the remote accessory scene named by assetId (verifying sha256 when given), and attaches it to the matching socket on character. It returns the accessory root, or nil and an error string when the asset cannot be loaded or attached.

Example

-- Plugin script (plugins/luduvo_tools/init.luau).
plugin:Operator({
    Id = "luduvo.wear_hat",
    Label = "Wear Hat",
    Params = {
        { Name = "Character", Type = "instance", Hidden = true, From = "Selection" },
        { Name = "Asset", Type = "string", Label = "Accessory asset ID" },
    },
    Execute = function(ctx: PluginContext, params)
        local edit = ctx.Edit :: PluginEdit
        local character = params.Character :: Entity
        local worn, err = edit:AddAccessory(character, params.Asset :: string)
        if not worn then
            return false, err
        end
        return true
    end,
})

SetParent

Method
SetParent(inst: Entity, parent: Entity?) -> ()

SetParent moves inst under parent (or the place root when nil) while preserving its world transform.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.group",
    Label = "Group Selection",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        local folder = edit:Create("Folder", { Name = "Group" })
        for _, inst in ctx.Selection do
            edit:SetParent(inst, folder)
        end
        return true
    end,
})

Destroy

Method
Destroy(inst: Entity) -> ()

Destroy removes inst and its descendants from the place.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.delete_selected",
    Label = "Delete Selected",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        for _, inst in ctx.Selection do
            edit:Destroy(inst)
        end
        return true
    end,
})

Select

Method
Select(list: {Entity}) -> ()

Select sets Studio's selection (up to 4,096 entities) when Execute succeeds.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.create_and_select",
    Label = "New Block",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        local block = edit:Create("Part", { Position = ctx.Camera.Pivot })
        edit:Select({ block })
        return true
    end,
})

SetCamera

Method
SetCamera(position: vector, yaw: number, pitch: number, distance: number?) -> ()

SetCamera takes (position, yaw, pitch, distance) (with yaw and pitch in degrees) and moves Studio's edit camera when Execute succeeds. Passing distance focuses an orbit pivot that many units ahead of position.

Example

-- Plugin script (plugins/build/init.luau).
plugin:Operator({
    Id = "build.view_origin",
    Label = "View Origin",
    Execute = function(ctx: PluginContext)
        local edit = ctx.Edit :: PluginEdit
        edit:SetCamera(Vector3.new(0, 12, 24), 0, -25, 24)
        return true
    end,
})