C# Solidworks二次开发:访问BOM表特性相关API详解

大家好,今天要讲的文章是和BOM表特性相关的API。

下面为要介绍的API:

(1)第一个为GetConfigurationCount,这个API的含义为获取此BOM表可用或在此BOM表中使用的配置数,下面是官方的具体解释:

其输入的参数值为bool值,当为true的时候,表示获取该表中当前显示的配置数,当为false的时候,表示获取该表中可用配置的总数。

返回值为此BOM表中或可用于此BOM表的配置个数。

使用API的时候可以先看一下备注:

The view associated with this BOM can contain a model with multiple configurations.

For a top-level only style BOM table, there can be several Quantity columns, each showing the results for a different configuration.  For the other styles of BOM tables, only a particular configuration can be shown in the table, and that configuration can be changed. To determine the style of the BOM table, use IBomFeature::TableType.

If OnlyVisible is...

Then the value returned is...

True

Number of configurations currently shown in the BOM table.

For a top-level only style BOM table, this could be any number from 0 to the total number of configurations available. For the other styles of BOM tables, this value is always 1.

false

Total number of configurations available.

To get the configuration names, call IBomFeature::GetConfigurations or IBomFeature::IGetConfigurations.

Call this method before calling IBomFeature::IGetConfigurations to get the number of configurations.

(2)第二个为GetFeature,这个API的含义为获取BOM表的特征,下面是官方的具体解释:

其没有输入值,只有返回值为指向BOM表特征的指针对象。

下面是官方使用的例子:

This example shows how to get the components in each row of a BOM table annotation.

//-----------------------------------------------------------------------------
// Preconditions:
// 1. Open public_documents\samples\tutorial\assemblyvisualize\food_processor.sldasm.
// 2. Make a drawing from the assembly.
// 3. Click Insert > Tables > Bill of Materials.
// 4. Ensure that Parts only in Bom Type is selected.
// 5. Ensure that Display configurations of the same part separate items
//    in Part Configuration Grouping is selected.
// 6. Click OK.
// 7. Click anywhere in the drawing to insert the BOM table.
//
// Postconditions:
// 1. Gets the Bill of Materials1 feature.
// 2. Gets the Default configuration.
// 3. Processes the BOM table for the Default configuration.
// 4. Examine the Immediate window.
//
// NOTE: Because the assembly is used elsewhere, do not save changes.
//-----------------------------------------------------------------------------
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
namespace Macro1CSharp.csproj
{
    partial class SolidWorksMacro
    {
 
        public void ProcessTableAnn(SldWorks swApp, ModelDoc2 swModel, TableAnnotation swTableAnn, string ConfigName)
        {
            int nNumRow = 0;
            int J = 0;
            int I = 0;
            string ItemNumber = null;
            string PartNumber = null;
            bool RowLocked;
            double RowHeight;
 
            Debug.Print("   Table Title: " + swTableAnn.Title);
 
            nNumRow = swTableAnn.RowCount;
 
            BomTableAnnotation swBOMTableAnn = default(BomTableAnnotation);
            swBOMTableAnn = (BomTableAnnotation)swTableAnn;
 
            for (J = 0; J <= nNumRow - 1; J++)
            {
                RowLocked = swTableAnn.GetLockRowHeight(J);
                RowHeight = swTableAnn.GetRowHeight(J);
                Debug.Print("   Row Number " + J + " (height = " + RowHeight + "; height locked = " + RowLocked + ")");
                Debug.Print("     Component Count: " + swBOMTableAnn.GetComponentsCount2(J, ConfigName, out ItemNumber, out PartNumber));
                Debug.Print("       Item Number: " + ItemNumber);
                Debug.Print("       Part Number: " + PartNumber);
 
                object[] vPtArr = null;
                Component2 swComp = null;
                object pt = null;
 
                vPtArr = (object[])swBOMTableAnn.GetComponents2(J, ConfigName);
 
                if (((vPtArr != null)))
                {
                    for (I = 0; I <= vPtArr.GetUpperBound(0); I++)
                    {
                        pt = vPtArr[I];
                        swComp = (Component2)pt;
                        if ((swComp != null))
                        {
                            Debug.Print("           Component Name: " + swComp.Name2);
                            Debug.Print("           Configuration Name: " + swComp.ReferencedConfiguration);
                            Debug.Print("           Component Path: " + swComp.GetPathName());
                        }
                        else
                        {
                            Debug.Print("  Could not get component.");
                        }
                    }
                }
            }
        }
 
 
 
