How do I create a .NET Array of COM objects from MATLAB?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm working with a COM API (for Siemens Solid Edge ST2) that requires a .NET array of objects to be passed to a particular method.
In Visual Basic .NET, one would do it as such (starting with an object objProfile, which is of a class Profile exposed by the COM API) ( note this is VB.NET code, not MATLAB) :
' Create a new array of profile objects, with just one object in it:
aProfiles = Array.CreateInstance(GetType(SolidEdgePart.Profile, 1)
aProfiles.SetValue(objProfile, 0)
' Use the array in a method:
objRevolve = objPart.Models.AddFiniteRevolvedProtrusion(1, _
aProfiles, objZAxis, 'igRight', 2.0*pi) ;
This revolves a profile around the Z-axis. But that's not the important part, the important part is that the method AddFiniteRevolvedProtrusion() expects a .NET Array for its second argument, not the Profile object itself.
Now, I have objProfile and objZAxis in MATLAB (as handles), but if I try to call the AddFiniteRevolvedProtrusion() method, it fails (this is now MATLAB code):
objRevolve = objPart.Models.AddFiniteRevolvedProtrusion(1, ...
objProfile, objZAxis, 'igRight', 2.0*pi) ;
Error using Interface.Solid_Edge_Part_Sync_Type_Library.Models/AddFiniteRevolvedProtrusion
Error: Type mismatch, argument 2
The error on argument 2 is because the method expects an array, not just the one object (objProfile).
I can't seem to use the System.Array.CreateInstance() because MATLAB doesn't allow direct use of the abstract .NET classes, it fails with the error:
Error using System.Array
Creating an instance of the Abstract class 'System.Array' is not allowed.
Nor can I use NET.convertArray (this works only on numeric MATLAB arrays). If I try:
objProfileArray = NET.convertArray(objProfile)
it fails with this error:
Conversion from 'Interface.Solid_Edge_Part_Sync_Type_Library.Profile' array type is not supported.
as would be expected.
Should I be using NET.createArray or NET.createGeneric instead? Thanks for any help people can provide.
Réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!