C# Solidworks二次开发:Pack And Go相关API详解(第二讲)

大家好,今天要介绍的是和打包相关的API,之前讲过一篇文章是关于打包时候的注意事项,这里就不再介绍了,有需要的家人可以访问前一个文章:

C# Solidworks二次开发:Pack and Go打包时需要注意的地方,纯干货(可以节省大量查找资料时间)-CSDN博客

下面介绍相关API:

(1)第一个为AddExternalDocument,这个API的含义为将非solidworks文件添加到打包或是移动中,下面是官方的具体解释:

其输入参数值只有一个为要添加到打包和移动的非solidworks文件的路径和文件名的数组,返回值为bool类型,成功为true,失败为false。

下面是官方使用的例子:

This example shows how to add SOLIDWORKS, render reference, and non-SOLIDWORKS files to Pack and Go. This example also shows how to remove a non-SOLIDWORKS file from Pack and Go.

//-------------------------------------------
// Preconditions:
// 1. Verify that the specified assembly exists.
// 2. Create c:\PackAndGo.
// 3. Open the Immediate window.
//
// Postconditions:
// 1. Gets the names of SOLIDWORKS, render reference, and
//    non-SOLIDWORKS files for Pack and Go.
// 2. Gets the the name of non-SOLIDWORKS file to remove.
// 3. Packs up SOLIDWORKS, render reference, and
//    non-SOLIDWORKS files and copies them to c:\PackAndGo.
// 4. Examine c:\PackAndGo and the Immediate window.
//-------------------------------------------

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace AddExternalDocumentsPackAndGo.csproj
{
    
partial class SolidWorksMacro
    {
        
public void Main()
        {
            ModelDoc2 swModel =
default(ModelDoc2);
            ModelDocExtension swModelDocExt =
default(ModelDocExtension);
            PackAndGo swPackAndGo =
default(PackAndGo);
            
string openFile = null;
            
int namesCount = 0;
            
int errors = 0;
            
int warnings = 0;
            
bool status = false;
            
int i = 0;
            
object[] renderReferences = null;
            
string myPath = null;
            
object statuses = null;

            
// Open assembly document
            openFile = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\EDraw\\claw\\claw-mechanism.sldasm";
            swModel = (ModelDoc2)swApp.OpenDoc6(openFile, (
int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_Silent, "", ref errors, ref warnings);
            swModelDocExt = (ModelDocExtension)swModel.Extension;

            
// Get Pack and Go object
            Debug.Print("Pack and Go");
            swPackAndGo = (PackAndGo)swModelDocExt.GetPackAndGo();

            
// Get number of documents in assembly
            namesCount = swPackAndGo.GetDocumentNamesCount();

            
// Get current paths and filenames of the assembly's documents
            object fileNames;
            
object[] pgFileNames = new object[namesCount - 1];
            status = swPackAndGo.GetDocumentNames(
out fileNames);
            pgFileNames = (
object[])fileNames;

            
Debug.Print("");
            
Debug.Print("  Add SOLIDWORKS files' paths and filenames: ");
            
if ((pgFileNames != null))
            {
                
for (i = 0; i <= pgFileNames.GetUpperBound(0); i++)
                {
                    
Debug.Print("    The path and filename is: " + pgFileNames[i]);
                }
            }

            
// Set document paths and names for Pack and Go
            status = swPackAndGo.SetDocumentSaveToNames(pgFileNames);

            
// Get the render stock references in this assembly
            // and print them to the Immediate window
            Debug.Print(" ");
            renderReferences = (
object[])swModelDocExt.GetRenderStockReferences();
            
Debug.Print("  Add render references:");
            
for (i = 0; i <= renderReferences.GetUpperBound(0); i++)
            {
                
Debug.Print("    The path and filename is: " + renderReferences[i]);
            }

            
// Add render stock files to Pack and Go
            status = swPackAndGo.AddExternalDocuments(renderReferences);

            
// Add other non-SOLIDWORKS files to Pack and Go
            object[] otherFiles = new object[2];
            
string otherFile = "C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\edraw\\claw\\claw-mechanism.easm";
            otherFiles[0] = (
object)otherFile;
            otherFile =
"C:\\Users\\Public\\Documents\\SOLIDWORKS\\SOLIDWORKS 2018\\samples\\tutorial\\edraw\\claw\\claw-mechanism.emodel_debugonly.xml";
            otherFiles[1] = (
object)otherFile;

            
Debug.Print(" ");
            
Debug.Print("  Add non-SOLIDWORKS files:");
            
for (i = 0; i <= otherFiles.GetUpperBound(0); i++)
            {
                
Debug.Print("    The path and filename is: " + otherFiles[i]);
            }

            
// Add non-SOLIDWORKS file to Pack and Go
            status = swPackAndGo.AddExternalDocuments(ObjectArrayToBStrWrapperArray(otherFiles));

            
// Remove one of the non-SOLIDWORKS files from Pack and Go
            object[] delOtherFiles = new object[1];
            delOtherFiles[0] = (
object)otherFiles[0];

            
Debug.Print(" ");
            
Debug.Print("  Remove non-SOLIDWORKS file:");
            
Debug.Print("    The path and filename is: " + delOtherFiles[0]);

            status = swPackAndGo.RemoveExternalDocuments(ObjectArrayToBStrWrapperArray(delOtherFiles));

            
// Override path where to save documents
            myPath = "c:\\PackAndGo\\";
            status = swPackAndGo.SetSaveToName(
true, myPath);

            
// Pack and Go both SOLIDWORKS and non-SOLIDWORKS files
            statuses = swModelDocExt.SavePackAndGo(swPackAndGo);
        }

        
public BStrWrapper[] ObjectArrayToBStrWrapperArray(object[] SwObjects)
        {
            
int arraySize;
            arraySize = SwObjects.GetUpperBound(0);
            
BStrWrapper[] dispwrap = new BStrWrapper[arraySize + 1];
            
int arrayIndex;

            
for (arrayIndex = 0; arrayIndex < arraySize + 1; arrayIndex++)
            {
                dispwrap[arrayIndex] =
new BStrWrapper((string)(SwObjects[arrayIndex]));
            }

            
return dispwrap;

        }

        
/// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>

        public SldWorks swApp;

    }
}

(2)第二个为GetDocumentNames,这个API的含义为获取打包和移动所有文件的名称,下面是官方的具体解释:

其输入参数值只有一个为要添加到打包和移动的非solidworks文件的路径和文件名的数组,返回值为bool类型,成功为true,失败为false。和上面的一致。

(3)第三个为GetDocumentSaveToNames,这个API的含义为获取保存模型文档的路径和模型名,下面是官方的具体解释:

输入参数有两个,分别为:

PathNameList
包含保存模型文档的路径和文件名的字符串数组(参见备注)
DocumentStatusList
包含swPackAndGoDocumentStatus_e中定义的文档类型的数组

其对应的类型有三个:

MemberDescription
swPackAndGoDocumentStatus_Normal0 = Normal
swPackAndGoDocumentStatus_UnKnown2 = Unknown
swPackAndGoDocumentStatus_Virtual1 = Virtual

本篇文章要介绍的API就是这些,我们下篇文章再见。

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

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

相关文章

设计模式代码实战-抽象工厂模式

1、问题描述 小明家新开了两个工厂用来生产家具&#xff0c;一个生产现代风格的沙发和椅子&#xff0c;一个生产古典风格的沙发和椅子&#xff0c;现在工厂收到了一笔订单&#xff0c;请你帮他设计一个系统&#xff0c;描述订单需要生产家具的信息。 输入试例&#xff1a; 3 …

lv_micropython to download and building

想要在ESP32-C3使用Micropython开发GUI&#xff0c;所以需要编译lv_micropython&#xff0c;当前github上的版本是9.1.0。 一、开发环境 因为编译lv_micropython需要在linux系统下&#xff0c;但是我的电脑是windows系统&#xff0c;所以我在windows系统上安装了VMware虚拟机&…

MongoDB的安装和使用

1.MongoDB 安装 1.1 基于Docker安装 docker run --restartalways -d --name mongo -v /opt/mongodb/data:/data/db -p 27017:27017 mongo:4.0.6 1.2 客户端工具使用 MongoDB Compass | MongoDB 2.MongoDB 使用 2.1 引用依赖包 <dependency><groupId>org.sprin…

mybiats-puls-插入测试以及雪花算法

一&#xff0c;测试 /* * 插入测试 * */ Test public void test01() {User user new User();/** 自动帮我们生成id* */user.setName("kuku");user.setAge(3);user.setEmail("2983394967qq.com");final int insert mapper.insert(user);System.out.print…

ES6基础(JavaScript基础)

本文用于检验学习效果&#xff0c;忘记知识就去文末的链接复习 1. ECMAScript介绍 ECMAScript是一种由Ecma国际&#xff08;前身为欧洲计算机制造商协会&#xff0c;英文名称是European Computer Manufacturers Association&#xff09;通过ECMA-262标准化的脚本程序设计语言…

基于SpringBoot的“汉服文化平台网站”的设计与实现(源码+数据库+文档+PPT)

基于SpringBoot的“汉服文化平台网站”的设计与实现&#xff08;源码数据库文档PPT) 开发语言&#xff1a;Java 数据库&#xff1a;MySQL 技术&#xff1a;SpringBoot 工具&#xff1a;IDEA/Ecilpse、Navicat、Maven 系统展示 系统功能结构图 系统功能界面图 用户登录、用…

推荐一款轻量级的hosts文件编辑器(免安装版)

在管理和编辑hosts文件时&#xff0c;一款简单而有效的工具是非常重要的。下面推荐一款免安装版的轻量级hosts文件编辑器&#xff0c;让你轻松管理你的hosts文件。 windows系统默认hosts文件位置 下载地址&#xff1a;https://www.alipan.com/s/8kSns9eAi9f

学习ArkTS -- 常用组件使用

学习ArkTS 使用Deveco studio写ArkTSImage: 图片显示组件1.声明Image组件并设置图片源2. 添加图片属性 Text: 文本显示组件1. 声明Text组件并设置文本内容2. 添加文本属性 TextInput&#xff1a;文本输入框1. 声明TextInput2. 添加属性和事件 Button 组件1. 声明Button组件&…

09 Php学习:超级全局变量

超级全局变量 PHP中预定义了几个超级全局变量&#xff08;superglobals&#xff09; &#xff0c;这意味着它们在一个脚本的全部作用域中都可用。 PHP 超级全局变量列表: $GLOBALS$_SERVER$_REQUEST$_POST$_GET$_FILES$_ENV$_COOKIE$_SESSION $GLOBALS $GLOBALS 是 PHP 中的…

微信ipad协议GO版本 最新不封号

支持A16&#xff0c;62数据号登录&#xff0c;长链接不掉线&#xff0c;稳定不封号。全新支持短信号登陆&#xff0c;并且支持扫码登录。可以获取小程序code、抢购、游戏试玩授权等功能。 以下是对登录和授权的一些方法&#xff1a; - getLoginQRCode (获取登录二维码) - Chec…

SpringCloud、SpringBoot、JDK版本对应关系

SpringCloud与SpringBoot 版本 官网说明&#xff1a;https://spring.io/projects/spring-cloud#overview SpringBoot 与 JDK版本关系 发布说明&#xff1a;https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Release-Notes SpringBoot 3.x不再支持JDK1.…

信号完整性之特性阻抗那些事儿

原文来自微信公众号&#xff1a;工程师看海&#xff0c;与我联系&#xff1a;chunhou0820 看海原创视频教程&#xff1a;《运放秘籍》 大家好&#xff0c;我是工程师看海。 我们经常说控制阻抗&#xff0c;这个阻抗是什么意思呢&#xff1f; 信号在传输线中&#xff0c;是一步…