動態

詳情 返回 返回

(Online CAD Software)在線CAD二次開發形位公差標註 - 動態 詳情

一、前言

形位公差是指對零件幾何要素的形狀誤差和位置誤差所允許的最大變動量,它與傳統的尺寸公差不同,不僅關注長度或直徑等線性尺寸的變化,還關注零件的幾何特性是否符合設計意圖。在本篇文章中我們將介紹如何通過mxcad插件根據形位公差的特性來實現形位公差標註功能。

二、形位公差的分類

形位公差的所有公差代號如下圖所示:

根據國家標準 GB/T 1182-2018(等同於 ISO 1101),形位公差主要分為以下幾類:

1.形狀公差(Form Tolerance)
2.方向公差(Orientation Tolerance)
3.位置公差(Location Tolerance)
4.跳動公差(Runout Tolerance)

三、形位公差的基本要素

  1. 被測要素:需要控制其形狀或位置的幾何要素。
  2. 基準要素:作為參照的標準幾何要素,通常用大寫字母 A、B、C 表示。
  3. 公差帶:允許誤差存在的區域範圍,通常是二維或三維的空間區域。
  4. 公差框格:標註形位公差信息的圖形符號,包含:

    公差類型符號
    公差值
    基準字母(如果有)

四、mxcad實現形位公差類

根據上面的介紹,我們可以根據形位公差的“特徵控制框”來構建我們的形位公差自定義實體,結構如下:

[公差符號] [公差值] [基準A] [基準B] 

4.1. 類定義與繼承

export class MxDbGeometricTolerances extends McDbCustomEntity {
    // 類實現
}

4.2. 核心屬性

// 標註起點
private startPoint: McGePoint3d = new McGePoint3d();
// 標註轉折點
private turningPoint: McGePoint3d = new McGePoint3d();
// 標註點
private dimPoint: McGePoint3d = new McGePoint3d();
// 標註終點
private endPoint: McGePoint3d = new McGePoint3d();
// 標註大小
private size: number = 4;
// 是否顯示全周符號
private isShowFull: boolean = false;
// 公差內容
private toleranceContents: toleranceContent[] = [];
// 附註上
private notesUp: string = '';
// 附註下
private notesDown: string = '';

4.3. 公差代號枚舉

export enum symbolName {
    Straightness = 'u',        // 直線度
    Flatness = 'c',           // 平面度
    Roundness = 'e',          // 圓度
    Cylindricity = 'g',       // 圓柱度
    LineContourdegree = 'k',  // 線輪廓度
    SurfaceContourDegree = 'd',// 面輪廓度
    Parallelism = 'f',        // 平行度
    Perpendicularity = 'b',   // 垂直度
    TiltDegree = 'a',         // 傾斜度
    PositionalDegree = 'j',   // 位置度
    Coaxiality = 'r',         // 同軸度
    SymmetryDegree = 'i',     // 對稱度
    CircleJumping = 'h',      // 圓跳動
    FullBeat = 't',           // 全跳動
    None = ''                 // 無
}

五、主要功能實現

5.1. 繪製功能

5.1.1 箭頭和引線繪製

private drawArrow(): McDbEntity[] {
    // 繪製箭頭
    const pt1 = this.startPoint;
    const pt2 = this.turningPoint;
    const arrowLength = this.size;
    const vec = pt2.sub(pt1).normalize().mult(arrowLength);
    const pt = pt1.clone().addvec(vec);
    const _vec = vec.clone().rotateBy(Math.PI / 2).normalize().mult(arrowLength / 8);
    const pt3 = pt.clone().addvec(_vec);
    const pt4 = pt.clone().subvec(_vec);
    const solid = new McDbHatch();
    solid.appendLoop(new McGePoint3dArray([pt1, pt3, pt4]));
    // 繪製引線
    const points = [this.startPoint, this.turningPoint, this.dimPoint, this.endPoint];
    const pl = new McDbPolyline();
    points.forEach(pt => pl.addVertexAt(pt));
    return [solid, pl];
}