        public void ProcessBomFeature(SldWorks swApp, ModelDoc2 swModel, BomFeature swBomFeat)
        {
            Feature swFeat = default(Feature);
            object[] vTableArr = null;
            object vTable = null;
            string[] vConfigArray = null;
            object vConfig = null;
            string ConfigName = null;
            TableAnnotation swTable = default(TableAnnotation);
            object visibility = null;
 
            swFeat = swBomFeat.GetFeature();
            vTableArr = (object[])swBomFeat.GetTableAnnotations();
 
            foreach (TableAnnotation vTable_loopVariable in vTableArr)
            {
                vTable = vTable_loopVariable;
                swTable = (TableAnnotation)vTable;
                vConfigArray = (string[])swBomFeat.GetConfigurations(true, ref visibility);
                foreach (object vConfig_loopVariable in vConfigArray)
                {
                    vConfig = vConfig_loopVariable;
                    ConfigName = (string)vConfig;
                    Debug.Print(" Component for Configuration: " + ConfigName);
                    ProcessTableAnn(swApp, swModel, swTable, ConfigName);
                }
            }
 
        }
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            DrawingDoc swDraw = default(DrawingDoc);
            Feature swFeat = default(Feature);
            BomFeature swBomFeat = default(BomFeature);
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swDraw = (DrawingDoc)swModel;
            swFeat = (Feature)swModel.FirstFeature();
 
            while ((swFeat != null))
            {
                if ("BomFeat" == swFeat.GetTypeName())
                {
                    Debug.Print("Feature Name: " + swFeat.Name);
                    swBomFeat = (BomFeature)swFeat.GetSpecificFeature2();
                    ProcessBomFeature(swApp, swModel, swBomFeat);
                }
                swFeat = (Feature)swFeat.GetNextFeature();
            }
        }
 
 
        public SldWorks swApp;
 
    }
}

本篇文章到此结束,我们下篇文章再见。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/814792.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

phpMyadmin 设置显示完整内容

额外选项这里&#xff0c;默认部分内容改成完整内容 方案&#xff1a; 版本>4.5.4.1&#xff0c;修改文件&#xff1a;config.inc.php&#xff0c;添加一行代码&#xff1a; if ( !isset($_REQUEST[pftext])) $_REQUEST[pftext] F;

浮点数的表示

王道考研ppt总结&#xff1a; 二、个人理解 浮点数解决的是定点数的位数局限&#xff0c;导致表示范围有限的问题 阶码&#xff1a;由阶符和数值部分组成&#xff0c;阶符为&#xff0c;小数点向左移动&#xff0c;否则向右移动&#xff1b;数值部分&#xff0c;是底数的几次幂…

区块链媒体推广的8个成功案例解析-华媒舍

区块链领域作为一个新兴行业&#xff0c;媒体推广对于项目的成功发展起着至关重要的作用。本文将从八个成功案例中来分析区块链媒体推广的重要性和成功策略。 1. 媒体报道对于区块链项目的重要影响 媒体报道是提升区块链项目知名度和用户认可度的重要手段。对于区块链项目来说…

Java | Leetcode Java题解之第25题K个一组翻转链表

题目&#xff1a; 题解&#xff1a; class Solution {public ListNode reverseKGroup(ListNode head, int k) {ListNode hair new ListNode(0);hair.next head;ListNode pre hair;while (head ! null) {ListNode tail pre;// 查看剩余部分长度是否大于等于 kfor (int i 0…

CSS3新增

一些CSS3新增的功能 课程视频链接 目录 CSS3概述私有前缀长度单位remvwvhvmaxvmin 颜色设置方式rgbahslhsla 选择器动态伪类目标伪类语言伪类UI伪类结构伪类否定伪类伪元素 盒子属性box-sizing问题插播 宽度与设置的不同 resizebox-shadowopacity 背景属性background-originb…

SDK-0.7.8-Release-实体管理 - ApiHug-Release

&#x1f917; ApiHug {Postman|Swagger|Api...} 快↑ 准√ 省↓ GitHub - apihug/apihug.com: All abou the Apihug apihug.com: 有爱&#xff0c;有温度&#xff0c;有质量&#xff0c;有信任ApiHug - API design Copilot - IntelliJ IDEs Plugin | Marketplace 更多精彩…

大数据存储解决方案和处理流程——解读大数据架构(四)

文章目录 前言数据存储解决方案数据集市运营数据存储&#xff08;Operational Data Store&#xff09;数据中心 数据处理数据虚拟化和数据联合虚拟化作为 ETL 或数据移动的替代品数据目录数据市场 前言 在数字时代&#xff0c;数据已成为公司的命脉。但是&#xff0c;仅仅拥有…

CNN卷积神经网络:理论基础、核心架构与多元应用

CNN是一种深度学习模型&#xff0c;利用卷积层提取图像特征&#xff0c;池化层降维与增强不变性&#xff0c;全连接层实现分类/回归。核心理论包括局部感知、权值共享、多层抽象。广泛应用图像识别、目标检测、语义分割、生成任务等领域。 一、CNN理论基础 1、局部感知野&…

