Skip to content
On this page

mxcad_2d API 文档 / 2d / McDbPolyline

Class: McDbPolyline

2d.McDbPolyline

多段线类

Example

ts
import { McDbPolyline, MxCpp } from 'mxcad'
//绘制线宽为10的矩形,pt1,pt2,pt3,pt4为矩形的4点个顶点
const pl = new McDbPolyline();
pl.constantWidth = 10;// 设置多段线线宽为10
// 设置多段线端点
pl.addVertexAt(pt1);
pl.addVertexAt(pt2);
pl.addVertexAt(pt3);
pl.addVertexAt(pt4);
pl.isClosed = true; // 设置多段线是否闭合
MxCpp.getCurrentMxCAD().drawEntity(pl); // 绘制多段线
ts
// 绘制中心矩形:指定矩形宽高与中心点,动态绘制矩形
 import { McDbPolyline, MxCpp, MxCADUiPrDist, MxCADUiPrPoint } from 'mxcad';

 async function Mx_CenterRect() {
   // 设置矩形宽度
   let width = 5;
   const getWidth = new MxCADUiPrDist();
   getWidth.setMessage("\n请输入矩形宽度<5>");
   const widthVal = await getWidth.go();
   if (widthVal) {
       width = getWidth.value()
   }
   // 设置矩形高度
   let height = 10;
   const getHeight = new MxCADUiPrDist();
   getHeight.setMessage("\n请输入矩形高度<10>");
   const heightVal = await getHeight.go();
   if (heightVal) {
       height = getHeight.value()
   }
   // 设置矩形的中心点
   const getCenterPt = new MxCADUiPrPoint();
   getCenterPt.setMessage("请点击确定矩形中心");
   const centerPt = await getCenterPt.go();
   if (!centerPt) return;
   // 根据矩形的中心点和宽高计算矩形的四个顶点
   let pt1 = new McGePoint3d(centerPt.x + width / 2, centerPt.y + height / 2, centerPt.z)
   let pt2 = new McGePoint3d(centerPt.x - width / 2, centerPt.y + height / 2, centerPt.z)
   let pt3 = new McGePoint3d(centerPt.x - width / 2, centerPt.y - height / 2, centerPt.z)
   let pt4 = new McGePoint3d(centerPt.x + width / 2, centerPt.y - height / 2, centerPt.z)
   let pl = new McDbPolyline;// 构造一个多段线对象
   // 依次添加矩形顶点
   pl.addVertexAt(pt1)
   pl.addVertexAt(pt2)
   pl.addVertexAt(pt3)
   pl.addVertexAt(pt4)
   const mxcad = MxCpp.App.getCurrentMxCAD();
   pl.isClosed = true; // 设置多段线闭合
   mxcad.drawEntity(pl); // 绘制多段线对象
 }

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new McDbPolyline(imp?)

构造函数

Example

ts
import { McDbPolyline } from "mxcad";
const pl = new McDbPolyline();

Parameters

NameTypeDescription
imp?any实现对象

Overrides

McDbCurve.constructor

Properties

imp

imp: any = 0

内部实现对象。

Inherited from

McDbCurve.imp

Accessors

colorIndex

get colorIndex(): number

得到对象颜色索引

Example

ts
import { McDbEntity, ColorIndexType } from 'mxcad'
 const ent = new McDbEntity();
 ent.colorIndex = ColorIndexType.kByblock;
 console.log(ent.colorIndex)

Returns

number

Inherited from

McDbCurve.colorIndex

set colorIndex(val): void

设置对象颜色索引

Parameters

NameTypeDescription
valnumber颜色索引(ColorIndexType)

Returns

void

Inherited from

McDbCurve.colorIndex


constantWidth

get constantWidth(): number

获取常量宽度

Example

ts
// pl 为有效多段线对象
const width = pl.constantWidth;

Returns

number

set constantWidth(val): void

设置常量宽度

Example

ts
import { McDbPolyline } from "mxcad";

const pl = new McDbPolyline();
pl.constantWidth = 10;//设置多线段常量宽度为10

Parameters

NameTypeDescription
valnumber常量宽度

Returns

void


drawOrder

get drawOrder(): number

对象的显示顺序

Example

ts
// 假设ent为有效实例对象
const order = ent.drawOrder();

Returns

number

Inherited from

McDbCurve.drawOrder

set drawOrder(order): void

对象的显示顺序

Example

ts
import { MxCpp, MxCADSelectionSet } from "mxcad";

let ss = new MxCADSelectionSet();
if (!await ss.userSelect("\n选择对象")) return;
//得到当前图上对象的最大,小最显示顺序.
let minmaxOrder = MxCpp.getCurrentDatabase().currentSpace.getMinMaxDrawOrder();
// 把对象放到最上面。
let lOrder = minmaxOrder.maxDrawOrder + 1;
ss.forEach((id) => {
  let ent = id.getMcDbEntity();
  if (ent) {
    ent.drawOrder = lOrder;
  }
})

Parameters

NameTypeDescription
ordernumber顺序值

Returns

void

Inherited from

McDbCurve.drawOrder


dxf0

get dxf0(): string

得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。

Returns

string

Inherited from

McDbCurve.dxf0


isClosed

get isClosed(): boolean

获取是否闭合

Example

