指南
- 开始
- 指南
- 基础绘图
- 交互绘图
- 图纸编辑
- 数据库
- 最佳实践
MxCAD API 文档
- 类
- 2d.Color
- 2d.McAppType
- 2d.McCmColor
- 2d.McDbAlignedDimension
- 2d.McDbArc
- 2d.McDbAttribute
- 2d.McDbAttributeDefinition
- 2d.McDbBlockReference
- 2d.McDbBlockTable
- 2d.McDbBlockTableRecord
- 2d.McDbCircle
- 2d.McDbCurve
- 2d.McDbDatabase
- 2d.McDbDimension
- 2d.McDbEllipse
- 2d.McDbEntity
- 2d.McDbHatch
- 2d.McDbLayerTable
- 2d.McDbLayerTableRecord
- 2d.McDbLine
- 2d.McDbLinetypeTable
- 2d.McDbLinetypeTableRecord
- 2d.McDbMText
- 2d.McDbObject
- 2d.McDbObjectArray
- 2d.McDbPoint
- 2d.McDbPolyline
- 2d.McDbProxyEntity
- 2d.McDbRasterImage
- 2d.McDbRasterImageDef
- 2d.McDbRotatedDimension
- 2d.McDbText
- 2d.McDbTextStyleTable
- 2d.McDbTextStyleTableRecord
- 2d.McGeLongArray
- 2d.McGeMatrix3d
- 2d.McGePoint3d
- 2d.McGePoint3dArray
- 2d.McGeStringArray
- 2d.McGeVector3d
- 2d.McObject
- 2d.McObjectId
- 2d.McRxObject
- 2d.MdGeDoubleArray
- 2d.MxCADResbuf
- 2d.MxCADSelectionSet
- 2d.MxCADUiPrAngle
- 2d.MxCADUiPrBase
- 2d.MxCADUiPrDist
- 2d.MxCADUiPrEntity
- 2d.MxCADUiPrInt
- 2d.MxCADUiPrKeyWord
- 2d.MxCADUiPrPoint
- 2d.MxCADUiPrString
- 2d.MxCADUtilityClass
- 2d.MxCppType
- 2d.MxPropertiesWindowCustom
- 2d.MxPropertiesWindowCustomValue
- 2d.ObjectInheritance
- 3d.MdGeAngleDim
- 3d.MdGeArray1OfInteger
- 3d.MdGeArray1OfPnt
- 3d.MdGeArray1OfReal
- 3d.MdGeArray2OfPnt
- 3d.MdGeArray2OfReal
- 3d.MdGeArrowAspect
- 3d.MdGeAxis
- 3d.MdGeBezierCurve
- 3d.MdGeBezierSurface
- 3d.MdGeBox
- 3d.MdGeBRep
- 3d.MdGeBSplineCurve
- 3d.MdGeBSplineSurface
- 3d.MdGeChamfer
- 3d.MdGeCircle
- 3d.MdGeColor
- 3d.MdGeCompound
- 3d.MdGeCompSolid
- 3d.MdGeCone
- 3d.MdGeCSYS
- 3d.MdGeCSYSR
- 3d.MdGeCylinder
- 3d.MdGeDiameterDim
- 3d.MdGeDimAspect
- 3d.MdGeDir
- 3d.MdGeEdge
- 3d.MdGeEllipse
- 3d.MdGeExplorer
- 3d.MdGeFace
- 3d.MdGeFillet
- 3d.MdGeHGeomPlane
- 3d.MdGeHGeomSurface
- 3d.MdGeHypr
- 3d.MdGeInterpolateBSpl
- 3d.MdGeLengthDim
- 3d.MdGeLight
- 3d.MdGeLine
- 3d.MdGeLineAspect
- 3d.MdGeListIteratorOfListOfShape
- 3d.MdGeListOfShape
- 3d.MdGeLoft
- 3d.MdGeMakeArcOfCircle
- 3d.MdGeMakeFace
- 3d.MdGeMakeThickSolid
- 3d.MdGeMakeWires
- 3d.MdGeMat
- 3d.MdGeMaterialAspect
- 3d.MdGeObject
- 3d.MdGeParab
- 3d.MdGePipe
- 3d.MdGePlane
- 3d.MdGePoint
- 3d.MdGePointsToBSpl
- 3d.MdGePointsToBSplSurface
- 3d.MdGePrism
- 3d.MdGeRadiusDim
- 3d.MdGeRect
- 3d.MdGeRevol
- 3d.MdGeSequenceIteratorOfSequenceOfShape
- 3d.MdGeSequenceOfShape
- 3d.MdGeShape
- 3d.MdGeShell
- 3d.MdGeSolid
- 3d.MdGeSphere
- 3d.MdGeText
- 3d.MdGeTextAspect
- 3d.MdGeTextLabel
- 3d.MdGeTopo
- 3d.MdGeTorus
- 3d.MdGeTransform
- 3d.MdGeTrsf
- 3d.MdGeVec
- 3d.MdGeVertex
- 3d.MdGeWedge
- 3d.MdGeWire
- 3d.MdGeXYZ
- 3d.MxDraw3d
- Color
- McAppType
- McCmColor
- McDbAlignedDimension
- McDbArc
- McDbAttribute
- McDbAttributeDefinition
- McDbBlockReference
- McDbBlockTable
- McDbBlockTableRecord
- McDbCircle
- McDbCurve
- McDbDatabase
- McDbDimension
- McDbEllipse
- McDbEntity
- McDbHatch
- McDbLayerTable
- McDbLayerTableRecord
- McDbLine
- McDbLinetypeTable
- McDbLinetypeTableRecord
- McDbMText
- McDbObject
- McDbObjectArray
- McDbPoint
- McDbPolyline
- McDbProxyEntity
- McDbRasterImage
- McDbRasterImageDef
- McDbRotatedDimension
- McDbText
- McDbTextStyleTable
- McDbTextStyleTableRecord
- McGeLongArray
- McGeMatrix3d
- McGePoint3d
- McGePoint3dArray
- McGeStringArray
- McGeVector3d
- McObject
- McObjectId
- McRxObject
- MdGeAngleDim
- MdGeArray1OfInteger
- MdGeArray1OfPnt
- MdGeArray1OfReal
- MdGeArray2OfPnt
- MdGeArray2OfReal
- MdGeArrowAspect
- MdGeAxis
- MdGeBezierCurve
- MdGeBezierSurface
- MdGeBox
- MdGeBRep
- MdGeBSplineCurve
- MdGeBSplineSurface
- MdGeChamfer
- MdGeCircle
- MdGeColor
- MdGeCompound
- MdGeCompSolid
- MdGeCone
- MdGeCSYS
- MdGeCSYSR
- MdGeCylinder
- MdGeDiameterDim
- MdGeDimAspect
- MdGeDir
- MdGeDoubleArray
- MdGeEdge
- MdGeEllipse
- MdGeExplorer
- MdGeFace
- MdGeFillet
- MdGeHGeomPlane
- MdGeHGeomSurface
- MdGeHypr
- MdGeInterpolateBSpl
- MdGeLengthDim
- MdGeLight
- MdGeLine
- MdGeLineAspect
- MdGeListIteratorOfListOfShape
- MdGeListOfShape
- MdGeLoft
- MdGeMakeArcOfCircle
- MdGeMakeFace
- MdGeMakeThickSolid
- MdGeMakeWires
- MdGeMat
- MdGeMaterialAspect
- MdGeObject
- MdGeParab
- MdGePipe
- MdGePlane
- MdGePoint
- MdGePointsToBSpl
- MdGePointsToBSplSurface
- MdGePrism
- MdGeRadiusDim
- MdGeRect
- MdGeRevol
- MdGeSequenceIteratorOfSequenceOfShape
- MdGeSequenceOfShape
- MdGeShape
- MdGeShell
- MdGeSolid
- MdGeSphere
- MdGeText
- MdGeTextAspect
- MdGeTextLabel
- MdGeTopo
- MdGeTorus
- MdGeTransform
- MdGeTrsf
- MdGeVec
- MdGeVertex
- MdGeWedge
- MdGeWire
- MdGeXYZ
- MxCADResbuf
- MxCADSelectionSet
- MxCADUiPrAngle
- MxCADUiPrBase
- MxCADUiPrDist
- MxCADUiPrEntity
- MxCADUiPrInt
- MxCADUiPrKeyWord
- MxCADUiPrPoint
- MxCADUiPrString
- MxCADUtilityClass
- MxCppType
- MxDraw3d
- MxPropertiesWindowCustom
- MxPropertiesWindowCustomValue
- ObjectInheritance
- 2d.ColorIndexType
- 2d.ColorMethod
- 2d.FetchAttributes
- 2d.McDb.AttachmentPoint
- 2d.McDb.ClipBoundaryType
- 2d.McDb.HatchEdgeType
- 2d.McDb.HatchLoopType
- 2d.McDb.HatchPatternType
- 2d.McDb.HatchStyle
- 2d.McDb.Intersect
- 2d.McDb.LineWeight
- 2d.McDb.TextHorzMode
- 2d.McDb.TextVertMode
- 2d.McObjectIdType
- 2d.MxCADResbufDataType
- 2d.MxCADSelectionSetStatus
- 2d.MxPropertiesWindowCustomValueType
- 3d.MdGe.MxCameraProjection
- 3d.MdGe.MxCF3dFilletShapeEnum
- 3d.MdGe.MxCFDSChamfMode
- 3d.MdGe.MxDimensionArrowOrientation
- 3d.MdGe.MxDimensionTextHorizontalPosition
- 3d.MdGe.MxDimensionTextVerticalPosition
- 3d.MdGe.MxDisplayMode
- 3d.MdGe.MxFontAspect
- 3d.MdGe.MxGAJoinTypeEnum
- 3d.MdGe.MxGAShapeEnum
- 3d.MdGe.MxGFTrihedron
- 3d.MdGe.MxHorizontalTextAlignment
- 3d.MdGe.MxKindOfDimension
- 3d.MdGe.MxNameOfColor
- 3d.MdGe.MxNameOfMaterial
- 3d.MdGe.MxOffsetModeEnum
- 3d.MdGe.MxShapeEnum
- 3d.MdGe.MxTextPath
- 3d.MdGe.MxTypeOfAngle
- 3d.MdGe.MxTypeOfAngleArrowVisibility
- 3d.MdGe.MxTypeOfColor
- 3d.MdGe.MxTypeOfDisplayText
- 3d.MdGe.MxTypeOfLightSource
- 3d.MdGe.MxTypeOfLine
- 3d.MdGe.MxTypeOfMaterial
- 3d.MdGe.MxTypeOfReflection
- 3d.MdGe.MxV3dTypeOfOrientation
- 3d.MdGe.MxVerticalTextAlignment
- 枚举
- ColorIndexType
- ColorMethod
- FetchAttributes
- McDb.AttachmentPoint
- McDb.ClipBoundaryType
- McDb.HatchEdgeType
- McDb.HatchLoopType
- McDb.HatchPatternType
- McDb.HatchStyle
- McDb.Intersect
- McDb.LineWeight
- McDb.TextHorzMode
- McDb.TextVertMode
- McObjectIdType
- MdGe.MxCameraProjection
- MdGe.MxCF3dFilletShapeEnum
- MdGe.MxCFDSChamfMode
- MdGe.MxDimensionArrowOrientation
- MdGe.MxDimensionTextHorizontalPosition
- MdGe.MxDimensionTextVerticalPosition
- MdGe.MxDisplayMode
- MdGe.MxFontAspect
- MdGe.MxGAJoinTypeEnum
- MdGe.MxGAShapeEnum
- MdGe.MxGFTrihedron
- MdGe.MxHorizontalTextAlignment
- MdGe.MxKindOfDimension
- MdGe.MxNameOfColor
- MdGe.MxNameOfMaterial
- MdGe.MxOffsetModeEnum
- MdGe.MxShapeEnum
- MdGe.MxTextPath
- MdGe.MxTypeOfAngle
- MdGe.MxTypeOfAngleArrowVisibility
- MdGe.MxTypeOfColor
- MdGe.MxTypeOfDisplayText
- MdGe.MxTypeOfLightSource
- MdGe.MxTypeOfLine
- MdGe.MxTypeOfMaterial
- MdGe.MxTypeOfReflection
- MdGe.MxV3dTypeOfOrientation
- MdGe.MxVerticalTextAlignment
- MxCADResbufDataType
- MxCADSelectionSetStatus
- MxPropertiesWindowCustomValueType
- 2d.MxCadConfig
- 2d.MxCADUI
- 3d.MxDraw3dConfig
- 3d.WasmConfig
- 接口
- 模块
2. 常用编辑操作
常用编辑操作
CAD中常见的修改和编辑命令包括移动、复制、缩放、旋转、镜像、剪切、延伸、阵列、修改和编辑,这些命令可以帮助用户对绘图进行修改、调整和优化,提高工作效率和设计质量。mxcad 根据该需求提供了相应接口和方法,实现了CAD中常见的修改和编辑命令。这些操作中涉及到对点、向量、矩阵、角度等的计算,具体规则可参考 指南-数学库 。
删除
我们可以通过调用实体的 erase() 方法删除作图过程中的图线和多余的图线。
import { MxCADUtility, McObjectId } from "mxcad"
const objIds = MxCADUtility.getCurrentSelect()
objIds.forEach((objId: McObjectId) => {
objId.erase()
})
复制
我们可以通过调用实体的 clone() 方法复制多个对象,也可对一个或多个对象进行多次复制。在复制完成后可点击复制实体移动到目标位置。
import { MxCADUtility, McDbEntity, McObjectId, MxCpp } from "mxcad"
const objIds = MxCADUtility.getCurrentSelect()
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if (!event) return;
const event_clone = event.clone() as McDbEntity
MxCpp.getCurrentMxCAD().drawEntity(event_clone)
})
此外,我们还可以调用实体的 transformBy() 方法复制对象。该方法是通过变换矩阵实现图形的编辑,具体矩阵变换原理可参考指南数学库中的矩阵-mcgematrix3d。
点击 McGeMatrix3d-clone() 查看矩形变换详细方法和属性。
import { MxCADUtility, McDbEntity, McObjectId, MxCpp} from "mxcad"
const objIds = MxCADUtility.getCurrentSelect()
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if (!event) return;
const event_clone = event.clone() as McDbEntity
const matrix = new McGeMatrix3d()
matrix.clone()
event_clone.transformBy(matrix)
MxCpp.getCurrentMxCAD().drawEntity(event_clone)
})
镜像
我们可以通过调用实体的 mirror() 方法将指定的对象按指定的参考线作镜像处理。
import { MxCADUtility, McObjectId,McGeMatrix3d, MxCADUiPrPoint } from "mxcad"
async function Mx_test_mirror(){
const objIds = MxCADUtility.getCurrentSelect()
const getPt1 = new MxCADUiPrPoint()
getPt1.setMessage("指定镜像参考线的开始点")
const pt1 = await getPt1.go()
if(!pt1) return
const getPt2 = new MxCADUiPrPoint()
getPt2.setMessage("指定镜像参考线的结束点")
const pt2 = await getPt2.go()
if(!pt2) return
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if(!event) return
event.mirror(pt1, pt2)
})
}
此外,我们还可以调用实体的 transformBy() 方法镜像处理对象。该方法是通过变换矩阵实现图形的编辑,具体矩阵变换原理可参考指南数学库中的矩阵-mcgematrix3d。
点击 McGeMatrix3d-setMirror() 查看矩形变换详细方法和属性。
import { MxCADUtility, McObjectId,McGeMatrix3d, MxCADUiPrPoint } from "mxcad"
async function Mx_test_mirror(){
const objIds = MxCADUtility.getCurrentSelect()
const getPt1 = new MxCADUiPrPoint()
getPt1.setMessage("指定镜像参考线的开始点")
const pt1 = await getPt1.go()
if(!pt1) return
const getPt2 = new MxCADUiPrPoint()
getPt2.setMessage("指定镜像参考线的结束点")
const pt2 = await getPt2.go()
if(!pt2) return
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if(!event) return
const matrix = new McGeMatrix3d()
matrix.setMirror(pt1,pt2)
event.transformBy(matrix)
})
}
移动
我们可以通过调用实体的 move() 方法移动目标对象,该移动方法只是变更对象的原始位置,并不复制对象。
import { MxCADUtility, McGePoint3d, McObjectId } from "mxcad"
const objIds = MxCADUtility.getCurrentSelect()
const pt1= new McGePoint3d(0,0,0)
const pt2 = new McGePoint3d(100,100,0)
objIds.forEach((objId: McObjectId) => {
objId.getMcDbEntity()?.move(pt1, pt2)
})
此外,我们还可以调用实体的 transformBy() 方法移动对象。该方法是通过变换矩阵实现图形的编辑,具体矩阵变换原理可参考指南数学库中的矩阵-mcgematrix3d。
点击 McGeMatrix3d-setToTranslation() 查看矩形变换详细方法和属性。
import { MxCADUtility, McGePoint3d, McObjectId } from "mxcad"
const objIds = MxCADUtility.getCurrentSelect()
const pt1= new McGePoint3d(0,0,0)
const pt2 = new McGePoint3d(100,100,0)
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if(!event) return
const matrix = new McGeMatrix3d()
const v = pt2.sub(pt1)
matrix.setToTranslation(v)
event.transformBy(matrix)
})
旋转
我们可以通过调用实体的 rotate() 方法将所选对象绕指定基点旋转指定角度。
import { MxCADUtility, MxCADUiPrPoint } from "mxcad"
async function Mx_test_rotate(){
const objIds = MxCADUtility.getCurrentSelect()
const getPt1 = new MxCADUiPrPoint()
getPt1.setMessage("指定旋转基点")
const pt1 = await getPt1.go()
if(!pt1) return
const getPt2 = new MxCADUiPrPoint()
getPt2.setMessage("指定旋转角度")
getPt2.setUserDraw((pt,pw)=>{
const line = new McDbLine(pt1.x,pt1.y,pt1.z,pt.x,pt.y,pt.z)
pw.drawMcDbEntity(line)
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()?.clone() as McDbEntity
if(!event) return
// 旋转角度
const dRotationAngle = pt1.sub(pt).angleTo2(McGeVector3d.kXAxis, McGeVector3d.kZAxis);
event.rotate(pt1, dRotationAngle)
pw.drawMcDbEntity(event)
})
})
const pt2 = await getPt2.go()
if(!pt2) return
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if(!event) return
const dRotationAngle = pt1.sub(pt2).angleTo2(McGeVector3d.kXAxis, McGeVector3d.kZAxis);
event.rotate(pt1, dRotationAngle)
})
}
此外,我们还可以调用实体的 transformBy() 方法旋转对象。该方法是通过变换矩阵实现图形的旋转,具体矩阵变换原理可参考指南数学库中的矩阵-mcgematrix3d。
点击 McGeMatrix3d-setToTranslation() 查看矩形变换详细方法和属性。
import { MxCADUtility, MxCADUiPrPoint, McGeMatrix3d, McObjectId } from "mxcad"
async function Mx_test_rotate(){
const objIds = MxCADUtility.getCurrentSelect()
const getPt1 = new MxCADUiPrPoint()
getPt1.setMessage("指定旋转中心点")
const pt1 = await getPt1.go()
if(!pt1) return
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if(!event) return
// 以pt1为中心点 绕z轴 旋转45度
const matrix = new McGeMatrix3d()
matrix.setToRotation(Math.PI / 4, McGeVector3d.kZAxis, pt1)
event.transformBy(matrix)
})
}
偏移
我们可以通过调用实体的 offsetCurves() 方法将直线、圆、多线段等作同心复制,相当于平行移动一段距离后进行复制。
import { MxCADResbuf, MxCADUtility, MxCpp } from "mxcad"
async function Mx_test_offset(){
const filter = new MxCADResbuf();
filter.AddMcDbEntityTypes("LINE") ;
const objIds = MxCADUtility.getCurrentSelect(filter)
const getPt1 = new MxCADUiPrPoint()
getPt1.setMessage("指定偏移点")
const pt1 = await getPt1.go()
if(!pt1) return
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity() ;
let objArr = (event as McDbLine).offsetCurves(100,pt1)
if (objArr.length() === 0) return;
objArr.forEach(obj=>{
MxCpp.getCurrentMxCAD().drawEntity(obj as McDbEntity)
})
})
}
缩放
我们可以通过调用实体的 scaleEntity() 方法对图形进行自由缩放。
import { MxCADUtility, MxCADUiPrPoint } from "mxcad"
async function Mx_test_scale(){
const objIds = MxCADUtility.getCurrentSelect()
const getPt = new MxCADUiPrPoint()
getPt.setMessage("指定缩放基点")
const pt = await getPt.go()
if(!pt) return
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if(!event) return
event.scaleEntity(pt,0.2)
})
}
此外,我们还可以调用实体的 transformBy() 方法缩放对象。该方法是通过变换矩阵实现图形的缩放,具体矩阵变换原理可参考指南数学库中的矩阵-mcgematrix3d。
点击 McGeMatrix3d-setToScaling() 查看矩形变换详细方法和属性。
import { MxCADUtility, MxCADUiPrPoint } from "mxcad"
async function Mx_test_scale(){
const objIds = MxCADUtility.getCurrentSelect()
const getPt = new MxCADUiPrPoint()
getPt.setMessage("指定缩放中心点")
const pt = await getPt.go()
if(!pt) return
objIds.forEach((objId: McObjectId) => {
const event = objId.getMcDbEntity()
if(!event) return
const matrix = new McGeMatrix3d()
matrix.setToScaling(0.2, pt)
event.transformBy(matrix)
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论