How can I pass an object array to activex (SolidEdge)?

2 views (last 30 days)

I am using matlab to control (through ActiveX) another application: SolidEdge. The SolidEdge guide contains only examples for visual basic, therefore I must suit the VB code for the Matlab language. I have a problem with all the methods that have as input the generic class "Object" that in matlab doesn't exist

Example

Public Function AddByObjects(ByVal ObjectCount As Long, _
 ByRef Objects() As Object, _
 ByVal xFlood As Double, _
 ByVal yFlood As Double _
) As Boundary2d

Considering that the generic class "Object" doesn't exist in Matlab, I have tried to use in a variable of generic class "handle" but it doesn't work and I get the following error

No method 'AddByObjects' with matching signature found for class
'Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d'.

if the length of input is 1, the error change

Error using
Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d/AddByObjects
Error: Type mismatch, argument 2

Here is the Guide example code in VB

Private Sub Form_Load()
    Dim objApp As SolidEdgeFramework.Application
    Dim objDoc As SolidEdgeDraft.DraftDocument
    Dim objSheet As SolidEdgeDraft.Sheet
    Dim objCompStrn As SolidEdgeFrameworkSupport.ComplexStrings2d
    Dim objL1 As SolidEdgeFrameworkSupport.Line2d
    Dim objL2 As SolidEdgeFrameworkSupport.Line2d
    Dim objL3 As SolidEdgeFrameworkSupport.Line2d
    Dim objBObjs(1 To 3) As Object
    ' Report errors
    Const PI = 3.14159265358979
    ' Create/get the application with specific settings
    On Error Resume Next
    Set objApp = GetObject(, "SolidEdge.Application")
    If Err Then
        Err.Clear
        Set objApp = CreateObject("SolidEdge.Application")
        Set objDoc = objApp.Documents.Add("SolidEdge.DraftDocument")
        objApp.Visible = True
    Else
        Set objDoc = objApp.ActiveDocument
    End If
    On Error GoTo 0
    'Get the Active Sheet object
    Set objSheet = objDoc.ActiveSheet
    'Get the ComplexStrings2d object on the active sheet
    Set objCompStrn = objSheet.ComplexStrings2d
    'Draw few lines on the active sheet
    Set objL1 = objSheet.Lines2d.AddBy2Points(x1:=0.1, y1:=0.1, x2:=0.2, y2:=0.2)
    Set objL2 = objSheet.Lines2d.AddBy2Points(x1:=0.2, y1:=0.2, x2:=0.4, y2:=0.2)
    Set objL3 = objSheet.Lines2d.AddBy2Points(x1:=0.4, y1:=0.2, x2:=0.5, y2:=0.1)
    ' Store the Line objects in an Array
    Set objBObjs(1) = objL1
    Set objBObjs(2) = objL2
    Set objBObjs(3) = objL3
    ' Create a ComplexString2d object
    Call objCompStrn.AddByObjects(ArraySize:=3, Members:=objBObjs())
    ' USER DISPLAY  
    ' Release objects
    Set objApp = Nothing
    Set objDoc = Nothing
    Set objSheet = Nothing
    Set objCompStrn = Nothing
    Set objL1 = Nothing
    Set objL2 = Nothing
    Set objL3 = Nothing
    Set objBObjs(1) = Nothing
    Set objBObjs(2) = Nothing
    Set objBObjs(3) = Nothing
End Sub

Here is my equivalent code in Matlab

% Create/get the application with specific settings
try
    % Se esiste una sessione aperta collegati con quella 
    objApp = actxGetRunningServer('SolidEdge.Application');
catch
    % Altrimenti aprine una nuova
    objApp = actxserver('SolidEdge.Application');
end
objApp.Visible = 1;
% Get the Active Sheet object
objDoc = objApp.Documents.Add('SolidEdge.DraftDocument');
% Get the Active Sheet object
objSheet = objDoc.ActiveSheet;
% Get the ComplexStrings2d object on the active sheet
objCompStrn = objSheet.ComplexStrings2d;
% Draw few lines on the active sheet
objL1 = objSheet.Lines2d.AddBy2Points(0.1,0.1,0.2,0.2);
objL2 = objSheet.Lines2d.AddBy2Points(0.2,0.2,0.4,0.2);
objL3 = objSheet.Lines2d.AddBy2Points(0.4,0.2,0.5,0.1);
% Store the Line objects in an Array
objBObjs(1,1) = objL1;
objBObjs(2,1) = objL2;
objBObjs(3,1) = objL3;
% Create a ComplexString2d object
objCompStrn.AddByObjects(1,objBObjs)
  8 Comments
Guillaume
Guillaume on 28 Apr 2018
I'm afraid I'm out of ideas. It's not clear if matlab fails to properly convert the cell array into a SAFEARRAY or if it's the content of the SAFEARRAY that is not correct.
If you can, I would suggest you raise a support request with Mathworks.

Sign in to comment.

Accepted Answer

Andrea Carignano
Andrea Carignano on 21 Jan 2019
MathWorks support and documentation were not so useul I suggest to improve them.
Anyway I was able to solve the problem after many attempts changing the approach from COM to .NET. Now this code works:
clear;close all; clc;
% Loading .NET libraries
SEF = NET.addAssembly('C:\Program Files\Solid Edge ST5\Custom\SELibrary\bin\Interop.SolidEdgeFramework.dll');
SEFS = NET.addAssembly('C:\Program Files\Solid Edge ST5\Custom\SELibrary\bin\Interop.SolidEdgeFrameworkSupport.dll');
SED = NET.addAssembly('C:\Program Files\Solid Edge ST5\Custom\CustomSensor\bin64\Interop.SolidEdgeDraft.dll');
% Connecting with SolidEdge
objType = System.Type.GetTypeFromProgID('SolidEdge.Application');
objApp = SolidEdgeFramework.Application(System.Activator.CreateInstance(objType));
objApp.Visible = true;
% Creating new document
objDoc = SolidEdgeDraft.DraftDocument(objApp.Documents.Add('SolidEdge.DraftDocument'));
objSheet = objDoc.ActiveSheet;
% Get the ComplexStrings2d object on the active sheet
objCompStrn = objSheet.ComplexStrings2d;
% Draw few lines on the active sheet
objL1 = objSheet.Lines2d.AddBy2Points(0.1,0.1,0.2,0.2);
objL2 = objSheet.Lines2d.AddBy2Points(0.2,0.2,0.4,0.2);
objL3 = objSheet.Lines2d.AddBy2Points(0.4,0.2,0.5,0.1);
% Store the Line objects in an Array
objBObjs = NET.createArray('System.Object',3);
objBObjs(1) = objL1;
objBObjs(2) = objL2;
objBObjs(3) = objL3;
% Create a ComplexString2d object
objCompStrn.AddByObjects(3, objBObjs)

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!