How can I pass an object array to activex (SolidEdge)?
2 views (last 30 days)
Show older comments
Andrea Carignano
on 19 Apr 2018
Answered: Andrea Carignano
on 21 Jan 2019
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
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.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!