ts
import { McDbPolyline } from "mxcad";
const pl = new McDbPolyline();
pl.isClosed = true;//设置多线段闭合 
const res = pl.isClosed;
console.log(res)//true

Returns

boolean

set isClosed(val): void

设置是否闭合

Example

ts
import { McDbPolyline } from "mxcad";

const pl = new McDbPolyline();
pl.isClosed = true;//设置多线段闭合

Parameters

NameTypeDescription
valboolean是否闭合

Returns

void


layer

get layer(): string

得到对象图层名

Returns

string

Inherited from

McDbCurve.layer

set layer(val): void

设置对象图层名

Example

ts
import { McDbEntity } from 'mxcad'
 const ent = new McDbEntity();
 ent.layer = "newLayerName";
 console.log(ent.layer)

Parameters

NameTypeDescription
valstring图层名

Returns

void

Inherited from

McDbCurve.layer


layerId

get layerId(): McObjectId

获取图层ID对象

Example

ts
// 假设ent为有效实例对象
const layerId = ent.layerId;

Returns

McObjectId

Inherited from

McDbCurve.layerId

set layerId(id): void

设置图层Id对象

Example

ts
// 假设ent为有效实例对象
const mxcad = MxCpp.getCurrentMxCAD();
const layerId = mxcad.addLayer("测试图层")
ent.layerId = layerId;

Parameters

NameType
idMcObjectId

Returns

void

Inherited from

McDbCurve.layerId


linetype

get linetype(): string

得到对象线型名

Returns

string

Inherited from

McDbCurve.linetype

set linetype(val): void

设置对象线型名

Example

ts
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.linetype = "MyLineType";
console.log(ent.linetype)

Parameters

NameTypeDescription
valstring线型名

Returns

void

Inherited from

McDbCurve.linetype


linetypeId

get linetypeId(): McObjectId

获取实体对象线型ID

Example

ts
// 假设ent为有效实例对象
const linetypeId = ent.linetypeId;

Returns

McObjectId

Inherited from

McDbCurve.linetypeId

set linetypeId(id): void

设置实体对象线型ID

Example

ts
// 假设ent为有效实例对象
const mxcad = MxCpp.getCurrentMxCAD();
const lineId = mxcad.addLinetypeEx("TestMyLine", '25,-5');
ent.linetypeId = lineId;

Parameters

NameType
idMcObjectId

Returns

void

Inherited from

McDbCurve.linetypeId


linetypeScale

get linetypeScale(): number

得到对象线型比例

Returns

number

Inherited from

McDbCurve.linetypeScale

set linetypeScale(val): void

设置对象线型比例

Example

ts
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.linetypeScale = 0.8;
console.log(ent.linetypeScale)

Parameters

NameTypeDescription
valnumber线型比例

Returns

void

Inherited from

McDbCurve.linetypeScale


lineweight

get lineweight(): number

得到对象线重

Returns

number

Inherited from

McDbCurve.lineweight

set lineweight(val): void

设置对象线重

Example

ts
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.lineweight = 20;
console.log(ent.lineweight)

Parameters

NameTypeDescription
valnumber线重

Returns

void

Inherited from

McDbCurve.lineweight


normal

get normal(): McGeVector3d

返回对象的normal

Example

ts

Returns

McGeVector3d

Inherited from

McDbCurve.normal

set normal(val): void

设置对象的normal

Example

ts

Parameters

NameType
valMcGeVector3d

Returns

void

Inherited from

McDbCurve.normal


objectName

get objectName(): string

获取对象名称。

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
console.log(obj.objectName);

Returns

string

返回对象名

Inherited from

McDbCurve.objectName


textStyle

get textStyle(): string

得到对象文字样式

Returns

string

Inherited from

McDbCurve.textStyle

set textStyle(val): void

设置对象文字样式

Example

ts
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.textStyle = "st_style";

Parameters

NameTypeDescription
valstring文字样式名

Returns

void

Inherited from

McDbCurve.textStyle


textStyleId

get textStyleId(): McObjectId

获取实体文字样式

Example

ts
// 假设ent为有效实例对象
const textStyleId = ent.textStyleId;

Returns

McObjectId

Inherited from

McDbCurve.textStyleId

set textStyleId(id): void

设置实体的文字样式

Example

ts
// 假设ent为有效实例对象
const mxcad = MxCpp.getCurrentMxCAD();
const textStyleId = mxcad.addTextStyle("MyLineTypeTextStyle", "txt.shx", "hztxt.shx", 1);
ent.textStyleId = textStyleId;

Parameters

NameType
idMcObjectId

Returns

void

Inherited from

McDbCurve.textStyleId


trueColor

get trueColor(): McCmColor

得到对象颜色

Example

ts
import { McDbEntity, McCmColor} from 'mxcad'
 const ent = new McDbEntity();
 ent.trueColor = new McCmColor(255, 0, 0);
 console.log(ent.trueColor)

Returns

McCmColor

Inherited from

McDbCurve.trueColor

set trueColor(val): void

设置对象颜色

Parameters

NameType
valMcCmColor

Returns

void

Inherited from

McDbCurve.trueColor


visible

get visible(): boolean

对象是否可见

Returns

boolean

Inherited from

McDbCurve.visible

set visible(val): void

设置是否可见

Example

ts
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.visible = true;
console.log(ent.visible)

Parameters

