I want to get the plane where the hole is located, I try to get the face through the feature, but it is the face inside the hole feature, not the plane where the hole is located. Later, I pass the plane of the special hole feature, and first call the AccessSelection method, but still can not get the plane where the hole is located.
ModelDoc2 swModel = (ModelDoc2)swApp.ActiveDoc;
if (feature.GetTypeName2() == "HoleWzd")
{
WizardHoleFeatureData2 wizardHoleFeature = (WizardHoleFeatureData2)feature.GetDefinition();
if (wizardHoleFeature != null)
{
// Access selections
wizardHoleFeature.AccessSelections(swModel, null);
// Get the IWizardHoleFeatureData2 interface
// Try to get the face
Face2 endConditionFace = (Face2)wizardHoleFeature.Face;
if (endConditionFace != null)
{
// Successfully got the face, proceed with your operations
// e.g., getting face properties or geometry
Debug.Print("Successfully retrieved the face.");
}
else
{
// Face is still null, handle the case
Debug.Print("The end condition face is null.");
}
// Release selections
wizardHoleFeature.ReleaseSelectionAccess();
}
else
{
Debug.Print("Failed to find the feature.");
}
feature.getface is not what i want
To obtain the referenced plane, you'll have to dig down to the sketch created by the Hole Wizard Feature.
var swSketchPoints = IWizardHoleFeatureData2.GetSketchPoints();
var swSketch = swSketchPoints[0].GetSketch();
var refEntity = swSketch.GetReferenceEntity(out int lEntityType);
if (lEntityType == swSelectType_e.swSelDATUMPLANES)
{
var swPlane = refEntity as IPlane;
}
Once you have the base entity, you can cast it to the type returned by the GetReferenceEntity
as outlined on the SW swSelectType_e API help page