ts-visio - v1.16.27
    Preparing search index...

    Class Shape

    A handle to a single shape on a Visio page.

    Obtain instances via Page.addShape, Page.getShapes, Page.getShapeById, or Page.findShapes.

    const shape = await page.addShape({ text: 'Box', x: 1, y: 1, width: 2, height: 1 });
    await shape.setStyle({ fillColor: '#4472C4', fontColor: '#ffffff', bold: true });
    console.log(shape.id, shape.x, shape.y);
    Index

    Constructors

    • Parameters

      • internalShape: VisioShape
      • pageId: string
      • pkg: VisioPackage
      • Optionalmodifier: ShapeModifier

      Returns Shape

    Accessors

    • get angle(): number

      Current rotation angle in degrees (0 if no Angle cell is set).

      Returns number

    • get height(): number

      Returns number

    • get isGroup(): boolean

      true if this shape is a Group (i.e. it can contain nested child shapes). Use shape.getChildren() to retrieve those children.

      Returns boolean

    • get type(): string

      The shape's Type attribute — 'Group' for group shapes, 'Shape' (or undefined normalised to 'Shape') for regular shapes.

      Returns string

    • get width(): number

      Returns number

    Methods

    • Parameters

      • address: string
      • Optionaldescription: string

      Returns Promise<Shape>

    • Parameters

      • name: string
      • type: number
      • options: { invisible?: boolean; label?: string } = {}

      Returns this

    • Alias for assignLayer. Adds this shape to a layer.

      Parameters

      Returns Promise<Shape>

    • Apply a document-level stylesheet to this shape. Create styles via doc.createStyle() and pass the returned id.

      Parameters

      • styleId: number

        The stylesheet ID to apply.

      • which: "text" | "fill" | "all" | "line" = 'all'

        'all' (default) applies to line, fill, and text; 'line', 'fill', or 'text' applies to only that category.

      Returns this

    • Returns Promise<void>

    • Flip the shape horizontally. Pass false to un-flip.

      Parameters

      • enabled: boolean = true

      Returns Promise<Shape>

    • Flip the shape vertically. Pass false to un-flip.

      Parameters

      • enabled: boolean = true

      Returns Promise<Shape>

    • Return the direct child shapes of this group. Returns an empty array for non-group shapes or groups with no children.

      Only direct children are returned — grandchildren are accessible by calling getChildren() on the child shape.

      Returns Shape[]

      const group = await page.addShape({ text: 'G', x: 5, y: 5, width: 4, height: 4, type: 'Group' });
      await page.addShape({ text: 'Child A', x: 1, y: 1, width: 1, height: 1 }, group.id);
      await page.addShape({ text: 'Child B', x: 2, y: 1, width: 1, height: 1 }, group.id);
      group.getChildren(); // → [Shape('Child A'), Shape('Child B')]
    • Read back the layer indices this shape is assigned to. Returns an empty array if the shape has no layer assignment.

      Returns number[]

    • Read back all custom property (shape data) entries written to this shape. Returns a map of property key → ShapeData. Values are coerced to the declared Visio type (Number, Boolean, Date, or String).

      Returns Record<string, ShapeData>

    • Parameters

      • targetPage: { name: string }
      • Optionaldescription: string

      Returns Promise<Shape>

    • Parameters

      • targetShape: Shape
      • options: { gap: number } = ...

      Returns Promise<Shape>

    • Parameters

      • targetShape: Shape
      • options: { gap: number } = ...

      Returns Promise<Shape>

    • Resize the shape to the given width and height (in inches). Updates LocPinX/LocPinY to keep the centre-pin at width/2, height/2.

      Parameters

      • width: number
      • height: number

      Returns Promise<Shape>

    • Parameters

      • padding: number = 0.25

      Returns Promise<Shape>

    • Rotate the shape to an absolute angle (degrees, clockwise). Replaces any existing rotation.

      Parameters

      • degrees: number

      Returns Promise<Shape>

    • Parameters

      • name: string
      • value: string | number | boolean | Date

      Returns this

    • Parameters

      • newText: string

      Returns Promise<void>

    • Adds an internal link to another page. Shows up in the right-click menu in Visio.

      Parameters

      • targetPage: { name: string }

        The Page object to link to

      • Optionaldescription: string

        Text to show in the menu

      Returns Promise<Shape>

    • Adds an external hyperlink to the shape. Shows up in the right-click menu in Visio.

      Parameters

      • url: string

        External URL (e.g. https://google.com)

      • Optionaldescription: string

        Text to show in the menu

      Returns Promise<Shape>