NameTypeDescription
valboolean布尔值

Returns

void

Inherited from

McDbCurve.visible

Methods

IntersectWith

IntersectWith(intersectObject, exOption): McGePoint3dArray

与其他实体相交, 得到交点

Example

ts
import { McDbLine, McDb } from 'mxcad'
const line1 = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
const line2 = new McDbLine(new McGePoint3d(10,10,0), new McGePoint3d(11,1,0));
const ptArr = line1.IntersectWith(line2, McDb.Intersect.kExtendBoth)

Parameters

NameTypeDescription
intersectObjectMcDbEntity需要相交的是实体对象
exOptionIntersect相交的选项

Returns

McGePoint3dArray

得到所有交点

Inherited from

McDbCurve.IntersectWith


addVertexAt

addVertexAt(pt, bulge?, startWidth?, endWidth?, index?): boolean

在指定位置添加顶点

Example

ts
import { McDbPolyline, MxCpp } from "mxcad";

const pl = new McDbPolyline();
pl.isClosed = true;
pl.addVertexAt(new McGePoint3d(800, 300, 0),0,10,10);
pl.addVertexAt(new McGePoint3d(900, 300, 0),0,10,10);
pl.addVertexAt(new McGePoint3d(900, 400, 0),0,10,10);
MxCpp.getCurrentMxCAD().drawEntity(pl);

Parameters

NameTypeDefault valueDescription
ptVector3 | McGePoint3dundefined
bulgenumber0凸度
startWidthnumber0起始宽度
endWidthnumber0结束宽度
indexnumber0位置

Returns

boolean


assertObjectModification

assertObjectModification(autoUndo?): number

设置对象被改变的状态,可自动触发更新显示函数,更新显示。 比如块表记录更新了,需要通知块引用更新显示,可以调用该函数。

Example

ts
//假设obj为一个数据库对象
obj.assertObjectModification()

Parameters

NameTypeDefault value
autoUndobooleanfalse

Returns

number

Inherited from

McDbCurve.assertObjectModification


clone

clone(): null | McDbObject

克隆对象。

Example

ts
//假设obj为一个数据库对象
const obj_clone = obj.clone();

Returns

null | McDbObject

克隆出的对象。

Inherited from

McDbCurve.clone


createExtensionDictionary

createExtensionDictionary(): boolean

创建对象的扩展字典数据.

Example

ts
//假设obj为一个数据库对象
const res = obj.createExtensionDictionary();

Returns

boolean

Inherited from

McDbCurve.createExtensionDictionary


deleteXData

deleteXData(appName): boolean

删除实体指定应用程序名称相关的数据

Example

ts
import { MxCADUiPrEntity, McDbEntity } from "mxcad";

let selEntity = new MxCADUiPrEntity();
selEntity.setMessage("选择对象");
let id = await selEntity.go();
if (!id.isValid()) return;
let ent:McDbEntity = id.getMcDbEntity();
if (ent === null) return;
const res = ent.deleteXData("DataName");
if(res){
  //删除成功
}else
  //删除失败
}

Parameters

NameTypeDescription
appNamestring扩展数据名称

Returns

boolean

Inherited from

McDbCurve.deleteXData


disableDisplay

disableDisplay(isDisable): void

禁用对象的自动更新显示.

Example

ts
import { McDbLine } from 'mxcad'
const line1 = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
line1.disableDisplay(true)

Parameters

NameTypeDescription
isDisableboolean是否禁用对象自动更新显示

Returns

void

Inherited from

McDbCurve.disableDisplay


erase

erase(): boolean

删除对象。

Example

ts
//假设obj为一个数据库对象
const res = obj.erase();
console.log(res);

Returns

boolean

是否删除成功。

Inherited from

McDbCurve.erase


explode

explode(): MxCADResbuf

打碎对象,返回打后对象数据链表

Example

ts
import { McDbEntity, MxCADResbuf } from "mxcad";
// 获取目标对象
let getEnt = new MxCADUiPrEntity();
getEnt.setMessage("选择打碎对象:");
let id = await getEnt.go();
let ent:McDbEntity = id.getMcDbEntity();
if (ent === null) return;
// 打碎对象
let retExplode: MxCADResbuf = ent.explode();

Returns

MxCADResbuf

resbuf 数据

Inherited from

McDbCurve.explode


getAllAppName

getAllAppName(): McGeStringArray

获取实体中包含的所有 XData 记录的应用程序名(AppName)

Example

ts
// 假设ent为有效实例对象
const appNames = ent.getAllAppName();
console.log(appNames);

Returns

McGeStringArray

Inherited from

McDbCurve.getAllAppName


getArea

getArea(): Object

计算面积

Example

ts
import { McGePoint3d, McDbCircle } from "mxcad"

const center = new McGePoint3d(0,0,0);
const circle = new McDbCircle(center, 20);
const area = circle.getArea();
console.log("圆面积:", area)

Returns

Object

val 面积值 | ret 是否获取成功

NameType
retboolean
valnumber

Inherited from

McDbCurve.getArea


getBoundingBox

getBoundingBox(): Object

得到对象的最小外包

Example

ts
import { McDbText, McGePoint3d } from 'mxcad'
const text = new McDbText();
text.textString = "测试Test";
text.height = 20;
text.position = text.alignmentPoint = new McGePoint3d(0,0,0);
const { minPt, maxPt, ret } = text.getBoundingBox()

