AnsweredAssumed Answered

Custom OpenGL Rendering of SW MacroFeature objects

Question asked by Yc Lim on Feb 17, 2016
Latest reply on Feb 18, 2016 by Yc Lim

Hello,

I'm a C++/C# developer but completely new to Solidworks and just started learning the API.   My goal is to create a solidworks addin that can import in STL meshes and Point clouds and render them in OpenGL similar to the ScanToCAD addin.

 

So by downloading the examples online I am able to create a working C# addin and implemented some basic OpenGL rendering to make sure everything works however, the Solidworks object model is very confusing to me so I'm unsure how to best solve my problem.

 

1) I want to use InsertMacroFeature3 as my standin object to represent the mesh that I will import in the Solidworks tree. This appears to work but how do i track the Transform of my objects and render it in the right position by OGL?  Right now my test object is unrotated and resting at 0,0,0 so my OGL rendering is of course correct. If i move or rotate the object inside of solidworks, I need to be able to track and update my rendering.

 

Simply put, i need to track down the 3D world position of my object in Solidworks space and be able to apply that transform when i render in openGL, but I'm very confused the functionality in objects between ModelDoc, Features, Bodies, and Component2 objects.  It looks like the Commponent2 object is able to get me a transform but I have no ideal how to get there the Feature / Body that I have.  I tried using the Feature.GetSpecificFeature2 and casting it as recommended but it always returns null.

 

2) Best way to add custom data to a Feature / object in the world?

I'm able to create a  custom objects in to the feature tree using InsertMacroFeature3, it appears this is the best way to approach things, however I wish to tag my feature with additional variable data.  I thought i could setup a separate lookup table using Feature.GetID but i'm unsure what would happen on document save / open. I'm guessing i need to save out my data separately somewhere? Alternatively i can use DefineAttribute / and then the solidworks Attribute function to get back the data. However, iFeature.GetSpecificFeature2  when cast back to an IAttribute always returns back null.  So i'm able to store the feature, but I can't seem to read the feature back.  I followed this example here, but instead of attaching the attribute to the face, i just attached it straight to the feature.

 

http://help.solidworks.com/2012/English/api/sldworksapi/Add_Attribute_to_Feature_and_Include_in_Library_Feature_Example_CSharp.htm

 

This is all new to me so i'm unsure if I'm approaching the problem correctly.

 

Thanks for any help

Outcomes