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

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 commentaires

In the output of
methods SolidEdgeFrameworkSupport.ComplexStrings2d -full
can you show us the signature for AddByObjects?
I get:
>> methods SolidEdgeFrameworkSupport.ComplexStrings2d -full
No class SolidEdgeFrameworkSupport.ComplexStrings2d.
But if I use this
>> methods(objCompStrn,'-full')
Methods for class Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d:
handle AddByObjects(handle, int32, SafeArray(handle))
handle Item(handle, Variant)
addproperty(handle, string)
delete(handle, MATLAB array)
deleteproperty(handle, string)
MATLAB array events(handle, MATLAB array)
MATLAB array get(handle)
MATLAB array get(handle, MATLAB array, MATLAB array)
MATLAB array get(handle vector, MATLAB array, MATLAB array)
MATLAB array invoke(handle)
MATLAB array invoke(handle, string, MATLAB array)
MATLAB array loadobj(handle)
release(handle, MATLAB array)
MATLAB array saveobj(handle)
MATLAB array set(handle)
MATLAB array set(handle, MATLAB array, MATLAB array)
MATLAB array set(handle vector, MATLAB array, MATLAB array)
I specify that the features "COM_SafeArraySingleDim" and "COM_PassSafeArrayByRef" are already set
feature('COM_SafeArraySingleDim',1);
feature('COM_PassSafeArrayByRef',1);
Hum, that signature
handle AddByObjects(handle, int32, SafeArray(handle))
Doesn't match this one at all:
Public Function AddByObjects(ByVal ObjectCount As Long, _
ByRef Objects() As Object, _
ByVal xFlood As Double, _
ByVal yFlood As Double _
) As Boundary2d
How come?
However, it does match your call:
objCompStrn.AddByObjects(1,objBObjs)
Do all of these:
objCompStrn.AddByObjects(1, objObjs)
objCompStrn.AddByObjects(1, {objL1, objL2, objL3})
invoke(objCompStrn, 'AddByObjects', 1, objObjs)
invoke(objCompStrn, 'AddByObjects', 1, {objL1, objL2, objL3})
result in the same error No method with matching signature found?
Sorry, it's my mistake. This method
Public Function AddByObjects(ByVal ObjectCount As Long, _
ByRef Objects() As Object, _
ByVal xFlood As Double, _
ByVal yFlood As Double _
) As Boundary2d
is not related to the example code. This one is the correct one
Public Function AddByObjects( _
ByVal ArraySize As Long, _
ByRef members() As Object _
) As ComplexString2d
I tried all your suggested command and I get:
>> objCompStrn.AddByObjects(1, objBObjs)
No method 'AddByObjects' with matching signature
found for class
'Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d'.
>> objCompStrn.AddByObjects(1, {objL1, objL2, objL3})
Error using
Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d/AddByObjects
Error: Type mismatch, argument 2
>> invoke(objCompStrn, 'AddByObjects', 1, objBObjs)
Error using
Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d/invoke
No method 'AddByObjects' with matching signature
found for class
'Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d'.
>> invoke(objCompStrn, 'AddByObjects', 1, {objL1, objL2, objL3})
Error using
Interface.Solid_Edge_FrameworkSupport_Type_Library_ComplexStrings2d/AddByObjects
Error: Type mismatch, argument 2
Guillaume
Guillaume le 27 Avr 2018
Modifié(e) : Guillaume le 27 Avr 2018
Well, it gets a bit further with the cell array syntax. At least it calls the function.
If you turn the two COM_SafeArraySingleDim and COM_PassSafeArrayByRef do you get the same type mismatch error (with the cell array syntax)?
Andrea Carignano
Andrea Carignano le 27 Avr 2018
Modifié(e) : Andrea Carignano le 27 Avr 2018
I've tried every combination of these parameters but unfortunately nothing changes, errors are exactly the same...
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.
Thanks for the help anyway

Connectez-vous pour commenter.

 Réponse acceptée

Andrea Carignano
Andrea Carignano le 21 Jan 2019

0 votes

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)

Plus de réponses (0)

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by