Returns

Object

NameType
maxPtMcGePoint3d
minPtMcGePoint3d
retboolean

Inherited from

McDbCurve.getBoundingBox


getBulgeAt

getBulgeAt(index): number

获取指定位置的凸度

Example

ts
// pl 为有效多段线对象
const bulge = pl.getBulgeAt(2);

Parameters

NameTypeDescription
indexnumber位置

Returns

number


getClosestPointTo

getClosestPointTo(givenPnt, isExtend): Object

得到一个点到曲线的最近点

Example

ts
import { McGePoint3d, McDbCircle, MxCADUiPrPoint, MxCpp } from "mxcad"

const center = new McGePoint3d(0,0,0);
const circle = new McDbCircle(center, 20);
const mxcad = MxCpp.getCurrentMxCAD();
mxcad.drawEntity(circle);

const getPoint = new MxCADUiPrPoint();
getPoint.setUserDraw((pt,pw)=>{
  //获取pt到circle上最近的点
  const point = circle.getClosestPointTo(pt);
  console.log(point)
})
const point = await getPoint.go();

Parameters

NameTypeDescription
givenPntMcGePoint3d参考点
isExtendboolean是否延展实体

Returns

Object

点对象及执行结果。

NameType
retboolean
valMcGePoint3d

Inherited from

McDbCurve.getClosestPointTo


getDatabase

getDatabase(): McDbDatabase

得到对象所在的数据库

Example

ts
//假设obj为一个数据库对象
const data = obj.getDatabase();

Returns

McDbDatabase

返回数据库

Inherited from

McDbCurve.getDatabase


getDatabaseIndexId

getDatabaseIndexId(): number

获取对象的索引ID

Example

ts
//假设obj为一个数据库对象
const id = obj.getDatabaseIndexId();

Returns

number

Inherited from

McDbCurve.getDatabaseIndexId


getDistAtParam

getDistAtParam(param): Object

获取参数位置上的距离。

Example

ts
// 假设curve为有效曲线实例对象
const res = curve.getDistAtParam(2);
if(res.ret){
  console.log(res.val)
}

Parameters

NameTypeDescription
paramnumber参数位置。

Returns

Object

距离及执行结果。

NameType
retboolean
valnumber

Inherited from

McDbCurve.getDistAtParam


getDistAtPoint

getDistAtPoint(pt): Object

获取曲线上点的距离位置。

Example

ts
import { McGePoint3d, McDbLine } from "mxcad"

const pt1 = new McGePoint3d(0,0,0);
const pt2 = new McGePoint3d(20,0,0);
const line = new McDbLine(pt1, pt2)
const res = line.getDistAtPoint(pt2);
if(res.ret){
  const dist = res.val;
  console.log(dist);//20
}

Parameters

NameTypeDescription
ptMcGePoint3d距离位置。

Returns

Object

点及执行结果。

NameType
retboolean
valnumber

Inherited from

McDbCurve.getDistAtPoint


getEndParam

getEndParam(): Object

获取结束参数。

Example

ts
// 假设curve为有效曲线实例对象
const endPa = curve.getEndParam();
if(endPa.ret){
  console.log(endPa.val)
}

Returns

Object

结束参数及执行结果。

NameType
retboolean
valnumber

Inherited from

McDbCurve.getEndParam


getEndPoint

getEndPoint(): Object

得到曲线的结束点

Example

ts
import { McGePoint3d, McDbLine } from "mxcad"

const pt1 = new McGePoint3d(0,0,0);
const pt2 = new McGePoint3d(20,0,0);
const line = new McDbLine(pt1, pt2)
const res = line.getEndPoint();
if(res.ret){
  const point = res.val;
  console.log(point);//(20, 0, 0)
}

Returns

Object

曲线的结束点及执行结果。

NameType
retboolean
valMcGePoint3d

Inherited from

McDbCurve.getEndPoint


getExtensionDictionary

getExtensionDictionary(): McDbDictionary

得到对象的扩展字典数据.

Example

ts
//假设obj为一个数据库对象
const id = obj.getOwnerID();

Returns

McDbDictionary

扩展字典数据

Inherited from

McDbCurve.getExtensionDictionary


getFirstDeriv

getFirstDeriv(pt): Object

通过曲线上某点得到曲线的一阶导数

Example

ts
import { McGePoint3d, McDbCircle } from "mxcad"

const center = new McGePoint3d(0,0,0);
const circle = new McDbCircle(center, 20);
const vec = circle.getFirstDeriv(new McGePoint3d(20,0,0));//目标点切向量
if(vec.ret){
 const val = vec.val;
}

Parameters

NameTypeDescription
ptMcGePoint3d曲线上的点

Returns

Object

曲线一阶导数及执行结果。

NameType
retboolean
valMcGeVector3d

Inherited from

McDbCurve.getFirstDeriv


getFirstDerivFromParam

getFirstDerivFromParam(param): Object

通过曲线参数得到曲线的一阶导数

Example

ts
// 假设curve为有效曲线实例对象
const res = curve.getFirstDerivFromParam(5);
if(res.ret){
  console.log(res.val)
}

Parameters

NameTypeDescription
paramnumber曲线参数

Returns

Object

曲线一阶导数及执行结果。

