Description
In this lesson you will learn more about the IComponent interface, inserting and editing parts, and bounding boxes. For the example, a new solid is inserted to engulf the bounding box of a selected component(s). This is based on a macro used in robotic simulations to simplify the boundaries of surrounding equipment.
Notes
Use IComponent2::GetSelectByIDString to get the string that is needed for use with IModelDocExtension::SelectByID2.
Use IModelDocExtension::DeleteSelection2 instead of IModelDoc2::EditDelete if you need to prevent the “Confirm Delete” dialog box from appearing.
Regarding lightweight components: you cannot access data in a lightweight component like you can in a fully resolved component. To identify a lightweight component and change its state from lightweight to resolved or vice versa, use IComponent2::GetSuppression and IComponent2::SetSuppression. Also note that using IComponent2::IsHidden and IComponent2::IsSuppressed both return true if the component is lightweight. To resolve all LW components, use IAssemblyDoc::ResolveAllLightWeightComponents. See the API Help article “Working with Lightweight Components” for more information.
Concerning exploded views, you have the option of creating an exploded view automatically or manually. To create it automatically, use IAssemblyDoc::AutoExplode. This method, however, sometimes produces unsatisfactory results. If that is the case then you can modify the individual explode steps that were created using IConfiguration::GetExplodeStep or IConfiguration::DeleteExplodeStep. The former method returns an IExplodeStep object, which contains members for controlling explode step options. If you wish to create all of the explode steps from scratch, use IConfiguration::AddExplodeStep. Finally, you can count the number of explode steps with IConfiguration::GetNumberOfExplodeSteps or add explode sketch lines with ISketchManager::InsertExplodeLineSketch.
Using Pack and Go is easy to use with the SolidWorks API. Use IModelDocExtension::GetPackAndGo to get an IPackAndGo object, with which you can modify all of the Pack and Go options. Then use that object as the argument in IModelDocExtension::SavePackAndGo to actually create the folder or compressed file.
Use IComponent2::GetModelDoc2 to get the underlying IModelDoc2 pointer for a component. Note that this will return Nothing if the component is suppressed, lightweight, opened via SpeedPak, or excluded from Selective Open in Large Design Review Mode.
When adding or modifying a feature in the context of an assembly, use the active model pointer only (the pointer to the assembly). Do not use the IModelDoc2 obtained through IComponent2::GetModelDoc2 or you could run into serious problems later. Instead, once that IModelDoc2 pointer is obtained through IComponent2::GetModelDoc2, use IComponent2::GetCorresponding to bring the pointer into the assembly context. Alternatively, you could first call IAssemblyDoc::EditPart2 and then modify the feature through the active document pointer.