Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swConfMgr As SldWorks.ConfigurationManager Dim swConf As SldWorks.Configuration Dim swRootComp As SldWorks.Component2 Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Set swConfMgr = swModel.ConfigurationManager Set swConf = swConfMgr.ActiveConfiguration Set swRootComp = swConf.GetRootComponent3(True) End Sub
The reason why IEntity.GetComponent() return NULL because it works for an Assembly only not for a Part. Below is the screenshot of API help remark for IEntity.GetComponent().
One way you can get the IComponent2 from IPartDoc is:
1. Create a dummy assembly using ISldWorks.NewDocument method. You may not have to save the assembly.
2. Use IAssemblyDoc.AddComponent5 method to add your part into the assembly. This method automatically returns IComponent2 object.
3. Destroy or not save the dummy assembly.
There may be a better solution but I am sure it will work for you now.
I don't know, in previous versions (before 2013) has this root component limited functionality. Maybe is the help text not updated.