Skip to content

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/MxCADWorldDraw

Class: MxCADWorldDraw

2d.MxCADWorldDraw

The drawing context of MxCAD is used to perform graphic rendering and layer settings during the worldDraw phase of custom entities.

Description

This class encapsulates the call entry of the underlying drawing device and provides capabilities such as drawEntity, drawOsnapEntity, set trueColor, set lineWeight, etc, Used for display, snap, and style control of custom graphics in AutoCAD. Common uses include: -Draw solid objects such as polylines, circles, and text; -Set the current color, line type, line width, and layer; -Redraw based on the geometric data of custom entities; -Process the capture and display effects of objects.

Usage:

  1. Obtain the current drawing context in the worldDraw (draw: MxCADWorldDraw) method of the custom entity;
  2. Call drawEntity () or drawOsnapEntity () to draw entities;
  3. Set rendering status through properties such as trueColor, layerId, lineTypeScale, etc;
  4. Use getData() to retrieve the current database environment when needed.

Summary: MxCADWorldDraw is the core entry point for custom entity rendering, and developers typically use it in WorldDraw to truly display objects in CAD interfaces.

Example

ts
import { McDbCustomEntity, McDbPolyline, McGePoint3d, MxCADWorldDraw } from "mxcad";

class McDbTestLineCustomEntity extends McDbCustomEntity {
  private pt1: McGePoint3d = new McGePoint3d();
  private pt2: McGePoint3d = new McGePoint3d();

  public create(imp?: any): McDbCustomEntity {
    return new McDbTestLineCustomEntity(imp);
  }

  public getTypeName(): string {
    return "McDbTestLineCustomEntity";
  }

  public dwgInFields(filter: any): boolean { return true; }
  public dwgOutFields(filter: any): boolean { return true; }

  public worldDraw(draw: MxCADWorldDraw): void {
    const pl = new McDbPolyline();
    pl.addVertexAt(this.pt1);
    pl.addVertexAt(this.pt2);
    pl.addVertexAt(new McGePoint3d(0, 10, 0));
    draw.drawEntity(pl);
  }
}

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new MxCADWorldDraw(lPtrWorldDraw)

Constructor function

Parameters

NameTypeDescription
LPtrWorldDrawnumberPass a pointer to the drawing device

Properties

imp

imp: any

Internal object implementation

Accessors

layerId

get layerId(): McObjectId

Returns

McObjectId

set layerId(val): void

Set or retrieve the currently used layer

Parameters

NameTypeDescription
Val[McObjectid] (2d. McObjectid. md)Layer ID

Returns

void


lineTypeId

get lineTypeId(): McObjectId

Returns

McObjectId

set lineTypeId(val): void

Set or retrieve the current line type ID being used

Parameters

NameTypeDescription
Val[McObjectid] (2d. McObjectid. md)Linetype ID

Returns

void


lineTypeScale

get lineTypeScale(): number

Returns

number

set lineTypeScale(val): void

Set or retrieve the current line type scale used

Parameters

NameTypeDescription
ValnumberLine type ratio

Returns

void


lineWeight

get lineWeight(): LineWeight

Returns

LineWeight

set lineWeight(val): void

Set or retrieve the current line weight being used

Parameters

NameTypeDescription
Val[LineWeight] (../enums/2d. McDb. LineWeight. md)Used line weight

Returns

void


trueColor

get trueColor(): McCmColor

Returns

McCmColor

set trueColor(val): void

Set or retrieve colors

Parameters

NameTypeDescription
Val[McCMColor] (2d. McCmColor. md)Color Object (McCMColor)

Returns

void

Methods

drawEntity

drawEntity(entity): void

Draw instance objects

Parameters

NameType
entityMcDbEntity

Returns

void


drawOsnapEntity

drawOsnapEntity(entity): void

Draw an object for capturing and using

Parameters

NameType
entityMcDbEntity

Returns

void


getDatabase

getDatabase(): McDbDatabase

Return the database currently being drawn by worddraw.

Returns

McDbDatabase


getType

getType(): MxCADWorldDrawType

Obtain worddraw type

Returns

MxCADWorldDrawType


initType

initType(type): void

Initialize worddraw type

Parameters

NameType
typeMxCADWorldDrawType

Returns

void


setupForEntity

setupForEntity(entity): boolean

Make Draw objects use entity properties

Parameters

NameType
entityMcDbEntity

Returns

boolean