NameType
retboolean
valMcGeVector3d

Inherited from

McDbCurve.getFirstDerivFromParam


getGripPoints

getGripPoints(): McGePoint3dArray

获取对象的控制点

Example

ts
//假设obj为一个数据库对象
const ptArr = obj.getGripPoints();

Returns

McGePoint3dArray

Inherited from

McDbCurve.getGripPoints


getHandle

getHandle(): string

得到对象句柄

Example

ts
//假设obj为一个数据库对象
const handle = obj.getHandle();

Returns

string

返回对象句柄

Inherited from

McDbCurve.getHandle


getImp

getImp(): any

获取内部实现对象。

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let imp = obj.getImp();

Returns

any

内部实现对象。

Inherited from

McDbCurve.getImp


getJson

getJson(): string

获取 JSON 格式的字符串。

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
const json = obj.getJson()

Returns

string

JSON 格式的字符串。

Inherited from

McDbCurve.getJson


getLength

getLength(): Object

得到曲线长度

Example

ts
import { MxCpp, MxCADResbuf, MxCADUtility, MxCADUiPrPoint} from "mxcad"

 const mxcad = MxCpp.App.getCurrentMxCAD();
   let filter = new MxCADResbuf();
   filter.AddMcDbEntityTypes("CIRCLE,ARC,LINE,LWPOLYLINE,ELLIPSE");
   let aryId = await MxCADUtility.userSelect("选择目标曲线", filter);
   if (aryId.length == 0)  return;
   aryId.forEach(async (id) => {
       let event = id.getMcDbEntity() as McDbCurve;
       let length = event.getLength().val;
       console.log(length)
   });

Returns

Object

NameType
retboolean
valnumber

Inherited from

McDbCurve.getLength


getObjectID

getObjectID(): McObjectId

获取对象 ID。

Example

ts
import { McDbObject } from "mxcad";
const id = obj.getObjectID();

Returns

McObjectId

对象 ID。

Inherited from

McDbCurve.getObjectID


getOwnerID

getOwnerID(): number

得到对象拥用者的id

Example

ts
//假设obj为一个数据库对象
const id = obj.getOwnerID();

Returns

number

Inherited from

McDbCurve.getOwnerID


getParamAtDist

getParamAtDist(dist): Object

获取距离位置上的参数。

Example

ts
// 假设curve为有效曲线实例对象
const res = curve.getParamAtDist(0);
if(res.ret){
  console.log(res.val)
}

Parameters

NameTypeDescription
distnumber距离位置。

Returns

Object

参数及执行结果。

NameType
retboolean
valnumber

Inherited from

McDbCurve.getParamAtDist


getParamAtPoint

getParamAtPoint(pt): Object

得到曲线某点位置的曲线参数

Example

ts
import { McGePoint3d, McDbLine } from "mxcad"

const pt1 = new McGePoint3d(0,0,0);
const pt2 = new McGePoint3d(20,0,0);
const line = new McDbLine(pt1, pt2)
const res = line.getParamAtPoint(pt1);
if(res.ret){
  const val = res.val;
  console.log(val);
}

Parameters

NameTypeDescription
ptMcGePoint3d曲线上的点

Returns

Object

曲线参数及执行结果。

NameType
retboolean
valnumber

Inherited from

McDbCurve.getParamAtPoint


getPointAt

getPointAt(index): Object

获取指定位置的点

Example

ts
// pl 为有效多段线对象
const res = pl.getPointAt(2);
const point = res.val;

Parameters

NameTypeDescription
indexnumber位置

Returns

Object

val: 点, ret: 返回值

NameType
retnumber
valMcGePoint3d

getPointAtDist

getPointAtDist(dist): Object

获取距离位置上的点。

Example

ts
import { McGePoint3d, McDbLine } from "mxcad"

const pt1 = new McGePoint3d(0,0,0);
const pt2 = new McGePoint3d(20,0,0);
const line = new McDbLine(pt1, pt2)
const res = line.getPointAtDist(10);
if(res.ret){
  const point = res.val;
  console.log(point);//(10, 0, 0)
}

Parameters

NameTypeDescription
distnumber距离位置。

Returns

Object

点及执行结果。

NameType
retboolean
valMcGePoint3d

Inherited from

McDbCurve.getPointAtDist


getPointAtParam

getPointAtParam(param): Object

得到曲线参数所在的点坐标

Example

ts
// 假设curve为有效曲线实例对象
const res = curve.getPointAtParam(5);
if(res.ret){
  console.log(res.val)
}

Parameters

NameTypeDescription
paramnumber曲线参数

Returns

Object

点对象及执行结果。

NameType
retboolean
valMcGePoint3d

Inherited from

McDbCurve.getPointAtParam


getSamplePoints

getSamplePoints(dApproxEps): MxCADResbuf

把曲线离散成一堆点

Example

ts
import { McGePoint3d, McDbLine } from "mxcad"

const pt1 = new McGePoint3d(0,0,0);
const pt2 = new McGePoint3d(20,0,0);
const line = new McDbLine(pt1, pt2);
const resBuf = line.getSamplePoints(0.1);

Parameters

NameTypeDescription
dApproxEpsnumber采样间隔

Returns

MxCADResbuf

resbuf 数据

Inherited from

McDbCurve.getSamplePoints


getStartParam

