CATIA 线束布线 API:Bundle / Branch / 路径自动生成完整指南

琛兴科技 · CATIA 二次开发系列 · 适用 V5R19~R32 / Electrical Harness Installation

一、原理:线束在 CATIA 里是几何 + 电气逻辑的双重对象

很多人第一次做线束二开会困惑:线束既不是 Part Design 的实体,也不是 GSD 的纯曲面。它是 CATIA EHI(Electrical Harness Installation) 工作台下的一种特殊产品对象,本质上是"路径曲线 + 直径属性 + 电气网络"三合一。

对象接口说明
Bundle SegmentCATIElbBundleSegment一段主干线束(含路径 + 直径 + 弯曲半径)
BranchCATIElbBranch分支段,从 BSG 派生
ConnectorCATIElbConnector电气连接器(公头/母头)
Multi-BranchableCATIElbMultiBranchableObject支持多分支拓扑的容器
Route 服务CATIRouRoutable路由可达性接口(Routing 通用)

关键差异:CATPart 里的曲线是几何,线束的路径曲线带有"流向"和"直径"两个语义属性。这意味着同一条空间样条,作为 GSD Spline 和作为 BSG 路径,在内核里是两个对象。CAA 二开必须用 EHI Factory 创建,不能拿 GSD Spline 当线束路径用。

线束所在的 CATProduct 文档下面通常有一个 Geometrical Bundle (GB) 几何束节点和一个 Functional Bundle (FB) 功能束节点。GB 装空间路径,FB 装电气逻辑(导线/网络/信号)。两者通过 link 同步。

二、流程:从两个 Connector 自动布出一根线束的 8 步

  1. 打开/创建 CATProduct:线束必须在 Product 上下文,不能在裸 Part 里建。
  2. 切换到 Electrical Harness Assembly 工作台:通过 CATIElbHarness 接口拿到 harness 容器。
  3. 放置两端 Connector:从 catalog 实例化(公头/母头零件),用 CATIRouPlaceable::Place 定位。
  4. 用 CATIElbBundleSegmentFactory 创建 BSG:调用 CreateBundleSegment 传入起止 connector 的电气端口。
  5. 设置路径模式:可选 Slack(自然垂落)、Bundle(直管)、Polyline(用引导点)。批量自动布线一般选 Polyline + 引导点列表。
  6. 添加引导点:用 CATIElbBundleSegment::AddSupport 把卡扣/支架的位置加进去。
  7. 设置直径与弯曲半径SetExtremityDiameter + SetMinimumBendRadius(不设默认 1mm/30mm,会画出鬼畜路径)。
  8. 调用 Update:触发实际曲线生成。Update 失败常因为弯曲半径太大穿支架。

三、避坑:线束二开六大雷区

坑 1:Connector 必须先 Place 在 Product 里
直接 New 出来的 Connector 不在 Product 树里,BSG 创建时会找不到端口位置,报 E_ELB_CONNECTOR_NOT_PLACED。务必先 Place 再 BSG。
坑 2:弯曲半径单位是 mm,不是 cm
某些版本 doc 把 BendRadius 写成 cm 误导,实测内部存的就是 mm。20mm 半径写成 0.02 会让 Update 直接失败。
坑 3:引导点必须按顺序加
AddSupport 不会自动按距离排序,乱序加会得到锯齿路径。批量时先把 support 按沿主轴投影距离排序再加。
坑 4:批量布线后 Update 要分两轮
第一轮 Update 只生成几何,第二轮才结算电气网络。BOM 工具读 length 必须等第二轮。
坑 5:Polyline 模式下两端 connector 朝向决定起点切线
连接器朝向不对会导致路径在端口处剧烈反折。Place 时要把 connector 的 Z 轴指向线束流出方向。
坑 6:CATIRouRoutable 与 CATIElbBundleSegment 是两套接口
通用路由(Tubing/Piping/Harness 共用)走 CATIRouRoutable,电气专属(如 wire mapping、connector pin)走 CATIElb*。两套都要 QI 才能拿全功能。
实战建议:批量整车线束布置先建一个"骨架 Part",把所有支架/卡扣点在骨架上做成 Publication;线束 Product 引用这些 Publication 作为 support。这样后期支架移动时线束自动跟随,是 OEM 的标准做法。

四、完整代码:从两个 Connector 自动布一根 BSG(含支架引导)

// AutoHarness.cpp
// 输入:Product Doc、起止 Connector 实例、支架点列表(CATMathPoint 数组)
// 输出:一根带几何路径的 Bundle Segment

#include "CATIProduct.h"
#include "CATIElbBundleSegmentFactory.h"
#include "CATIElbBundleSegment.h"
#include "CATIElbConnector.h"
#include "CATIRouPlaceable.h"
#include "CATIRouRoutable.h"
#include "CATIUpdate.h"
#include "CATMathPoint.h"

HRESULT CreateAutoHarness(
    CATIProduct_var spProduct,
    CATIProduct_var spStartConnector,   // 已 Place 在 Product 中
    CATIProduct_var spEndConnector,
    const CATListOfCATMathPoint& supportPts,
    double diameterMM,
    double bendRadiusMM)
{
    HRESULT rc = S_OK;
    if (spProduct == NULL_var) return E_FAIL;

    // 1. 拿 BSG Factory(属于 Product 的扩展)
    CATIElbBundleSegmentFactory_var spFactory = spProduct;
    if (spFactory == NULL_var) return E_FAIL;

    // 2. 拿两端 Connector 的电气端口
    CATIElbConnector_var spStartElb = spStartConnector;
    CATIElbConnector_var spEndElb   = spEndConnector;
    if (spStartElb == NULL_var || spEndElb == NULL_var)
        return E_FAIL;  // 不是电气连接器

    // 3. 创建 BSG(Polyline 模式)
    CATIElbBundleSegment_var spBSG;
    rc = spFactory->CreateBundleSegment(
            spStartElb, spEndElb,
            CATElbBSGPolyline,   // 路径模式
            spBSG);
    if (FAILED(rc) || spBSG == NULL_var) return rc;

    // 4. 设置直径与弯曲半径(mm)
    spBSG->SetExtremityDiameter(diameterMM);
    spBSG->SetMinimumBendRadius(bendRadiusMM);

    // 5. 添加支架引导点(必须按沿路径方向排序)
    for (int i = 1; i <= supportPts.Size(); ++i) {
        const CATMathPoint& pt = supportPts[i];
        spBSG->AddSupport(pt, NULL_var);   // 第二参传 NULL = 空中点
    }

    // 6. 第一轮 Update(生成几何路径)
    CATIUpdate_var spUpd = spProduct;
    if (spUpd != NULL_var) spUpd->Update();

    // 7. 第二轮 Update(结算电气网络与长度)
    if (spUpd != NULL_var) spUpd->Update();

    // 8. 验证:读 BSG 长度
    double bsgLength = 0.0;
    spBSG->GetLength(bsgLength);
    cout << "BSG length = " << bsgLength << " mm" << endl;

    return rc;
}

© 上海琛兴科技发展有限公司 · 转载请注明出处 · CATIA 是 Dassault Systèmes 注册商标