Skip to content

mxcad_2d API 文档 / 2d / MxCADWorldDraw

Class: MxCADWorldDraw

2d.MxCADWorldDraw

MxCAD 的绘图上下文,用于在自定义实体的 worldDraw 阶段执行图形渲染与图层设置。

Description

该类封装了底层绘图设备的调用入口,提供了 drawEntity、drawOsnapEntity、set trueColor、set lineWeight 等能力, 用于在 AutoCAD 中进行自定义图形的显示、捕捉和样式控制。 常见用途包括:

  • 绘制多段线、圆、文字等实体;
  • 设置当前颜色、线型、线宽和图层;
  • 根据自定义实体的几何数据进行重绘;
  • 处理对象的捕捉和显示效果。

使用方式:

  1. 在自定义实体的 worldDraw(draw: MxCADWorldDraw) 方法中获取当前绘图上下文;
  2. 调用 drawEntity() 或 drawOsnapEntity() 绘制实体;
  3. 通过 trueColor、layerId、lineTypeScale 等属性设置渲染状态;
  4. 在需要时使用 getDatabase() 获取当前数据库环境。

总结:MxCADWorldDraw 是自定义实体渲染的核心入口,开发者通常在 worldDraw 中使用它来将对象真正显示在 CAD 界面中。

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)

构造函数

Parameters

NameTypeDescription
lPtrWorldDrawnumber传递指向绘图设备的指针

Properties

imp

imp: any

内部对象实现

Accessors

layerId

get layerId(): McObjectId

Returns

McObjectId

set layerId(val): void

设置或获取当前使用的图层

Parameters

NameTypeDescription
valMcObjectId图层id

Returns

void


lineTypeId

get lineTypeId(): McObjectId

Returns

McObjectId

set lineTypeId(val): void

设置或获取当前使用的线型id

Parameters

NameTypeDescription
valMcObjectId线型id

Returns

void


lineTypeScale

get lineTypeScale(): number

Returns

number

set lineTypeScale(val): void

设置或获取当前使用的线型比例

Parameters

NameTypeDescription
valnumber线型比例

Returns

void


lineWeight

get lineWeight(): LineWeight

Returns

LineWeight

set lineWeight(val): void

设置或获取当前使用的线重

Parameters

NameTypeDescription
valLineWeight使用的线重

Returns

void


trueColor

get trueColor(): McCmColor

Returns

McCmColor

set trueColor(val): void

设置或获取颜色

Parameters

NameTypeDescription
valMcCmColor颜色对象(McCmColor)

Returns

void

Methods

drawEntity

drawEntity(entity): void

绘制实例对象

Parameters

NameType
entityMcDbEntity

Returns

void


drawOsnapEntity

drawOsnapEntity(entity): void

绘制一个用于捕捉使用的对象.

Parameters

NameType
entityMcDbEntity

Returns

void


getDatabase

getDatabase(): McDbDatabase

返回worddraw当前绘制的数据库。

Returns

McDbDatabase


getType

getType(): MxCADWorldDrawType

得到worddraw type

Returns

MxCADWorldDrawType


initType

initType(type): void

初始化worddraw type

Parameters

NameType
typeMxCADWorldDrawType

Returns

void


setupForEntity

setupForEntity(entity): boolean

使Draw对象使用使用entity的属性

Parameters

NameType
entityMcDbEntity

Returns

boolean