getStartParam(): Object

获取起始参数。

Example

ts
// 假设curve为有效曲线实例对象
const startPa = curve.getStartParam();
if(startPa.ret){
  console.log(startPa.val)
}

Returns

Object

起始参数及执行结果。

NameType
retboolean
valnumber

Inherited from

McDbCurve.getStartParam


getStartPoint

getStartPoint(): Object

得到曲线的开始点

Example

ts
import { McGePoint3d, McDbLine } from "mxcad"

const pt1 = new McGePoint3d(0,0,0);
const pt2 = new McGePoint3d(20,0,0);
const line = new McDbLine(pt1, pt2)
const res = line.getStartPoint();
if(res.ret){
  const point = res.val;
  console.log(point);//(0, 0, 0)
}

Returns

Object

曲线的开始点及执行结果。

NameType
retboolean
valMcGePoint3d

Inherited from

McDbCurve.getStartPoint


getType

getType(): PolylineType

设置多线段类型

Example

ts
// pl 为有效多段线对象
const type = pl.getType();

Returns

PolylineType


getWidthsAt

getWidthsAt(index): Object

获取指定位置的起始和结束宽度

Example

ts
// pl 为有效多段线对象
const width = pl.getWidthsAt(2);
if(width.ret){
  const startWidth = width.val1;
  const endWidth = width.val2
}else{
  //获取失败
}

Parameters

NameTypeDescription
indexnumber位置

Returns

Object

val1: 起始宽度, val2: 结束宽度, ret: 返回值

NameType
retboolean
val1number
val2number

getxData

getxData(appName?): MxCADResbuf

得到对象的扩展数据

Example

ts
// 假设ent为有效实例对象
const xData = ent.getXData();

Parameters

NameTypeDefault valueDescription
appNamestring""扩展数据名

Returns

MxCADResbuf

Inherited from

McDbCurve.getxData


getxDataDouble

getxDataDouble(appName): Object

获取实体的指定 XData 类型中的 double 值

Example

ts
// 假设ent为有效实例对象
let data = ent.getxDataDouble("DataName");
if(data.ret){
  console.log(data.val)
}

Parameters

NameTypeDescription
appNamestring扩展数据名称

Returns

Object

double 值

NameType
retboolean
valnumber

Inherited from

McDbCurve.getxDataDouble


getxDataLong

getxDataLong(appName): Object

获取实体的指定 XData 类型中的 long(整数)值

Example

ts
// 假设ent为有效实例对象
let data = ent.getxDataLong("DataName");
if(data.ret){
  console.log(data.val)
}

Parameters

NameTypeDescription
appNamestring扩展数据名称

Returns

Object

long 值

NameType
retboolean
valnumber

Inherited from

McDbCurve.getxDataLong


getxDataPoint

getxDataPoint(appName): Object

获取实体的指定 XData 类型中的点对象

Parameters

NameTypeDescription
appNamestring扩展数据名称

Returns

Object

获取结果及三维点对象

NameType
retboolean
valMcGePoint3d

Inherited from

McDbCurve.getxDataPoint


getxDataString

getxDataString(appName): Object

获取与特定实体关联的 XData 信息,并以字符串形式返回

Example

ts
// 假设ent为有效实例对象
let data = ent.getxDataString("DataName");
if(data.ret){
  console.log(data.val)
}

Parameters

NameTypeDescription
appNamestring扩展数据名称

Returns

Object

val XData信息 | ret 是否返回成功

NameType
retboolean
valstring

Inherited from

McDbCurve.getxDataString


highlight

highlight(isHighlight): void

设置对象是否高亮

Example

ts
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.highlight(true);

Parameters

NameTypeDescription
isHighlightboolean是否高亮

Returns

void

Inherited from

McDbCurve.highlight


initTempObject

initTempObject(imp): void

初始化临时对象。

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
obj.initTempObject()

Parameters

NameTypeDescription
impany内部实现对象。

Returns

void

Inherited from

McDbCurve.initTempObject


isErased

isErased(): boolean

对象是否已经删除

Example

ts
//假设obj为一个数据库对象
const res = obj.isErased();
console.log(res);

Returns

boolean

Inherited from

McDbCurve.isErased


isHaveExtensionDictionary

isHaveExtensionDictionary(): boolean

是否有扩展字典数据.

Example

ts
//假设obj为一个数据库对象
const res = obj.isHaveExtensionDictionary();

Returns

boolean

Inherited from

McDbCurve.isHaveExtensionDictionary


isKindOf

isKindOf(sObjectName): boolean

判断对象类型

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false

Parameters

NameTypeDescription
sObjectNamestring类型名

Returns

boolean

返回对象是否是目标类型

Inherited from

McDbCurve.isKindOf


isNull

isNull(): any

判断是否为空对象

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
console.log(obj.isNull()); // 输出: true 或 false

Returns

any

Inherited from

McDbCurve.isNull


mirror

mirror(point1, point2): boolean

镜向对象

Example

ts
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.mirror(new McGePoint3d(0,0,0), new McGePoint3d(20,10,0))

Parameters

NameTypeDescription
point1McGePoint3d镜像基点
point2McGePoint3d-

Returns

boolean

Inherited from

McDbCurve.mirror


move

move(fromPoint, toPoint): boolean

移动对象

Example