5.1.2 公差代號繪製

    // 繪製公差代號
    private drawCode(topPt: McGePoint3d, endPt: McGePoint3d, boxHeight: number): McDbEntity[] {
        const entityArr: McDbEntity[] = [];
        // 首先繪製整體code邊框
        const pl = new McDbPolyline();
        pl.isClosed = true;
        const v = McGeVector3d.kXAxis.clone().mult(boxHeight);
        const ptArr = [endPt, topPt, topPt.clone().addvec(v), endPt.clone().addvec(v)];
        ptArr.forEach(pt => pl.addVertexAt(pt));
        entityArr.push(pl);
        // 合併相鄰公差代號
        const mergeAdjacent = (arr) => {
            const result = [];
            let i = 0;
            while (i < arr.length) {
                let j = i + 1;
                // 找到連續相同的元素
                while (j < arr.length && arr[j] === arr[i]) {
                    j++;
                }
                // 推入當前值和個數
                result.push({
                    value: arr[i],
                    count: j - i
                });
                // 移動指針到下一個不同的位置
                i = j;
            }
            return result;
        }
        const arr = this.toleranceContents.map(item => item.toleranceCode);
        const res = mergeAdjacent(arr);
        const vec_x = McGeVector3d.kXAxis.clone().mult(boxHeight);
        res.forEach(item => {
            // 繪製公差代號
            const text = new McDbMText();
            text.textHeight = this.size * (3 / 4);
            text.contents = item.value;
            text.attachment = McDb.AttachmentPoint.kBottomMid;
            const v = endPt.sub(topPt).normalize().mult(boxHeight * item.count);
            const center = topPt.clone().addvec(v.clone().mult(1 / 2)).addvec(vec_x.clone().mult(1 / 2));
            text.location = center;
            text.textStyle = 'cxgdt';
            topPt.addvec(v);
            entityArr.push(text);
            text.reCompute();
            const { maxPt, minPt } = MxCADUtility.getTextEntityBox(text, false);  
            if(minPt.distanceTo(maxPt) > text.textHeight*3){
                maxPt.addvec(McGeVector3d.kXAxis.clone().negate().mult(text.textHeight*(7/4)));
            }
            const midPt = minPt.clone().addvec(maxPt.sub(minPt).mult(1 / 2));
            text.move(midPt, center);
            const line = new McDbLine(topPt, topPt.clone().addvec(vec_x));
            entityArr.push(line)
        });
        return entityArr
    }

