mxcad_2d API 文档 / 2d / McDbCurve
Class: McDbCurve
2d.McDbCurve
表示数据库曲线。实现了曲线的相关操作,如求曲线的长度,最近点,面积,曲线上任一点在曲线上的长度 切向方向,曲线交点,坐标变换,打断,偏移,离散等功能。
Example
// 下面代码演示了,选择一个曲线,然后选择其它曲线,计算曲线与这个曲线的交点,然后在交点处打断曲线。
import { MxCADUiPrEntity, MxCADResbuf, MxCpp, MxCADUtility, McDbCurve } from "mxcad";
async function Mx_IntersectBreak() {
// 选择参考曲线
let eventObj = new MxCADUiPrEntity();
eventObj.setMessage("请选择参考曲线");
let eventObj_id = await eventObj.go();
let event = await eventObj_id.getMcDbEntity()//获取实例对象
if (event === null) return;
const mxcad = MxCpp.App.getCurrentMxCAD();
let curve = event.clone();// 克隆曲线
let filter = new MxCADResbuf();
//设置过滤器 选中圆类、圆弧类、直线类、多段线类、椭圆类
filter.AddMcDbEntityTypes("CIRCLE,ARC,LINE,LWPOLYLINE,ELLIPSE");
let aryId = await MxCADUtility.userSelect("选择打断对象", filter);//选中对象的id
if (aryId.length == 0) return
// 遍历选中的曲线对象
aryId.forEach(async (id) => {
if (id.id !== eventObj_id.id) {
let breakEvent: McDbCurve = (await id.getMcDbEntity()) as McDbCurve;// 获取打断曲线的实例
let breakArr = breakEvent.IntersectWith(curve as McDbEntity, McDb.Intersect.kOnBothOperands);//与实体相交的点集合
if (breakArr.length() != 0) {
//有交点的对象
let arr: McGePoint3d[] = [];//交点数组
breakArr.forEach((item: McGePoint3d) => {
arr.push(item)
})
let breakPoint: McGePoint3d[] = [];
arr.forEach(pt => {
let closePoint = breakEvent.getClosestPointTo(pt, false);//曲线上离鼠标位置最近的点
if (!closePoint.ret) return;
let vec = breakEvent.getFirstDeriv(closePoint.val);//断点所在位置的向量
if (!vec.ret) return;
vec.val.normalize().mult(MxFun.viewCoordLong2Cad(10));//断开的距离
let pt1 = closePoint.val.clone();
pt1.addvec(vec.val);
let pt2 = closePoint.val.clone();
pt2.subvec(vec.val);
breakPoint.push(pt1);
breakPoint.push(pt2);
});
let breakcurve = breakEvent.splitCurves(breakPoint);// 根据端点截取曲线
if (breakcurve.empty()) {
breakEvent.highlight(false);
return;
}
// 重绘打断后的曲线
breakcurve.forEach((obj: McDbObject, index: number) => {
if (index % 2 == 0) mxcad.drawEntity(obj as McDbEntity);
});
breakEvent.erase() // 删除原曲线
}
}
})
}
Hierarchy
↳
McDbCurve
↳↳
McDbLine
↳↳
McDbCircle
↳↳
McDbPolyline
↳↳
McDbArc
↳↳
McDbEllipse
Table of contents
Constructors
Properties
Accessors
- colorIndex
- drawOrder
- dxf0
- layer
- layerId
- linetype
- linetypeId
- linetypeScale
- lineweight
- normal
- objectName
- textStyle
- textStyleId
- trueColor
- visible
Methods
- IntersectWith
- assertObjectModification
- clone
- createExtensionDictionary
- deleteXData
- disableDisplay
- erase
- explode
- getAllAppName
- getArea
- getBoundingBox
- getClosestPointTo
- getDatabase
- getDatabaseIndexId
- getDistAtParam
- getDistAtPoint
- getEndParam
- getEndPoint
- getExtensionDictionary
- getFirstDeriv
- getFirstDerivFromParam
- getGripPoints
- getHandle
- getImp
- getJson
- getLength
- getObjectID
- getOwnerID
- getParamAtDist
- getParamAtPoint
- getPointAtDist
- getPointAtParam
- getSamplePoints
- getStartParam
- getStartPoint
- getxData
- getxDataDouble
- getxDataLong
- getxDataPoint
- getxDataString
- highlight
- initTempObject
- isErased
- isHaveExtensionDictionary
- isKindOf
- isNull
- mirror
- move
- moveGripPointsAt
- offsetCurves
- rotate
- scaleEntity
- setJson
- setxData
- setxDataDouble
- setxDataLong
- setxDataPoint
- setxDataString
- splitCurves
- splitCurvesFromParam
- syncData
- transformBy
- unErase
- updateDisplay
Constructors
constructor
• new McDbCurve(imp?
)
构造函数。
Parameters
Name | Type | Description |
---|---|---|
imp? | any | 内部实现对象。 |
Example
import { McDbCurve } from "mxcad";
const curve = new McDbCurve();
Overrides
Properties
imp
• imp: any
= 0
内部实现对象。
Inherited from
Accessors
colorIndex
• get
colorIndex(): number
得到对象颜色索引
Returns
number
Example
import { McDbEntity, ColorIndexType } from 'mxcad'
const ent = new McDbEntity();
ent.colorIndex = ColorIndexType.kByblock;
console.log(ent.colorIndex)
Inherited from
McDbEntity.colorIndex
• set
colorIndex(val
): void
设置对象颜色索引
Parameters
Name | Type | Description |
---|---|---|
val | number | 颜色索引(ColorIndexType) |
Returns
void
Inherited from
McDbEntity.colorIndex
drawOrder
• get
drawOrder(): number
对象的显示顺序
Returns
number
Example
// 假设ent为有效实例对象
const order = ent.drawOrder();
Inherited from
McDbEntity.drawOrder
• set
drawOrder(order
): void
对象的显示顺序
Parameters
Name | Type | Description |
---|---|---|
order | number | 顺序值 |
Returns
void
Example
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;
}
})
Inherited from
McDbEntity.drawOrder
dxf0
• get
dxf0(): string
得到对象的DXF组码的类型名,这个和AutoCAD中的DXF组码是一样。 比如直线的类型名为:McDbLine,DXF0组码值: LINE,DXF0组码值可以用来构造集时的类型过滤。
Returns
string
Inherited from
McDbEntity.dxf0
layer
• get
layer(): string
得到对象图层名
Returns
string
Inherited from
McDbEntity.layer
• set
layer(val
): void
设置对象图层名
Parameters
Name | Type | Description |
---|---|---|
val | string | 图层名 |
Returns
void
Example
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity();
ent.layer = "newLayerName";
console.log(ent.layer)
Inherited from
McDbEntity.layer
layerId
• get
layerId(): McObjectId
获取图层ID对象
Returns
Example
// 假设ent为有效实例对象
const layerId = ent.layerId;
Inherited from
McDbEntity.layerId
• set
layerId(id
): void
设置图层Id对象
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
void
Example
// 假设ent为有效实例对象
const mxcad = MxCpp.getCurrentMxCAD();
const layerId = mxcad.addLayer("测试图层")
ent.layerId = layerId;
Inherited from
McDbEntity.layerId
linetype
• get
linetype(): string
得到对象线型名
Returns
string
Inherited from
McDbEntity.linetype
• set
linetype(val
): void
设置对象线型名
Parameters
Name | Type | Description |
---|---|---|
val | string | 线型名 |
Returns
void
Example
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.linetype = "MyLineType";
console.log(ent.linetype)
Inherited from
McDbEntity.linetype
linetypeId
• get
linetypeId(): McObjectId
获取实体对象线型ID
Returns
Example
// 假设ent为有效实例对象
const linetypeId = ent.linetypeId;
Inherited from
McDbEntity.linetypeId
• set
linetypeId(id
): void
设置实体对象线型ID
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
void
Example
// 假设ent为有效实例对象
const mxcad = MxCpp.getCurrentMxCAD();
const lineId = mxcad.addLinetypeEx("TestMyLine", '25,-5');
ent.linetypeId = lineId;
Inherited from
McDbEntity.linetypeId
linetypeScale
• get
linetypeScale(): number
得到对象线型比例
Returns
number
Inherited from
McDbEntity.linetypeScale
• set
linetypeScale(val
): void
设置对象线型比例
Parameters
Name | Type | Description |
---|---|---|
val | number | 线型比例 |
Returns
void
Example
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.linetypeScale = 0.8;
console.log(ent.linetypeScale)
Inherited from
McDbEntity.linetypeScale
lineweight
• get
lineweight(): number
得到对象线重
Returns
number
Inherited from
McDbEntity.lineweight
• set
lineweight(val
): void
设置对象线重
Parameters
Name | Type | Description |
---|---|---|
val | number | 线重 |
Returns
void
Example
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.lineweight = 20;
console.log(ent.lineweight)
Inherited from
McDbEntity.lineweight
normal
• get
normal(): McGeVector3d
返回对象的normal
Returns
Example
Inherited from
McDbEntity.normal
• set
normal(val
): void
设置对象的normal
Parameters
Name | Type |
---|---|
val | McGeVector3d |
Returns
void
Example
Inherited from
McDbEntity.normal
objectName
• get
objectName(): string
获取对象名称。
Returns
string
返回对象名
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.objectName);
Inherited from
McDbEntity.objectName
textStyle
• get
textStyle(): string
得到对象文字样式
Returns
string
Inherited from
McDbEntity.textStyle
• set
textStyle(val
): void
设置对象文字样式
Parameters
Name | Type | Description |
---|---|---|
val | string | 文字样式名 |
Returns
void
Example
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.textStyle = "st_style";
Inherited from
McDbEntity.textStyle
textStyleId
• get
textStyleId(): McObjectId
获取实体文字样式
Returns
Example
// 假设ent为有效实例对象
const textStyleId = ent.textStyleId;
Inherited from
McDbEntity.textStyleId
• set
textStyleId(id
): void
设置实体的文字样式
Parameters
Name | Type |
---|---|
id | McObjectId |
Returns
void
Example
// 假设ent为有效实例对象
const mxcad = MxCpp.getCurrentMxCAD();
const textStyleId = mxcad.addTextStyle("MyLineTypeTextStyle", "txt.shx", "hztxt.shx", 1);
ent.textStyleId = textStyleId;
Inherited from
McDbEntity.textStyleId
trueColor
• get
trueColor(): McCmColor
得到对象颜色
Returns
Example
import { McDbEntity, McCmColor} from 'mxcad'
const ent = new McDbEntity();
ent.trueColor = new McCmColor(255, 0, 0);
console.log(ent.trueColor)
Inherited from
McDbEntity.trueColor
• set
trueColor(val
): void
设置对象颜色
Parameters
Name | Type |
---|---|
val | McCmColor |
Returns
void
Inherited from
McDbEntity.trueColor
visible
• get
visible(): boolean
对象是否可见
Returns
boolean
Inherited from
McDbEntity.visible
• set
visible(val
): void
设置是否可见
Parameters
Name | Type | Description |
---|---|---|
val | boolean | 布尔值 |
Returns
void
Example
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.visible = true;
console.log(ent.visible)
Inherited from
McDbEntity.visible
Methods
IntersectWith
▸ IntersectWith(intersectObject
, exOption
): McGePoint3dArray
与其他实体相交, 得到交点
Parameters
Name | Type | Description |
---|---|---|
intersectObject | McDbEntity | 需要相交的是实体对象 |
exOption | Intersect | 相交的选项 |
Returns
得到所有交点
Example
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)
Inherited from
assertObjectModification
▸ assertObjectModification(autoUndo?
): number
设置对象被改变的状态,可自动触发更新显示函数,更新显示。 比如块表记录更新了,需要通知块引用更新显示,可以调用该函数。
Parameters
Name | Type | Default value |
---|---|---|
autoUndo | boolean | false |
Returns
number
Example
//假设obj为一个数据库对象
obj.assertObjectModification()
Inherited from
McDbEntity.assertObjectModification
clone
▸ clone(): null
| McDbObject
克隆对象。
Returns
null
| McDbObject
克隆出的对象。
Example
//假设obj为一个数据库对象
const obj_clone = obj.clone();
Inherited from
createExtensionDictionary
▸ createExtensionDictionary(): boolean
创建对象的扩展字典数据.
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.createExtensionDictionary();
Inherited from
McDbEntity.createExtensionDictionary
deleteXData
▸ deleteXData(appName
): boolean
删除实体指定应用程序名称相关的数据
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
Returns
boolean
Example
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
//删除失败
}
Inherited from
disableDisplay
▸ disableDisplay(isDisable
): void
禁用对象的自动更新显示.
Parameters
Name | Type | Description |
---|---|---|
isDisable | boolean | 是否禁用对象自动更新显示 |
Returns
void
Example
import { McDbLine } from 'mxcad'
const line1 = new McDbLine(new McGePoint3d(0,0,0), new McGePoint3d(20,1,0));
line1.disableDisplay(true)
Inherited from
erase
▸ erase(): boolean
删除对象。
Returns
boolean
是否删除成功。
Example
//假设obj为一个数据库对象
const res = obj.erase();
console.log(res);
Inherited from
explode
▸ explode(): MxCADResbuf
打碎对象,返回打后对象数据链表
Returns
resbuf 数据
Example
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();
Inherited from
getAllAppName
▸ getAllAppName(): McGeStringArray
获取实体中包含的所有 XData 记录的应用程序名(AppName)
Returns
Example
// 假设ent为有效实例对象
const appNames = ent.getAllAppName();
console.log(appNames);
Inherited from
getArea
▸ getArea(): Object
计算面积
Returns
Object
val 面积值 | ret 是否获取成功
Name | Type |
---|---|
ret | boolean |
val | number |
Example
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)
Inherited from
getBoundingBox
▸ getBoundingBox(): Object
得到对象的最小外包
Returns
Object
Name | Type |
---|---|
maxPt | McGePoint3d |
minPt | McGePoint3d |
ret | boolean |
Example
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()
Inherited from
getClosestPointTo
▸ getClosestPointTo(givenPnt
, isExtend
): Object
得到一个点到曲线的最近点
Parameters
Name | Type | Description |
---|---|---|
givenPnt | McGePoint3d | 参考点 |
isExtend | boolean | 是否延展实体 |
Returns
Object
点对象及执行结果。
Name | Type |
---|---|
ret | boolean |
val | McGePoint3d |
Example
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();
getDatabase
▸ getDatabase(): McDbDatabase
得到对象所在的数据库
Returns
返回数据库
Example
//假设obj为一个数据库对象
const data = obj.getDatabase();
Inherited from
getDatabaseIndexId
▸ getDatabaseIndexId(): number
获取对象的索引ID
Returns
number
Example
//假设obj为一个数据库对象
const id = obj.getDatabaseIndexId();
Inherited from
getDistAtParam
▸ getDistAtParam(param
): Object
获取参数位置上的距离。
Parameters
Name | Type | Description |
---|---|---|
param | number | 参数位置。 |
Returns
Object
距离及执行结果。
Name | Type |
---|---|
ret | boolean |
val | number |
Example
// 假设curve为有效曲线实例对象
const res = curve.getDistAtParam(2);
if(res.ret){
console.log(res.val)
}
getDistAtPoint
▸ getDistAtPoint(pt
): Object
获取曲线上点的距离位置。
Parameters
Name | Type | Description |
---|---|---|
pt | McGePoint3d | 距离位置。 |
Returns
Object
点及执行结果。
Name | Type |
---|---|
ret | boolean |
val | number |
Example
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
}
getEndParam
▸ getEndParam(): Object
获取结束参数。
Returns
Object
结束参数及执行结果。
Name | Type |
---|---|
ret | boolean |
val | number |
Example
// 假设curve为有效曲线实例对象
const endPa = curve.getEndParam();
if(endPa.ret){
console.log(endPa.val)
}
getEndPoint
▸ getEndPoint(): Object
得到曲线的结束点
Returns
Object
曲线的结束点及执行结果。
Name | Type |
---|---|
ret | boolean |
val | McGePoint3d |
Example
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)
}
getExtensionDictionary
▸ getExtensionDictionary(): McDbDictionary
得到对象的扩展字典数据.
Returns
扩展字典数据
Example
//假设obj为一个数据库对象
const id = obj.getOwnerID();
Inherited from
McDbEntity.getExtensionDictionary
getFirstDeriv
▸ getFirstDeriv(pt
): Object
通过曲线上某点得到曲线的一阶导数
Parameters
Name | Type | Description |
---|---|---|
pt | McGePoint3d | 曲线上的点 |
Returns
Object
曲线一阶导数及执行结果。
Name | Type |
---|---|
ret | boolean |
val | McGeVector3d |
Example
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;
}
getFirstDerivFromParam
▸ getFirstDerivFromParam(param
): Object
通过曲线参数得到曲线的一阶导数
Parameters
Name | Type | Description |
---|---|---|
param | number | 曲线参数 |
Returns
Object
曲线一阶导数及执行结果。
Name | Type |
---|---|
ret | boolean |
val | McGeVector3d |
Example
// 假设curve为有效曲线实例对象
const res = curve.getFirstDerivFromParam(5);
if(res.ret){
console.log(res.val)
}
getGripPoints
▸ getGripPoints(): McGePoint3dArray
获取对象的控制点
Returns
Example
//假设obj为一个数据库对象
const ptArr = obj.getGripPoints();
Inherited from
getHandle
▸ getHandle(): string
得到对象句柄
Returns
string
返回对象句柄
Example
//假设obj为一个数据库对象
const handle = obj.getHandle();
Inherited from
getImp
▸ getImp(): any
获取内部实现对象。
Returns
any
内部实现对象。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let imp = obj.getImp();
Inherited from
getJson
▸ getJson(): string
获取 JSON 格式的字符串。
Returns
string
JSON 格式的字符串。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const json = obj.getJson()
Inherited from
getLength
▸ getLength(): Object
得到曲线长度
Returns
Object
Name | Type |
---|---|
ret | boolean |
val | number |
Example
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)
});
getObjectID
▸ getObjectID(): McObjectId
获取对象 ID。
Returns
对象 ID。
Example
import { McDbObject } from "mxcad";
const id = obj.getObjectID();
Inherited from
getOwnerID
▸ getOwnerID(): number
得到对象拥用者的id
Returns
number
Example
//假设obj为一个数据库对象
const id = obj.getOwnerID();
Inherited from
getParamAtDist
▸ getParamAtDist(dist
): Object
获取距离位置上的参数。
Parameters
Name | Type | Description |
---|---|---|
dist | number | 距离位置。 |
Returns
Object
参数及执行结果。
Name | Type |
---|---|
ret | boolean |
val | number |
Example
// 假设curve为有效曲线实例对象
const res = curve.getParamAtDist(0);
if(res.ret){
console.log(res.val)
}
getParamAtPoint
▸ getParamAtPoint(pt
): Object
得到曲线某点位置的曲线参数
Parameters
Name | Type | Description |
---|---|---|
pt | McGePoint3d | 曲线上的点 |
Returns
Object
曲线参数及执行结果。
Name | Type |
---|---|
ret | boolean |
val | number |
Example
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);
}
getPointAtDist
▸ getPointAtDist(dist
): Object
获取距离位置上的点。
Parameters
Name | Type | Description |
---|---|---|
dist | number | 距离位置。 |
Returns
Object
点及执行结果。
Name | Type |
---|---|
ret | boolean |
val | McGePoint3d |
Example
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)
}
getPointAtParam
▸ getPointAtParam(param
): Object
得到曲线参数所在的点坐标
Parameters
Name | Type | Description |
---|---|---|
param | number | 曲线参数 |
Returns
Object
点对象及执行结果。
Name | Type |
---|---|
ret | boolean |
val | McGePoint3d |
Example
// 假设curve为有效曲线实例对象
const res = curve.getPointAtParam(5);
if(res.ret){
console.log(res.val)
}
getSamplePoints
▸ getSamplePoints(dApproxEps
): MxCADResbuf
把曲线离散成一堆点
Parameters
Name | Type | Description |
---|---|---|
dApproxEps | number | 采样间隔 |
Returns
resbuf 数据
Example
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);
getStartParam
▸ getStartParam(): Object
获取起始参数。
Returns
Object
起始参数及执行结果。
Name | Type |
---|---|
ret | boolean |
val | number |
Example
// 假设curve为有效曲线实例对象
const startPa = curve.getStartParam();
if(startPa.ret){
console.log(startPa.val)
}
getStartPoint
▸ getStartPoint(): Object
得到曲线的开始点
Returns
Object
曲线的开始点及执行结果。
Name | Type |
---|---|
ret | boolean |
val | McGePoint3d |
Example
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)
}
getxData
▸ getxData(appName?
): MxCADResbuf
得到对象的扩展数据
Parameters
Name | Type | Default value | Description |
---|---|---|---|
appName | string | "" | 扩展数据名 |
Returns
Example
// 假设ent为有效实例对象
const xData = ent.getXData();
Inherited from
getxDataDouble
▸ getxDataDouble(appName
): Object
获取实体的指定 XData 类型中的 double 值
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
Returns
Object
double 值
Name | Type |
---|---|
ret | boolean |
val | number |
Example
// 假设ent为有效实例对象
let data = ent.getxDataDouble("DataName");
if(data.ret){
console.log(data.val)
}
Inherited from
getxDataLong
▸ getxDataLong(appName
): Object
获取实体的指定 XData 类型中的 long(整数)值
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
Returns
Object
long 值
Name | Type |
---|---|
ret | boolean |
val | number |
Example
// 假设ent为有效实例对象
let data = ent.getxDataLong("DataName");
if(data.ret){
console.log(data.val)
}
Inherited from
getxDataPoint
▸ getxDataPoint(appName
): Object
获取实体的指定 XData 类型中的点对象
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
Returns
Object
获取结果及三维点对象
Name | Type |
---|---|
ret | boolean |
val | McGePoint3d |
Inherited from
getxDataString
▸ getxDataString(appName
): Object
获取与特定实体关联的 XData 信息,并以字符串形式返回
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
Returns
Object
val XData信息 | ret 是否返回成功
Name | Type |
---|---|
ret | boolean |
val | string |
Example
// 假设ent为有效实例对象
let data = ent.getxDataString("DataName");
if(data.ret){
console.log(data.val)
}
Inherited from
highlight
▸ highlight(isHighlight
): void
设置对象是否高亮
Parameters
Name | Type | Description |
---|---|---|
isHighlight | boolean | 是否高亮 |
Returns
void
Example
import { McDbEntity } from 'mxcad'
const ent = new McDbEntity()
ent.highlight(true);
Inherited from
initTempObject
▸ initTempObject(imp
): void
初始化临时对象。
Parameters
Name | Type | Description |
---|---|---|
imp | any | 内部实现对象。 |
Returns
void
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
obj.initTempObject()
Inherited from
isErased
▸ isErased(): boolean
对象是否已经删除
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.isErased();
console.log(res);
Inherited from
isHaveExtensionDictionary
▸ isHaveExtensionDictionary(): boolean
是否有扩展字典数据.
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.isHaveExtensionDictionary();
Inherited from
McDbEntity.isHaveExtensionDictionary
isKindOf
▸ isKindOf(sObjectName
): boolean
判断对象类型
Parameters
Name | Type | Description |
---|---|---|
sObjectName | string | 类型名 |
Returns
boolean
返回对象是否是目标类型
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
let isKind = obj.isKindOf('SomeObjectType');
console.log(isKind); // 输出: true 或 false
Inherited from
isNull
▸ isNull(): any
判断是否为空对象
Returns
any
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
console.log(obj.isNull()); // 输出: true 或 false
Inherited from
mirror
▸ mirror(point1
, point2
): boolean
镜向对象
Parameters
Name | Type | Description |
---|---|---|
point1 | McGePoint3d | 镜像基点 |
point2 | McGePoint3d | - |
Returns
boolean
Example
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.mirror(new McGePoint3d(0,0,0), new McGePoint3d(20,10,0))
Inherited from
move
▸ move(fromPoint
, toPoint
): boolean
移动对象
Parameters
Name | Type | Description |
---|---|---|
fromPoint | McGePoint3d | 移动开始点 |
toPoint | McGePoint3d | 移动结束点 |
Returns
boolean
Example
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.move(new McGePoint3d(0,0,0), new McGePoint3d(20,0,0))
Inherited from
moveGripPointsAt
▸ moveGripPointsAt(iIndex
, dXOffset
, dYOffset
, dZOffset
): any
移动对象的控制点
Parameters
Name | Type | Description |
---|---|---|
iIndex | number | 索引 |
dXOffset | number | X轴偏移量 |
dYOffset | number | Y轴偏移量 |
dZOffset | number | Z轴偏移量 |
Returns
any
Example
//假设obj为一个数据库对象
obj.moveGripPointsAt(1,10,10,10);
Inherited from
offsetCurves
▸ offsetCurves(dOffsetDist
, ptOffsetRef
): McDbObjectArray
得到偏移曲线
Parameters
Name | Type | Description |
---|---|---|
dOffsetDist | number | 偏移距离 |
ptOffsetRef | McGePoint3d | 偏移点 |
Returns
偏移后的对象数组。
Example
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);
});
rotate
▸ rotate(basePoint
, dRotationAngle
): boolean
旋转对象
Parameters
Name | Type | Description |
---|---|---|
basePoint | McGePoint3d | 旋转基点 |
dRotationAngle | number | 旋转角度 |
Returns
boolean
Example
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.rotate(new McGePoint3d(0,0,0), Math.PI)
Inherited from
scaleEntity
▸ scaleEntity(basePoint
, dScaleFactor
): boolean
缩放对象
Parameters
Name | Type | Description |
---|---|---|
basePoint | McGePoint3d | 缩放基点 |
dScaleFactor | number | 缩放因子(<1 缩小; >1 放大) |
Returns
boolean
Example
import { McDbEntity, McGePoint3d } from 'mxcad'
const ent = new McDbEntity()
ent.scaleEntity(new McGePoint3d(0,0,0), 0.5)
Inherited from
setJson
▸ setJson(str
): boolean
设置 JSON 格式的字符串。
Parameters
Name | Type | Description |
---|---|---|
str | string | JSON 格式的字符串。 |
Returns
boolean
是否设置成功。
Example
import { McRxObject } from 'mxcad';
let obj = new McRxObject();
const res = obj.setJson('{"key": "value"}');
console.log(res)
Inherited from
setxData
▸ setxData(xdata
): boolean
设置对象的扩展数据
Parameters
Name | Type | Description |
---|---|---|
xdata | MxCADResbuf | 扩展数据链表 |
Returns
boolean
Example
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"}]));
Inherited from
setxDataDouble
▸ setxDataDouble(appName
, val
): boolean
设置实体的指定 XData 类型中的 double 值
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
val | number | double 值 |
Returns
boolean
布尔值
Example
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{
//设置失败
}
Inherited from
setxDataLong
▸ setxDataLong(appName
, val
): boolean
设置实体的指定 XData 类型中的 long(整数)值
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
val | number | long 值 |
Returns
boolean
long 值
Example
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{
//设置失败
}
Inherited from
setxDataPoint
▸ setxDataPoint(appName
, val
): boolean
设置实体的指定 XData 类型中的点对象
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
val | McGePoint3d | 点对象 |
Returns
boolean
获取结果及三维点对象
Inherited from
setxDataString
▸ setxDataString(appName
, val
): boolean
设置与特定实体关联的 XData 信息,并以字符串形式设置
Parameters
Name | Type | Description |
---|---|---|
appName | string | 扩展数据名称 |
val | string | 字符串值 |
Returns
boolean
是否设置成功
Example
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{
//设置失败
}
Inherited from
splitCurves
▸ splitCurves(pts
): McDbObjectArray
打断曲线
Parameters
Name | Type | Description |
---|---|---|
pts | McGePoint3d [] | 断点数组 |
Returns
打断后的曲线数组。
Example
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)
}
})
splitCurvesFromParam
▸ splitCurvesFromParam(params
): McDbObjectArray
根据曲线参数打断曲线
Parameters
Name | Type | Description |
---|---|---|
params | number [] | 曲线参数数组 |
Returns
打断后的曲线数组。
syncData
▸ syncData(_toCpp?
): boolean
同步实体的数据。这个方法可能是在修改了实体的属性或者附加了新的数据之后调用的,以确保所有的改变都被正确地保存到实体的数据库记录中。
Parameters
Name | Type | Default value | Description |
---|---|---|---|
_toCpp | boolean | true | 是否同步数据 |
Returns
boolean
Example
// 假设ent为有效实例对象
const res = ent.syncData(true);
if(res){
//同步成功
}else{
//同步失败
}
Inherited from
transformBy
▸ transformBy(transformationMatrix
): boolean
变换对象
Parameters
Name | Type | Description |
---|---|---|
transformationMatrix | McGeMatrix3d | 变换矩阵 |
Returns
boolean
Example
import { McGeMatrix3d, McDbEntity, McGeVector3d} from 'mxcad'
const ent = new McDbEntity()
let matrix = new McGeMatrix3d();
matrix.setToTranslation(new McGeVector3d(20,0,0));//平移
ent.transformBy(matrix);
Inherited from
unErase
▸ unErase(): boolean
反删除对象。
Returns
boolean
Example
//假设obj为一个数据库对象
const res = obj.unErase();
console.log(res);
Inherited from
updateDisplay
▸ updateDisplay(): void
显示调用对象更新显示.
Returns
void
Example
// 假设ent为有效实例对象
ent.updateDisplay()