ts
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.move(new McGePoint3d(0,0,0), new McGePoint3d(20,0,0))

Parameters

NameTypeDescription
fromPointMcGePoint3d移动开始点
toPointMcGePoint3d移动结束点

Returns

boolean

Inherited from

McDbCurve.move


moveGripPointsAt

moveGripPointsAt(iIndex, dXOffset, dYOffset, dZOffset): any

移动对象的控制点

Example

ts
//假设obj为一个数据库对象
obj.moveGripPointsAt(1,10,10,10);

Parameters

NameTypeDescription
iIndexnumber索引
dXOffsetnumberX轴偏移量
dYOffsetnumberY轴偏移量
dZOffsetnumberZ轴偏移量

Returns

any

Inherited from

McDbCurve.moveGripPointsAt


numVerts

numVerts(): number

获取顶点数量

Example

ts
// pl 为有效多段线对象
const num = pl.numVerts();

Returns

number


offsetCurves

offsetCurves(dOffsetDist, ptOffsetRef): McDbObjectArray

得到偏移曲线

Example

ts
import { MxCADUiPrPoint, MxCpp } from 'mxcad'
   let getFristPoint = new MxCADUiPrPoint();
   let offsetDist = 10 ;
   let getEvent = new MxCADUiPrEntity();
   getEvent.setMessage('指定偏移对象');
   let event_id = await getEvent.go();
   if (!event_id) return;
   let event = (await event_id.getMcDbEntity()) as McDbCurve;
   let getoOffPt = new MxCADUiPrPoint();
   getoOffPt.setMessage('指定偏移点');
   let offPt = await getoOffPt.go();
   if (!offPt) return;
   let objArr = event.offsetCurves(offsetDist, offPt);
   if (objArr.length() === 0) return;
   objArr.forEach((obj: McDbObject) => {
       MxCpp.getCurrentCAD().drawEntity(obj as McDbEntity);
   });

Parameters

NameTypeDescription
dOffsetDistnumber偏移距离
ptOffsetRefMcGePoint3d偏移点

Returns

McDbObjectArray

偏移后的对象数组。

Inherited from

McDbCurve.offsetCurves


removeVertexAt

removeVertexAt(index): boolean

移除指定位置的顶点

Example

ts
// pl 为有效多段线对象
const res = pl.removeVertexAt(2);
if(res){
  //移除成功
}else{
  //移除失败
}

Parameters

NameTypeDescription
indexnumber位置

Returns

boolean


rotate

rotate(basePoint, dRotationAngle): boolean

旋转对象

Example

ts
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.rotate(new McGePoint3d(0,0,0), Math.PI)

Parameters

NameTypeDescription
basePointMcGePoint3d旋转基点
dRotationAnglenumber旋转角度

Returns

boolean

Inherited from

McDbCurve.rotate


scaleEntity

scaleEntity(basePoint, dScaleFactor): boolean

缩放对象

Example

ts
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.scaleEntity(new McGePoint3d(0,0,0), 0.5)

Parameters

NameTypeDescription
basePointMcGePoint3d缩放基点
dScaleFactornumber缩放因子(<1 缩小; >1 放大)

Returns

boolean

Inherited from

McDbCurve.scaleEntity


setBulgeAt

setBulgeAt(index, bulge): boolean

设置指定位置的凸度

Example

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

const pl = new McDbPolyline();
pl.addVertexAt(new McGePoint3d(800, 300, 0));
const res = pl.setBulgeAt(0, 10);
if(res){
  //设置成功
}else{
  //设置失败
}

Parameters

NameTypeDescription
indexnumber位置
bulgenumber凸度

Returns

boolean


setJson

setJson(str): boolean

设置 JSON 格式的字符串。

Example

ts
import { McRxObject } from 'mxcad';

let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)

Parameters

NameTypeDescription
strstringJSON 格式的字符串。

Returns

boolean

是否设置成功。

Inherited from

McDbCurve.setJson


setPointAt

setPointAt(index, pt): boolean

设置指定位置的点

Example

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

const pl = new McDbPolyline();
pl.setPointAt(0,new McGePoint3d(0,0,0));
pl.setPointAt(1,new McGePoint3d(10,10,0));

Parameters

NameTypeDescription
indexnumber位置
ptMcGePoint3d

Returns

boolean


setType

setType(type): boolean

返回多线段类型

Example

ts
// pl 为有效多段线对象
pl.setType(McDb.PolylineType.kLwPolyline);

Parameters

NameTypeDescription
typePolylineType多线段类型

Returns

boolean


setWidthsAt

setWidthsAt(index, dStartWdith, dEntWdith): boolean

修改线段的开始宽度,和结束宽度

Example

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

const pl = new McDbPolyline();
pl.addVertexAt(new McGePoint3d(800, 300, 0));
const res = pl.setWidthsAt(0, 10, 10);
if(res){
  //设置成功
}else{
  //设置失败
}

Parameters

NameTypeDescription
indexnumber位置
dStartWdithnumber-
dEntWdithnumber-

Returns

boolean


setxData

setxData(xdata): boolean

设置对象的扩展数据

Example

ts
import { MxCADUiPrEntity, McDbEntity } from "mxcad";