5.1.3 公差內容繪製

 // 繪製公差內容
    private drawToleranceContents(topPt: McGePoint3d, endPt: McGePoint3d, boxHeight: number): { MText: MxCADMText[], entityArr: McDbEntity[], max_x: number } {
        const entityArr: McDbEntity[] = [];
        const MText: MxCADMText[] = [];
        const mxcad = MxCpp.getCurrentMxCAD();
        /**
         * 公差1標註:3個標註中記錄出X最大值
         */
        let max_x = topPt.x;
        const v_spacing = McGeVector3d.kXAxis.clone().mult(this.size / 4);
        const vec_y = McGeVector3d.kYAxis.clone().mult(boxHeight).negate();
        this.toleranceContents.forEach((item, ind) => {
            const _topPt = topPt.clone();
            const _endPt = endPt.clone();
            if (item.tolerance.length) {
                _topPt.addvec(v_spacing).addvec(vec_y.clone().mult(ind));
                const _v = McGeVector3d.kYAxis.clone().mult(boxHeight / 2 - this.size * (3 / 8)).negate();
                item.tolerance.forEach((str, index) => {
                    if (index === 4 || (index === 3 && (str === '{' || str === '@'))) {
                        const mText = new MxCADMText()
                        mText.data = [{
                            type: 'paragraph',
                            children: [
                                { text: str, font: 'cxgdtshp.shx' },
                            ]
                        }];
                        mText.position = _topPt.clone().addvec(_v);
                        mText.textBaseHeight = this.size * (3 / 4);
                        MText.push(mText);
                        const v = McGeVector3d.kXAxis.clone().mult(this.size);
                        const pt = mText.position.clone().addvec(v);
                        _topPt.x = _endPt.x = pt.x;
                    } else {
                        const text = new McDbMText();
                        text.contents = str;
                        text.location = _topPt.clone().addvec(_v);
                        text.textHeight = this.size * (3 / 4);
                        if (index == 2 || index == 4) {
                            text.textStyle = 'cxgdtshp';
                        } else if (index == 3 && str !== '{') {
                            text.textStyle = 'cxgdt'
                        } else {
                            text.textStyleId = mxcad.getDatabase().getCurrentlyTextStyleId()
                        }
                        text.reCompute();
                        const { maxPt, minPt } = MxCADUtility.getTextEntityBox(text, false);
                        _topPt.x = _endPt.x = maxPt.x;
                        entityArr.push(text);
                    }
                });
            };
            if (_topPt.x > max_x) max_x = _topPt.x;
        });
        if (max_x > topPt.x) {
            this.toleranceContents.forEach((item, index) => {
                const pl = new McDbPolyline();
                const topPt_max = new McGePoint3d(max_x, topPt.y);
                const endPt_max = new McGePoint3d(max_x, endPt.y);
                const points = [topPt, topPt_max.clone().addvec(v_spacing), endPt_max.clone().addvec(v_spacing)];
                points.forEach(pt => pl.addVertexAt(pt));
                entityArr.push(pl);
                topPt.addvec(vec_y);
                if (index === this.toleranceContents.length - 1) {
                    const line = new McDbLine(endPt_max.clone().addvec(v_spacing), endPt);
                    entityArr.push(line);
                }
            });
            max_x = new McGePoint3d(max_x, topPt.y).addvec(v_spacing).x;
        };
        return { entityArr, MText, max_x }
    }

5.1.4 繪製基準內容

