C# Solidworks二次开发:相机访问相关API详解

news/2025/3/15 5:15:14/

大家好,今天要介绍的API为相机相关的API,这篇文章比较适合女孩子,学会了相机就会拍照了,哈哈。

下面是要介绍的API:

(1)第一个为GetFocalDistance,这个API的含义为获取相机的焦距,下方是官方的具体解释:

其API没有输入参数,只有返回值为相机的焦距。使用的时候还是先看备注,非常重要,非常重要,非常重要,重要的事情说三遍。

下面是官方使用的例子:

This example shows how to insert a camera and print out its settings.

//---------------------------------------------------------------
// Preconditions:
// 1. Open a model document that does not have any cameras inserted.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Inserts a camera in the model document.
// 2. Click View > Lights and Cameras > Properties > Camera1.
// 3. Click Zoom to Fit.
// 4. Examine the Immediate window, the graphics area, and the
//    Camera1 PropertyManager page.
//-------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;namespace Macro1CSharp.csproj
{public partial class SolidWorksMacro{public void Main(){ModelDoc2 swModel = default(ModelDoc2);ModelDocExtension swModelDocExt = default(ModelDocExtension);Camera swCamera = default(Camera);swModel = (ModelDoc2)swApp.ActiveDoc;swModelDocExt = (ModelDocExtension)swModel.Extension;// Insert a cameraswCamera = (Camera)swModelDocExt.InsertCamera();// Print out camera settingsDebug.Print("ID                                               = " + swCamera.ID);Debug.Print("Focal distance                                   = " + swCamera.GetFocalDistance() * 1000.0 + " mm");Debug.Print("Perspective mode                                 = " + swCamera.Perspective);Debug.Print("Depth of field effects enabled                   = " + swCamera.DepthOfFieldEnabled);Debug.Print("Distance from focal plane to where focus is lost = " + swCamera.DepthOfFieldOffset * 1000.0 + " mm");Debug.Print("Horizontal angle of the field of view            = " + swCamera.FieldOfViewAngle * 1000.0 + " mm");Debug.Print("Depth of the field of view                       = " + swCamera.FieldOfViewDepth * 1000.0 + " mm");Debug.Print("Height of the field of view                      = " + swCamera.FieldOfViewHeight * 1000.0 + " mm");}/// <summary>///  The SldWorks swApp variable is pre-assigned for you./// </summary>public SldWorks swApp;}
}

(2)第二个为GetPosition,这个API的含义为获取相机的当前位置,下面是官方的具体解释:

其没有输入值,返回值为相机的当前位置IMathPoint。

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


http://www.ppmy.cn/news/1426815.html

相关文章

【在线OJ系统】自定义注解实现分布式ID无感自增

实现思路 首先自定义参数注解&#xff0c;然后根据AOP思想&#xff0c;找到该注解作用的切点&#xff0c;也就是mapper层对于mapper层的接口在执行前都会执行该aop操作&#xff1a;获取到对于的方法对象&#xff0c;根据方法对象获取参数列表&#xff0c;根据参数列表判断某个…

python应用

划分数据集 将数据集划分为训练集和测试集 import os import shutil import random # 数据集路径 images_dir ./images targets_dir ./gt # 划分后的路径 train_images_dir ./train/images test_images_dir ./test/images train_targets_dir ./train/gt test_ta…

Jackson 2.x 系列【25】Spring Boot 集成之起步依赖、自动配置

有道无术&#xff0c;术尚可求&#xff0c;有术无道&#xff0c;止于术。 本系列Jackson 版本 2.17.0 本系列Spring Boot 版本 3.2.4 源码地址&#xff1a;https://gitee.com/pearl-organization/study-jaskson-demo 文章目录 1. 前言2. 起步依赖3. 自动配置3.1 JacksonPrope…

软考139-上午题-【软件工程】-软件容错技术

一、软件容错技术 提高软件质量和可靠性的技术大致可分为两类&#xff0c;一类是避开错误&#xff0c;即在开发的过程中不让差错潜入软件的技术&#xff1b;另一类是容错技术&#xff0c;即对某些无法避开的差错&#xff0c;使其影响减至最小的技术。 1-1、容错软件的定义 归…

2024 年江苏省职业院校技能大赛“区块链技术应用” 赛项赛卷(样卷)运维题解析一

运维题 环境: ubuntu20 fisco 2.8.0 前言 准备两台机子,并且可以能相互pin通 192.168.19.133 [M1-A] 192.168.19.137 [M2-B] 子任务 1-2-1: 搭建区块链系统并验证 基于给定服务器环境以及软件,搭建一条双机 1 机构 8 节点 1 群组的区块 链系统(默认端口开始[30300,2020…

算法刷题记录 Day49

算法刷题记录 Day49 Date: 2024.04.17 lc 5. 最长回文子串 class Solution { public:string longestPalindrome(string s) {// 1. dp. dp[i][j]表示s[i:j]是否是回文子串。// dp[i][j] s[i] s[j] && dp[i1][j-1];int n s.size();vector<vector<bool>>…

【iOS】—— SDWebImage源码学习(1)(未完)

iOS】—— SDWebImage源码学习 SDWebImage基础使用主要功能获取图片缓存缓存机制 SDWebImage SDWebImage具有缓存支持的异步映像下载程序。并添加了像UI元素分类类UIImageView、UIButton、MKAnnotationView&#xff0c;可以直接为这些UI元素添加图片。 基础使用 在日常的使用中…

04 JavaScript学习:输出

JavaScript 没有任何打印或者输出的函数。 JavaScript 显示数据 JavaScript 可以通过不同的方式来输出数据&#xff1a; 使用 window.alert() 弹出警告框。使用 document.write() 方法将内容写到 HTML 文档中。使用 innerHTML 写入到 HTML 元素。使用 console.log() 写入到浏…