//设置扩展数据
let selEntity = new MxCADUiPrEntity();
selEntity.setMessage("选择对象");
let id = await selEntity.go();
if (!id.isValid()) return;
let ent:McDbEntity = id.getMcDbEntity();
if (ent === null) return;
ent.setxData(new MxCADResbuf([{type:DxfCode.kExDataName,val:"DataName"},{type:DxfCode.kString,val:"yyyyy"}]));

Parameters

NameTypeDescription
xdataMxCADResbuf扩展数据链表

Returns

boolean

Inherited from

McDbCurve.setxData


setxDataDouble

setxDataDouble(appName, val): boolean

设置实体的指定 XData 类型中的 double 值

Example

ts
import { MxCADUiPrEntity, McDbEntity } from "mxcad";
let selEntity = new MxCADUiPrEntity();
selEntity.setMessage("选择对象");
let id = await selEntity.go();
if (!id.isValid()) return;
let ent:McDbEntity = id.getMcDbEntity();
if (ent === null) return;
const res = ent.setxDataDouble("DataName", 0);
if(res){
  //设置成功
}else{
  //设置失败
}

Parameters

NameTypeDescription
appNamestring扩展数据名称
valnumberdouble 值

Returns

boolean

布尔值

Inherited from

McDbCurve.setxDataDouble


setxDataLong

setxDataLong(appName, val): boolean

设置实体的指定 XData 类型中的 long(整数)值

Example

ts
import { MxCADUiPrEntity, McDbEntity } from "mxcad";

let selEntity = new MxCADUiPrEntity();
selEntity.setMessage("选择对象");
let id = await selEntity.go();
if (!id.isValid()) return;
let ent:McDbEntity = id.getMcDbEntity();
if (ent === null) return;
const res = ent.setxDataLong("DataName", 123456);
if(res){
  //设置成功
}else{
  //设置失败
}

Parameters

NameTypeDescription
appNamestring扩展数据名称
valnumberlong 值

Returns

boolean

long 值

Inherited from

McDbCurve.setxDataLong


setxDataPoint

setxDataPoint(appName, val): boolean

设置实体的指定 XData 类型中的点对象

Parameters

NameTypeDescription
appNamestring扩展数据名称
valMcGePoint3d点对象

Returns

boolean

获取结果及三维点对象

Inherited from

McDbCurve.setxDataPoint


setxDataString

setxDataString(appName, val): boolean

设置与特定实体关联的 XData 信息,并以字符串形式设置

Example

ts
import { MxCADUiPrEntity, McDbEntity } from "mxcad";
let selEntity = new MxCADUiPrEntity();
selEntity.setMessage("选择对象");
let id = await selEntity.go();
if (!id.isValid()) return;
let ent:McDbEntity = id.getMcDbEntity();
if (ent === null) return;
const res = ent.setxDataString("DataName", "xxxxx");
if(res){
  //设置成功
}else{
  //设置失败
}

Parameters

NameTypeDescription
appNamestring扩展数据名称
valstring字符串值

Returns

boolean

是否设置成功

Inherited from

McDbCurve.setxDataString


splitCurves

splitCurves(pts): McDbObjectArray

打断曲线

Example

ts
import { MxCpp } from "mxcad"
// PointsArr:断点数组 event:McDbCurve
   event.splitCurves(PointsArr).forEach((e:McDbCurve, index:number) => {
       if(index % 2 === 0){
           MxCpp.getCurrentCAD().drawEntity(e as McDbEntity)
       }
   })

Parameters

NameTypeDescription
ptsMcGePoint3d[]断点数组

Returns

McDbObjectArray

打断后的曲线数组。

Inherited from

McDbCurve.splitCurves


splitCurvesFromParam

splitCurvesFromParam(params): McDbObjectArray

根据曲线参数打断曲线

Parameters

NameTypeDescription
paramsnumber[]曲线参数数组

Returns

McDbObjectArray

打断后的曲线数组。

Inherited from

McDbCurve.splitCurvesFromParam


syncData

syncData(_toCpp?): boolean

同步实体的数据。这个方法可能是在修改了实体的属性或者附加了新的数据之后调用的,以确保所有的改变都被正确地保存到实体的数据库记录中。

Example

ts
// 假设ent为有效实例对象
const res = ent.syncData(true);
if(res){
  //同步成功
}else{
  //同步失败
}

Parameters

NameTypeDefault valueDescription
_toCppbooleantrue是否同步数据

Returns

boolean

Inherited from

McDbCurve.syncData


transformBy

transformBy(transformationMatrix): boolean

变换对象

Example

ts
import { McGeMatrix3d, McDbEntity, McGeVector3d} from 'mxcad'
 const ent = new McDbEntity()
   let matrix = new McGeMatrix3d();
   matrix.setToTranslation(new McGeVector3d(20,0,0));//平移
   ent.transformBy(matrix);

Parameters

NameTypeDescription
transformationMatrixMcGeMatrix3d变换矩阵

Returns

boolean

Inherited from

McDbCurve.transformBy


unErase

unErase(): boolean

反删除对象。

Example

ts
//假设obj为一个数据库对象
const res = obj.unErase();
console.log(res);

Returns

boolean

Inherited from

McDbCurve.unErase


updateDisplay

updateDisplay(): void

显示调用对象更新显示.

Example

ts
// 假设ent为有效实例对象
ent.updateDisplay()

Returns

void

Inherited from

McDbCurve.updateDisplay