// 繪製基準內容
    private drawBenchmark(topPt: McGePoint3d, endPt: McGePoint3d, boxHeight: number): { entityArr: McDbEntity[], MText } {
        const mxcad = MxCpp.getCurrentMxCAD();
        const _v = McGeVector3d.kYAxis.clone().mult(boxHeight / 2 - this.size * (3 / 8)).negate();
        const vec_y = McGeVector3d.kYAxis.clone().mult(boxHeight).negate();
        const v_spacing = McGeVector3d.kXAxis.clone().mult(this.size / 4);
        let max_x = topPt.x;
        const lineX = [];
        const MText: MxCADMText[] = []
        const getTextEnts = (contents: Array<string[]>, _topPt: McGePoint3d): McDbEntity[] => {
            const entity = [];
            let endPt = _topPt.clone();
            _topPt.addvec(v_spacing)
            if (contents.length === 2 && contents.filter(item => item.length != 0).length === 2) contents.splice(1, 0, ['-']);
            contents.forEach((arr, index) => {
                if (arr.length) {
                    arr.forEach((str, ind) => {
                        if (ind === 1 && str === '{') {
                            const mText = new MxCADMText()
                            mText.data = [{
                                type: 'paragraph',
                                children: [
                                    { text: str, font: 'cxgdtshp.shx' },
                                ]
                            }];
                            mText.position = _topPt.clone().addvec(_v);
                            mText.textBaseHeight = this.size * (3 / 4);
                            MText.push(mText);
                            const v = McGeVector3d.kXAxis.clone().mult(this.size);
                            const pt = mText.position.clone().addvec(v);
                            _topPt.x = endPt.x = pt.x;
                        } else {
                            const text = new McDbMText();
                            text.contents = str;
                            text.location = _topPt.clone().addvec(_v);
                            text.textHeight = this.size * (3 / 4);
                            if (ind == 1) {
                                text.textStyle = 'CXGDT';
                            } else {
                                text.textStyleId = mxcad.getDatabase().getCurrentlyTextStyleId()
                            }
                            text.reCompute();
                            const { maxPt, minPt } = MxCADUtility.getTextEntityBox(text, false);
                            if (max_x < maxPt.x) max_x = maxPt.x;
                            endPt.x = maxPt.x;
                            entity.push(text);
                            _topPt.x = maxPt.x;
                        }
                    })
                }
            });
            if (max_x < endPt.x) max_x = endPt.x;
            return entity;
        }
        const entityArr: McDbEntity[] = [];
        const maxXArr: number[] = [];
        //先統一繪製基準1、2、3
        const bNames = ['b1', 'b2', 'b3'];
        let textEnd_x = topPt.x;
        bNames.forEach((name, index) => {
            if (index != 0 && lineX.length) {
                textEnd_x = Math.max(...lineX)
                maxXArr.push(textEnd_x)
            };
            lineX.length = 0;
            this.toleranceContents.forEach((item, ind) => {
                if (item.Benchmark[name]?.length && item.Benchmark[name].filter(i => i.length).length > 0) {
                    const _topPt = new McGePoint3d(textEnd_x, topPt.clone().addvec(vec_y.clone().mult(ind)).y);
                    entityArr.push(...getTextEnts(item.Benchmark[name], _topPt));
                    const pt = new McGePoint3d(max_x, topPt.y);
                    pt.addvec(v_spacing);
                    max_x = pt.x;
                    lineX.push(max_x)
                }
            })
        })
        if (entityArr.length > 0) {
            maxXArr.forEach(x => {
                const line = new McDbLine(new McGePoint3d(x, topPt.y), new McGePoint3d(x, endPt.y));
                entityArr.push(line)
            })
            const line = new McDbLine(new McGePoint3d(max_x, topPt.y), new McGePoint3d(max_x, endPt.y));
            const _line = new McDbLine(endPt, new McGePoint3d(max_x, endPt.y));
            entityArr.push(line, _line);
            this.toleranceContents.forEach((item, index) => {
                if (index != 0) topPt.addvec(vec_y.clone());
                const line = new McDbLine(topPt, new McGePoint3d(max_x, topPt.y));
                entityArr.push(line)
            });
        }
        return { entityArr, MText }
    }

