Open flycast opened 2 years ago
Your code is correct (it works fine for me). Just make sure that the ISketch is not a 3DSketch (in this case you need to use ISwSketch3D) and not null. Or just use ISwSketchBase for the common interface.
Thank you. These two versions just worked for me.
ISwApplication xCadSwApp = _application as ISwApplication;
var test = xCadSwApp.CreateObjectFromDispatch<ISwSketch2D>(sketch, xCadSwApp.Documents.Active);
var test1 = xCadSwApp.Documents.Active.CreateObjectFromDispatch<ISwSketch2D>(sketch);
Not sure if this is an issue or not. This is now working fine when I get an ISketch object coming from a Sketch in the Solidworks feature tree (as noted above). Now I am trying to get the ISwSketch2D in the same way but using the ISketch from the ISketchBlockDefinition:
var blockInstance = node.Feature.GetSpecificFeature2() as ISketchBlockInstance;
var blockDefinition = blockInstance.Definition as ISketchBlockDefinition;
var blockSketch = blockDefinition.GetSketch();
sketchFromDispatch = xCadSwApp.CreateObjectFromDispatch<ISwSketch2D>(blockSketch, xCadSwApp.Documents.Active);
It seems I am getting two different objects. If I get the ISketch from a sketch feature I get a com object. If I get an ISketch from ISketchBlockDefinition::GetSketch() I get a SketchClass. When I use the SketchClass it is not a pointer to the com object so the CreateObjectFromDispatch fails.
I need to convert a Solidworks sketch to an XCad.Solidworks.ISwSketch2D object.
As I understand I can use a pointer to a Solidworks Sketch to create a ISWxxxxxxx entity:
Only when I do this I get:
Is this a bug or am I not doing things right?
Summary: I need to get a ISwXXXXXX object from a pointer to a Solidworks object. How?