二叉树之遍历

概述 之前有说到二叉树的建树&#xff0c;这次讲讲二叉树的遍历过程。二叉树的遍历分为深度优先遍历和广度优先遍历&#xff0c;二叉树的逻辑结构如下所示&#xff1a; class TreeNode{int val;TreeNode left;TreeNode right;public TreeNode(){}public TreeNode(int val){thi…

dPET论文笔记

PBPK论文笔记 题目&#xff1a;Self-supervised Learning for Physiologically-Based Pharmacokinetic Modeling in Dynamic PET 摘要 动态正电子发射断层扫描成像 &#xff08;dPET&#xff09; 提供示踪剂的时间分辨图像。从 dPET 中提取的时间活动曲线 &#xff08;TAC&a…

Spring Boot统一功能处理(一)

本篇主要介绍Spring Boot的统一功能处理中的拦截器。 目录 一、拦截器的基本使用 二、拦截器实操 三、浅尝源码 初始化DispatcherServerlet 处理请求&#xff08;doDispatch) 四、适配器模式 一、拦截器的基本使用 在一般的学校或者社区门口&#xff0c;通常会安排几个…

(我的创作纪念日)[MySQL]数据库原理7——喵喵期末不挂科

希望你开心&#xff0c;希望你健康&#xff0c;希望你幸福&#xff0c;希望你点赞&#xff01; 最后的最后&#xff0c;关注喵&#xff0c;关注喵&#xff0c;关注喵&#xff0c;大大会看到更多有趣的博客哦&#xff01;&#xff01;&#xff01; 喵喵喵&#xff0c;你对我真的…

无酒不水浒,无肉不江湖

很难想象&#xff0c;没有酒的《水浒传》&#xff0c;将会是什么样儿&#xff1f; 武松醉打蒋门神&#xff0c;小霸王醉入销金帐、杨雄醉骂潘巧云&#xff0c;诸如此类&#xff0c;都是水浒传中经典的酒故事&#xff0c;倘若离开了酒&#xff0c;水浒少的就不仅仅是故事了&…

头歌-机器学习实验 第8次实验 决策树

第1关&#xff1a;什么是决策树 任务描述 本关任务&#xff1a;根据本节课所学知识完成本关所设置的选择题。 相关知识 为了完成本关任务&#xff0c;你需要掌握决策树的相关基础知识。 引例 在炎热的夏天&#xff0c;没有什么比冰镇后的西瓜更能令人感到心旷神怡的了。现…

【Linux实践室】Linux高级用户管理实战指南:用户所属组变更操作详解

&#x1f308;个人主页&#xff1a;聆风吟_ &#x1f525;系列专栏&#xff1a;Linux实践室、网络奇遇记 &#x1f516;少年有梦不应止于心动&#xff0c;更要付诸行动。 文章目录 一. ⛳️任务描述二. ⛳️相关知识2.1 &#x1f514;Linux查看用户所属组2.1.1 &#x1f47b;使…

《UE5_C++多人TPS完整教程》学习笔记31 ——《P32 角色移动(Character Movement)》

本文为B站系列教学视频 《UE5_C多人TPS完整教程》 —— 《P32 角色移动&#xff08;Character Movement&#xff09;》 的学习笔记&#xff0c;该系列教学视频为 Udemy 课程 《Unreal Engine 5 C Multiplayer Shooter》 的中文字幕翻译版&#xff0c;UP主&#xff08;也是译者&…

IntelliJ IDEA 2024 for Mac/Win:引领Java开发新纪元的高效集成环境

在日新月异的软件开发领域&#xff0c;一款高效、智能的集成开发环境&#xff08;IDE&#xff09;无疑是程序员们不可或缺的神兵利器。今天&#xff0c;我要为大家介绍的&#xff0c;正是这样一款集大成之作——IntelliJ IDEA 2024。无论是Mac用户还是Windows用户&#xff0c;只…

全球AI顶会NeurlPS开始收高中生论文了

ChatGPT狂飙160天&#xff0c;世界已经不是之前的样子。 新建了免费的人工智能中文站https://ai.weoknow.com 新建了收费的人工智能中文站https://ai.hzytsoft.cn/ 更多资源欢迎关注 卷高考之后的下一步&#xff0c;卷论文&#xff1f; 培养 AI 人才&#xff0c;要从娃娃抓起&…

Spark-Scala语言实战(16)

在之前的文章中&#xff0c;我们学习了三道任务&#xff0c;运用之前学到的方法。想了解的朋友可以查看这篇文章。同时&#xff0c;希望我的文章能帮助到你&#xff0c;如果觉得我的文章写的不错&#xff0c;请留下你宝贵的点赞&#xff0c;谢谢。 Spark-Scala语言实战&#x…