5.1.5 動態繪製

 // 繪製實體
    public worldDraw(draw: MxCADWorldDraw): void {
        const mxcad = MxCpp.getCurrentMxCAD();
        const textStyle = ['cxgdtshp', 'cxgdt'];
        textStyle.forEach(name => {
            if (!mxcad.getDatabase().getTextStyleTable().has(name)) {
                MxCpp.App.loadFonts([`${name}.shx`], [], [`${name}.shx`], () => {
                    mxcad.addTextStyle(name, `${name}.shx`, `${name}.shx`);
                });
            }
        })
        const { MText, allEntityArr } = this.getAllEnitty();
        MText.forEach((ent: MxCADMText) => {
            ent.worldDraw(draw);
        });
        allEntityArr.forEach((ent: McDbEntity) => {
            draw.drawEntity(ent);
        })
    }
    // 獲取所有實體
    private getAllEnitty(): { allEntityArr: McDbEntity[], MText: MxCADMText[] } {
        const allEntityArr = [];
        // 繪製箭頭
        const entity = this.drawArrow();
        allEntityArr.push(...entity);
        //  繪製全周符號
        const types = [symbolName.LineContourdegree, symbolName.SurfaceContourDegree];
        if (this.toleranceContents.length === 1 && types.includes(this.toleranceContents[0].toleranceCode) && this.isShowFull) {
            const circle = new McDbCircle(this.dimPoint.x, this.dimPoint.y, 0, this.size * (7 / 16));
            allEntityArr.push(circle);
        }
        // 繪製公差標註
        const boxHeight = this.size * (7 / 4);
        const vec = McGeVector3d.kYAxis.clone().mult(boxHeight * (this.toleranceContents.length / 2))
        const topPt = this.endPoint.clone().addvec(vec);
        const endPt = this.endPoint.clone().addvec(vec.clone().negate());
        // 繪製公差代號
        allEntityArr.push(...this.drawCode(topPt.clone(), endPt.clone(), boxHeight));
        // 繪製公差內容
        const vec_x = McGeVector3d.kXAxis.clone().mult(boxHeight);
        const { MText, entityArr, max_x } = this.drawToleranceContents(topPt.clone().addvec(vec_x), endPt.clone().addvec(vec_x), boxHeight);
        allEntityArr.push(...entityArr);
        // 繪製基準一二三
        const { MText: _MText, entityArr: _entityArr } = this.drawBenchmark(new McGePoint3d(max_x, topPt.y), new McGePoint3d(max_x, endPt.y), boxHeight)
        allEntityArr.push(..._entityArr);
        MText.push(..._MText);
        // 繪製上下附註
        const arr = [this.notesUp, this.notesDown];
        arr.forEach((item, index) => {
            const text = new McDbMText();
            text.contents = item;
            text.textHeight = this.size * (3 / 4)
            text.location = index == 0 ? topPt.clone().addvec(McGeVector3d.kYAxis.clone().mult(this.size)) : endPt.clone().addvec(McGeVector3d.kYAxis.clone().mult(this.size / 4).negate());
            allEntityArr.push(text);
        })
        return { allEntityArr, MText }
    }

5.2. 數據存儲

// 讀取自定義實體數據
    public dwgInFields(filter: IMcDbDwgFiler): boolean {
        this.startPoint = filter.readPoint("startPoint").val;
        this.turningPoint = filter.readPoint("turningPoint").val;
        this.dimPoint = filter.readPoint("dimPoint").val;
        this.endPoint = filter.readPoint("endPoint").val;
        this.size = filter.readDouble("size").val;
        this.isShowFull = filter.readLong("isShowFull").val ? true : false;
        this.notesUp = filter.readString('notesUp').val;
        this.notesDown = filter.readString('notesDown').val;
        this.minPt = filter.readPoint("minPt").val;
        this.maxPt = filter.readPoint("maxPt").val;
        this.toleranceContents = JSON.parse(filter.readString('toleranceContents').val);
        return true;
    }
    // 寫入自定義實體數據
    public dwgOutFields(filter: IMcDbDwgFiler): boolean {
        filter.writePoint("startPoint", this.startPoint);
        filter.writePoint("turningPoint", this.turningPoint);
        filter.writePoint("dimPoint", this.dimPoint);
        filter.writePoint("endPoint", this.endPoint);
        filter.writeDouble("size", this.size);
        filter.writeLong("isShowFull", this.isShowFull ? 1 : 0);
        filter.writeString("notesUp", this.notesUp);
        filter.writeString("notesDown", this.notesDown);
        filter.writePoint("minPt", this.minPt);
        filter.writePoint("maxPt", this.maxPt);
        filter.writeString('toleranceContents', JSON.stringify(this.toleranceContents));
        return true;
    }

5.3. 夾點編輯功能

 // 移動自定義對象的夾點
    public moveGripPointsAt(iIndex: number, dXOffset: number, dYOffset: number, dZOffset: number) {
        this.assertWrite();
        if (iIndex === 0) {
            this.startPoint.x += dXOffset;
            this.startPoint.y += dYOffset;
            this.startPoint.z += dZOffset;
        } else if (iIndex === 1) {
            this.turningPoint.x += dXOffset;
            this.turningPoint.y += dYOffset;
            this.turningPoint.z += dZOffset;
        } else if (iIndex === 2) {
            this.dimPoint.x += dXOffset;
            this.dimPoint.y += dYOffset;
            this.dimPoint.z += dZOffset;
            this.endPoint.x += dXOffset;
            this.endPoint.y += dYOffset;
            this.endPoint.z += dZOffset;
        } else if (iIndex === 3) {
            this.endPoint.x += dXOffset;
            this.endPoint.y += dYOffset;
            this.endPoint.z += dZOffset;
        }
    };
    // 獲取自定義對象的夾點
    public getGripPoints(): McGePoint3dArray {
        let ret = new McGePoint3dArray()
        ret.append(this.startPoint);
        ret.append(this.turningPoint);
        ret.append(this.dimPoint);
        ret.append(this.endPoint);
        return ret;
    };

