简体   繁体   English

从静态 void 中的接口或抽象类调用方法

[英]Call method from interface or abstract class within static void

I'm usually a javascript developer, but for my company I just started learning c# in order to use the CimatronE 13 API to develop custom command line PDM tools for this 3D modelling software.我通常是一名 javascript 开发人员,但对于我的公司,我刚刚开始学习 c#,以便使用 CimatronE 13 API 为这个 3D 建模软件开发自定义命令行 PDM 工具。

As I'm making progress understanding the programming language, there's this frustrating situation where I want to use an API endpoint method but I can't manage to get it working.随着我对编程语言的理解不断取得进展,在这种令人沮丧的情况下,我想使用 API 端点方法,但我无法使其正常工作。

The Cimatron documentation says the following: Cimatron 文档说明如下:

IPdm::GetRelatedDocuments IPdm::GetRelatedDocuments

Syntax : RelatedDocuments = GetRelatedDocuments ( DocumentPath );语法:RelatedDocuments = GetRelatedDocuments ( DocumentPath );

This method allows you to get related files from compound types of files, for example Assembly or Drawing.此方法允许您从复合类型的文件(例如装配或绘图)中获取相关文件。

Input : (String) DocumentPath, Path to file.输入:(字符串)DocumentPath,文件路径。 For example \\Documents\\Location\\Folder\\Document.例如\\Documents\\Location\\Folder\\Document。 The file must be Assembly or Drawing.该文件必须是装配体或工程图。

Return : (Variant) RelatedDocuments, Variant type array each element of which contain two dimensioned string type array of files related to selected one.返回:(Variant)RelatedDocuments,Variant 类型数组,其中每个元素包含与所选文件相关的二维字符串类型数组。


This looks pretty straight forward to me, so I tried calling it in multiple ways from within the static void Main() method, but I keep getting errors:这对我来说看起来很直接,所以我尝试从static void Main()方法中以多种方式调用它,但我不断收到错误:

var RelatedDocuments = interop.CimBaseAPI.IPdm.GetRelatedDocuments("path");

CS0120: An object reference is required for the non-static field, method, or property 'IPdm.GetRelatedDocuments(string)' CS0120:非静态字段、方法或属性“IPdm.GetRelatedDocuments(string)”需要对象引用

interop.CimBaseAPI.IPdm pdm = new interop.CimBaseAPI.IPdm();
var RelatedDocuments = pdm.GetRelatedDocuments("path");

CS0144: Cannot create an instance of the abstract class or interface 'IPdm' CS0144:无法创建抽象类或接口“IPdm”的实例

Any ideas?有任何想法吗? It's probably simple but I'm still a noob with c# :p这可能很简单,但我仍然是 c# 的菜鸟:p


EDIT:编辑:

Cimatron documentation about the interface interop.CimBaseAPI.IPdm : Cimatron 文档关于接口interop.CimBaseAPI.IPdm

Properties:特性:

Get Query (String, DocumentEnumType, DocumentEnumUnit ) Variant获取查询(字符串、DocumentEnumType、DocumentEnumUnit)变体

Methods:方法:

A lot, including Variant GetRelatedDocuments ( String )很多,包括Variant GetRelatedDocuments ( String )

As how I see it now... interop.CimatronE.IPdm is an interface and in order to use it's methods, we first need access to the Cimatron application.正如我现在所看到的... interop.CimatronE.IPdm是一个接口,为了使用它的方法,我们首先需要访问 Cimatron 应用程序。 Using the application object, we can use it's methods to get the desired interfaces such as IPdm and use their methods.使用 application 对象,我们可以使用它的方法来获取所需的接口,例如IPdm并使用它们的方法。

The following code gives no errors from the compiler but does when executing.下面的代码没有从编译器中给出错误,但在执行时有错误。 This seems to be related to version 13 of CimatronE, since the application object works just fine using version 12. A lot has changed between these versions which I think is the reason the API is not functioning properly, outdated.这似乎与 CimatronE 的 13 版有关,因为应用程序对象在使用 12 版时工作得很好。这些版本之间发生了很多变化,我认为这是 API 无法正常运行、过时的原因。

interop.CimAppAccess.AppAccess AppAcc = new interop.CimAppAccess.AppAccess();
interop.CimatronE.IApplication CimApp = /*(interop.CimatronE.IApplication)*/AppAcc.GetApplication();

interop.CimatronE.IPdm pdm = CimApp.GetPdm();

var RelatedDocuments = pdm.GetRelatedDocuments("path");
Console.WriteLine(RelatedDocuments);

Please correct me if I'm wrong!如果我错了,请纠正我! (since I just started and still learning c#) (因为我刚刚开始并且还在学习 c#)

I ran into this same issue with Cimatron 14. I needed to make some changes in Visual Studio for things run properly with Cimatron.我在使用 Cimatron 14 时遇到了同样的问题。我需要在 Visual Studio 中进行一些更改,以便使用 Cimatron 正常运行。

  • Run Visual Studio in administrator mode以管理员模式运行 Visual Studio
  • Set your Debug & Release Solution Platform to 'x64'将您的调试和发布解决方案平台设置为“x64”
  • It was also recommended to point the build path for release & debug to the same folder as the Cimatron references.还建议将发布和调试的构建路径指向与 Cimatron 引用相同的文件夹。 In my case 'C:\\Program Files\\3D Systems\\Cimatron\\14.0\\Program'.就我而言,'C:\\Program Files\\3D Systems\\Cimatron\\14.0\\Program'。 However my code appears to run fine without this.但是,如果没有这个,我的代码似乎运行良好。

I created the Cimatron Application with this code (VB.Net):我用这个代码 (VB.Net) 创建了 Cimatron 应用程序:

    Dim gAppAccess As New CIMAPPACCESSLib.AppAccess 'Define an AppAccess object to get running active application
    Dim gApp As CIMAPPACCESSLib.Application 'Define an Application object
    gApp = gAppAccess.GetApplication 'Getting running active application
    If gApp Is Nothing Then
        gApp = New CIMAPPACCESSLib.Application 'Creating a new instance of a Cimatron application
    End If

References: Interop.CIMAPPACCESSLib.dll & interop.CimServicesAPI.dll参考资料:Interop.CIMAPPACCESSLib.dll & interop.CimServicesAPI.dll

It is my understanding that Cimatron 15 may also requires some manifest changes.据我了解,Cimatron 15 可能还需要一些明显的更改。

There is some help information in the Cimatron program under Cimatrom Modules > Cimaton SDK that may be mildly helpful.在 Cimatron 程序中的 Cimatron模块 > Cimaton SDK下有一些帮助信息,可能会有一些帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM