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

大家好,今天要介绍的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 camera
            swCamera = (Camera)swModelDocExt.InsertCamera();
 
            // Print out camera settings
            Debug.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

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

相关推荐
尼古拉斯-托尔斯泰-赵四13 分钟前
Go 语言,你需要了解的一些规则
开发语言·后端·golang
亨得利先生23 分钟前
户外双目3D相机哪家好?SICK Visionary 系列户外选型指南与 Visionary-B Two 分析
数码相机·相机·户外相机·户外3d相机·sick
郝学胜-神的一滴43 分钟前
C++20 高级编程 004:从初始化、内存到const系列关键字
开发语言·算法·编程·软件构建·c++20
雪芽蓝域zzs44 分钟前
Vue3 + JS + pnpm 创建项目
开发语言·javascript·ecmascript
一晌小贪欢1 小时前
Python办公16:PDF 强力缝合——将几十个 PDF 合并为单个文档并添加页码
开发语言·python·excel·数据可视化·python办公
名剑走天下1 小时前
Kotlin_LiveData
开发语言·kotlin
迷迭香yy1 小时前
回测过拟合检测体系从样本内外到组合稳健性评估 IG50免费开源股票数据API接口
服务器·开发语言·数据库·人工智能·python
zmzb01031 小时前
C++课后习题训练记录Day199
开发语言·c++
Zane1994121 小时前
`ClassName()` 只是一步?拆开看 `__new__` 和 `__init__` 各自在干什么
开发语言·python