5.4. 暴露內部屬性方法

 //設置或獲取標註大小
    public set dimSize(val: number) {
        this.size = val;
    }
    public get dimSize(): number {
        return this.size;
    }
    //設置或獲取是否顯示全周符號
    public set isShowFullWeekSymbol(val: boolean) {
        this.isShowFull = val;
    }
    public get isShowFullWeekSymbol(): boolean {
        return this.isShowFull;
    }
    //設置或獲取公差標註內容
    public set dimToleranceContents(val: toleranceContent[]) {
        this.toleranceContents = val;
    }
    public get dimToleranceContents(): toleranceContent[] {
        return this.toleranceContents;
    }
    //設置或獲取附註上
    public set dimNotesUp(val: string) {
        this.notesUp = val;
    }
    public get dimNotesUp(): string {
        return this.notesUp;
    }
    //設置或獲取附註下
    public set dimNotesDown(val: string) {
        this.notesDown = val;
    }
    public get dimNotesDown(): string {
        return this.notesDown;
    }
    private getBox(entityArr: McDbEntity[]) {
        const mxcad = MxCpp.getCurrentMxCAD();
        let _minPt, _maxPt = null;
        let result;
        entityArr.forEach(entity => {
            if (entity instanceof McDbMText) {
                // 將ent的文字樣式設置為當前文字樣式
                const textStyleId = mxcad.getDatabase().getCurrentlyTextStyleId();
                entity.textStyleId = textStyleId;
                entity.reCompute();
                result = MxCADUtility.getTextEntityBox(entity, false);
            } else if (entity instanceof McDbMText) {
                entity.reCompute();
                result = MxCADUtility.getTextEntityBox(entity, false);
            } else {
                result = entity.getBoundingBox();
            }
            const { minPt, maxPt, ret } = result;
            if (!_minPt) _minPt = minPt.clone();
            if (!_maxPt) _maxPt = maxPt.clone();
            if (minPt.x < _minPt.x) _minPt.x = minPt.x;
            if (minPt.y < _minPt.y) _minPt.y = minPt.y;
            if (maxPt.x > _maxPt.x) _maxPt.x = maxPt.x;
            if (maxPt.y > _maxPt.y) _maxPt.y = maxPt.y;
        });
        if (_minPt && _maxPt) {
            this.maxPt = _maxPt;
            this.minPt = _minPt;
        }
    }
    // 設置標註起點
    public setStartPoint(pt: McGePoint3d) {
        this.startPoint = this.turningPoint = this.endPoint = this.dimPoint = pt.clone();
    }
    // 獲取標註起點
    public getStartPoint() {
        return this.startPoint;
    }
    // 設置標註轉折點
    public setTurningPoint(pt: McGePoint3d) {
        this.turningPoint = this.endPoint = this.dimPoint = pt.clone();
    }
    // 獲取標註轉折點
    public getTurningPoint() {
        return this.turningPoint;
    }
    // 設置標註終點
    public setEndPoint(pt: McGePoint3d) {
        this.endPoint = pt.clone();
    }
    // 獲取標註終點
    public getEndPoint() {
        return this.endPoint;
    }
    // 獲取標註轉折點
    public getDimPoint() {
        return this.dimPoint;
    }
    // 設置標註終點
    public setDimPoint(pt: McGePoint3d) {
        this.dimPoint = this.endPoint = pt.clone();
    }
    // 獲取包圍盒
    public getBoundingBox(): { minPt: McGePoint3d; maxPt: McGePoint3d; ret: boolean; } {
        const { allEntityArr } = this.getAllEnitty();
        this.getBox(allEntityArr);
        return { minPt: this.minPt, maxPt: this.maxPt, ret: true }
    }

