The add-in wizard generates all the required connection code automatically. We recommend that you start with the skeleton code produced by the wizard.
COM add-ins receive an IDispatch
interface pointer for the Creo Elements/Direct Modeling
server application in their OnConnection method
and can use this pointer to contact the server:
#import "OsdmServer.tlb" raw_interfaces_only named_guids namespace CoCreate { #import "OsdmObjects.tlb" raw_dispinterfaces rename_namespace("Osdm") } STDMETHODIMP CXmlStructure::OnConnection(IDispatch *pApplication, ConnectMode /* cMode */, IDispatch *pAddInInst, SAFEARRAY ** /*custom*/ ) { // Query main application interface CComQIPtr<CoCreate::Osdm::IApplication> pIApplication = pApplication; // Now use this interface to get to other interfaces CComQIPtr<CoCreate::Osdm::IFrame> pIFrame = pIApplication; ... }
Add-ins may also be written in any .NET language, e.g. VB.NET or C#. We provide an add-in wizard for C# and recommend that you start with the skeleton code produced by the wizard.
Like a COM add-in, the .NET add-in must implement the IOsdmAddin
interface. The add-in will be called on this interface when the add-in is activated.
Note that the .NET add-in class and all functions that are to be used by other add-ins or
Lisp code must be marked with ComVisible(true)
. We also advise to assign a GUID to
the add-in class and to derive it from MarshalByRefObject
.
using CoCreate; using CoCreate.Osdm; namespace MyCompanyName { ////// A sample OSDM .NET add-in /// [Guid("6E28F71F-2638-418f-A117-72F6CD4BF53C"), ComVisible(true)] public class MyOsdmAddin : MarshalByRefObject, IOsdmAddin { private IApplication _app; #region IOsdmAddin Implementation public void OnConnection(object app, ConnectMode cMode, object AddInInst, ref object[] custom) { // keep a reference to the appplication object _app = (IApplication)app; ... } ... #endregion #region COM Dispatch callable methods [ComVisible(true)] public bool MyAddinFunction() { ... } #endregion } }
#import "OsdmServer.tlb" raw_interfaces_only named_guids namespace CoCreate { #import "OsdmObjects.tlb" raw_dispinterfaces rename_namespace("Osdm") } int main(int argc, char *argv[]) { ::CoInitialize(0); { CComPtr<CoCreate::Osdm::IApplication> pIAppl; pIAppl.CoCreateInstance(T2COLE("CoCreate.OsdmServer")); // now do something with the interfaces } ::CoUninitialize(); return 0; }
Sub ConnectToOsdmServer() Dim OsdmApp As CoCreate_OsdmObjects.IApplication Set OsdmApp = CreateObject("CoCreate.OsdmServer") OsdmApp.LoadFile("c:/temp/foo.pkg") End Sub
Set Osdm=CreateObject("CoCreate.OsdmServer") MsgBox("Server version: " & Osdm.Version)
External clients can control precisely which server version to instantiate by using a library function provided with our API. The ExtClientUtility library implements the following API:
HRESULT ConnectToOsdm(ServerType serverType, const char *minVersion, const char *maxVersion, unsigned long reserved, IApplication **ppIAppl);
ServerType describes the type of server which the clients wants to instantiate. For example, if the client requires full 3D modeling capability, it needs to specify ServerType_DesignerModeling. If other server packages, such as stripped-down viewer versions, are also acceptable, the client can ask for ServerType_Any. On systems which have multiple server versions installed, ConnectToOsdm will always prefer the most capable package (usually Creo Elements/Direct Modeling) and the highest installed version.
Some usage examples for C++ clients:
CComPtrpIAppl = 0; // Try to instantiate OSDM 16.00-17.00 HRESULT hr = ConnectToOsdm(ServerType_DesignerModeling, "16.00", "17.00", 0, &pIAppl); // 3DAccess 16.00 and higher HRESULT hr = ConnectToOsdm(ServerType_3DAccess, "16.00", 0, 0, &pIAppl); // anything up to version 16.00 HRESULT hr = ConnectToOsdm(ServerType_Any, 0, "16.00", 0, &pIAppl);
VB usage:
Dim hr as Long Dim ppIAppl As CoCreate.Osdm.IApplication rem Run any type of server, version 16.00 and above hr = ConnectToOsdm(CoCreate.ServerType.ServerType_Any, "16.00", "", 0, ppIAppl);
ConnectToOsdm will scan the system for installed versions and pick a matching version according to the version and server type constraints specified. If successful, it returns an IApplication interface pointer.
If the client does not specify a version, ConnectToOsdm tries to find an active (running) instance of the server based on the ServerType and connects to it. If there is no active instance of the server, the function will scan the system for the highest installed server version based on the ServerType, and will instantiate that version.
To use ConnectToOsdm, the external client needs to link against the ExtClientUtility.dll library. C++ clients need to include the ExtClientUtility.h header file; VB clients can use the following declaration:
Private Declare Ansi Function ConnectToOsdm Lib "ExtClientUtility.dll" ( _ ByVal svType As CoCreate.ServerType, _ ByVal minVersion As String, _ ByVal maxVersion As String, _ ByVal reserved As Long, _ ByRef ppIAppl As CoCreate.Osdm.IApplication) As Long
Not supported in this release.