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

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

相关推荐
晨非辰40 分钟前
#C语言——学习攻略:深挖指针路线(三)--数组与指针的结合、冒泡排序
c语言·开发语言·数据结构·学习·算法·排序算法·visual studio
一只小风华~4 小时前
JavaScript 函数
开发语言·前端·javascript·ecmascript·web
苕皮蓝牙土豆4 小时前
Qt 分裂布局:QSplitter 使用指南
开发语言·qt
Brookty7 小时前
Java线程安全与中断机制详解
java·开发语言·后端·学习·java-ee
從南走到北8 小时前
JAVA东郊到家按摩服务同款同城家政服务按摩私教茶艺师服务系统小程序+公众号+APP+H5
android·java·开发语言·微信小程序·小程序
遇见尚硅谷9 小时前
C语言:20250728学习(指针)
c语言·开发语言·数据结构·c++·笔记·学习·算法
☆璇9 小时前
【C++】C/C++内存管理
c语言·开发语言·c++
愿你天黑有灯下雨有伞9 小时前
枚举策略模式实战:优雅消除支付场景的if-else
java·开发语言·策略模式
网络安全打工人9 小时前
CentOS7 安装 rust 1.82.0
开发语言·后端·rust
楚轩努力变强9 小时前
前端工程化常见问题总结
开发语言·前端·javascript·vue.js·visual studio code