六、使用方法

6.1.註冊MxDbGeometricTolerances實體類

new MxDbGeometricTolerances().rxInit();

6.2.繪製形位公差

async function Mx_drawGeometricTolerance() {
             // 創建形位公差實體
            const dim = new MxDbGeometricTolerances();
            // 設置公差內容
            dim.dimToleranceContents = [{
                "toleranceCode": "b", "tolerance": ["φ","we","<","@"],
                "Benchmark": {"b1": [[],[]],"b1": [[],[]],"b1": [[],[]]}
            }];
            dim.isShowFullWeekSymbol = false;
            dim.dimNotesDown = '下標註';
            dim.dimNotesUp = '上標註';
            // 設置標註點
            const getStartPt = new MxCADUiPrPoint();
            getStartPt.setMessage('請設置定位點或直線或圓弧或圓');
            const startPt = await getStartPt.go();
            if (!startPt) return;
            dim.setStartPoint(startPt);           
            // 設置轉折點
            const getTurningPt = new MxCADUiPrPoint();
            getTurningPt.setMessage('請設置轉折點');
            getTurningPt.setUserDraw((pt, pw) => {
                dim.setTurningPoint(pt);
                pw.drawMcDbEntity(dim);
            });
            const turnPt = await getTurningPt.go();
            if (!turnPt) return;
            dim.setTurningPoint(turnPt);           
            // 設置標註位置
            const getDimPt = new MxCADUiPrPoint();
            getDimPt.setMessage('拖動確定標註位置');
            getDimPt.setUserDraw((pt, pw) => {
                dim.setDimPoint(pt);
                pw.drawMcDbEntity(dim);
            });
            const dimPt = await getDimPt.go();
            if (!dimPt) return;
            dim.setDimPoint(dimPt);           
            // 設置終點
            const getEndPt = new MxCADUiPrPoint();
            getEndPt.setMessage('拖動確定標註位置');
            getEndPt.setUserDraw((pt, pw) => {
                dim.setEndPoint(pt);
                pw.drawMcDbEntity(dim);
            });
            const endPt = await getEndPt.go();
            if (!endPt) return;
            dim.setEndPoint(endPt);   
            // 繪製實體
            const mxcad = MxCpp.getCurrentMxCAD();
            mxcad.drawEntity(dim);
}

七、注意事項

  1. 使用前需要確保已正確加載字體文件(cxgdtshp.shx 和 cxgdt.shx)
  2. 形位公差的繪製需要按照正確的順序設置各個點(起點、轉折點、標註點、終點)
  3. 公差內容的設置需要符合規範,包括公差代號、公差值和基準等
  4. 在繪製過程中需要注意座標系統的正確使用

八、效果演示

在上述介紹中,我們已經實現了形位公差的自定義實體,通過該實體與我們的mxcad項目結合,我們就能夠實現更完善的形位公差標註功能。
基礎效果演示:

根據上述內容可做擴展開發,根據焊接符號特性設置對應的彈框,其示例效果如下:

user avatar grewer 頭像 vleedesigntheory 頭像 littlelyon 頭像 zaoying 頭像 linx 頭像 anchen_5c17815319fb5 頭像 hard_heart_603dd717240e2 頭像 u_17443142 頭像 jiavan 頭像 xiaolei_599661330c0cb 頭像 jdcdevloper 頭像 assassin 頭像
點贊 86 用戶, 點贊了這篇動態!
點贊

Add a new 評論

Some HTML is okay.