FeatureManager對象的方法提供給我們創(chuàng)建各類特征,如FeatureManager:: FeatureCut4,F(xiàn)eatureManager:: FeatureExtrusion3筒狠,用于創(chuàng)建切除及拉伸特征汪诉。這種是采用FeatureManager的具體某個方法創(chuàng)建具體某類特征白胀。
其實(shí),F(xiàn)eatureManager還有一個通用方法可以創(chuàng)建各類特征:FeatureManager:: CreateFeature抚岗,此方法將傳入某個特征的特征數(shù)據(jù)對象或杠。
特征數(shù)據(jù)對象是什么?ExtrudeFeatureData2宣蔚,CircularPatternFeatureData向抢,RefAxisFeatureData都是特征數(shù)據(jù)對象,ExtrudeFeatureData2對應(yīng)的是凸臺拉伸及切除的特征數(shù)據(jù)胚委,CircularPatternFeatureData對應(yīng)的是特征圓周陣列的數(shù)據(jù)挟鸠,RefAxisFeatureData對應(yīng)的基準(zhǔn)軸的特征數(shù)據(jù)。
簡單來說亩冬,幾乎每種特征都有其對應(yīng)的特征數(shù)據(jù)對象艘希,其含義可以理解成如下圖的特征數(shù)據(jù)。故雖然我們可以直接通過尺寸修改硅急,去修改某些特征覆享,但是這種方法的修改范圍是有限的,而通過特征數(shù)據(jù)對象营袜,我們可以操作如下圖中各特征的各類參數(shù)撒顿。
實(shí)例1
如下圖,獲取模型中相關(guān)特征的特征數(shù)據(jù)對象
代碼實(shí)例
public static void GetFeatureData(ModelDoc2 SwDoc)
{
FeatureManager SwFeatMrg = SwDoc.FeatureManager;
object[] ObjFeats = SwFeatMrg.GetFeatures(true);
StringBuilder Sb = new StringBuilder("");
foreach (object ObjFeat in ObjFeats)
{
if (ObjFeat is Feature)
{
Feature SwFeat = (Feature)ObjFeat;
string FeatTypeName = SwFeat.GetTypeName2();//
if (FeatTypeName == "ICE")//
{
ExtrudeFeatureData2 rfd = SwFeat.GetDefinition();
if (rfd != null)
{
Sb.Append("【" + SwFeat.Name + "】特征數(shù)據(jù)對象: ExtrudeFeatureData2 \r\n");
}
}
else if (FeatTypeName == "Extrusion")//
{
ExtrudeFeatureData2 efd = SwFeat.GetDefinition();
if (efd != null)
{
Sb.Append("【" + SwFeat.Name + "】特征數(shù)據(jù)對象:ExtrudeFeatureData2\r\n");
}
}
else if (FeatTypeName == "RefAxis")//
{
RefAxisFeatureData rafd = SwFeat.GetDefinition();
if (rafd != null)
{
Sb.Append("【" + SwFeat.Name + "】特征數(shù)據(jù)對象:RefAxisFeatureData\r\n");
}
}
else if (FeatTypeName == "CirPattern")//
{
CircularPatternFeatureData cpfd = SwFeat.GetDefinition();
if (cpfd != null)
{
Sb.Append("【" + SwFeat.Name + "】特征數(shù)據(jù)對象:CircularPatternFeatureData\r\n");
}
}
SwFeat.GetDefinition();
}
}
System.Windows.MessageBox.Show(Sb.ToString().Trim());
}
運(yùn)行效果
實(shí)例分析
如果需要獲得特征對應(yīng)的特征數(shù)據(jù)對象荚板,我們先需要通過Feature:: GetTypeName2方法凤壁,獲得特征對應(yīng)的特征類型名稱吩屹,然后有針對性地使用Feature:: GetDefinition方法,獲得對應(yīng)的特征數(shù)據(jù)對象拧抖,從而進(jìn)一步獲取與修改特征對應(yīng)的參數(shù)煤搜。
實(shí)例2
對裝配體中的圓柱與方臺進(jìn)行圓周陣列
代碼示例
public static void CreateCircularPatternByFeatureData(ModelDoc2 SwDoc, string AxiName, List<string> CompontName)
{
FeatureManager SwFeatMrg = SwDoc.FeatureManager;
Feature SwAxiFeat = ((AssemblyDoc)SwDoc).FeatureByName(AxiName);
SwAxiFeat.Select2(false, 2);
foreach (string compname in CompontName)
{
Feature SwComp = ((AssemblyDoc)SwDoc).FeatureByName(compname);
SwComp.Select2(true, 1);
}
LocalCircularPatternFeatureData SwLocalCircularPatternFeatureData = SwFeatMrg.CreateDefinition((int)swFeatureNameID_e.swFmLocalCirPattern);
SwLocalCircularPatternFeatureData.TotalInstances = 3;
SwLocalCircularPatternFeatureData.EqualSpacing = true;
Feature SwCirPattern = SwFeatMrg.CreateFeature(SwLocalCircularPatternFeatureData);
SwDoc.ClearSelection2(true);
SwCirPattern.Name = "圓周陣列";
}
運(yùn)行效果
實(shí)例3
對實(shí)例2的陣列結(jié)果進(jìn)行修改,取消方臺部件的陣列徙鱼。
代碼示例
public static void ReviseFeatureData(ModelDoc2 SwDoc, string FeatureName, List<string> CompontName)
{
FeatureManager SwFeatMrg = SwDoc.FeatureManager;
Feature CircleParFeat = ((AssemblyDoc)SwDoc).FeatureByName(FeatureName);
LocalCircularPatternFeatureData SwLocalCircularPatternFeatureData = CircleParFeat.GetDefinition();
foreach (string compname in CompontName)
{
Feature SwComp = ((AssemblyDoc)SwDoc).FeatureByName(compname);
SwComp.Select2(true, 1);
}
bool sc = SwLocalCircularPatternFeatureData.AccessSelections(SwDoc, null);
if (sc)//進(jìn)入回退編輯狀態(tài)
{
try
{
Feature[] CompFeats = new Feature[CompontName.Count];
for (int i = 0; i < CompontName.Count; i++)
{
Feature SwComp = ((AssemblyDoc)SwDoc).FeatureByName(CompontName[i]);
CompFeats[i] = SwComp;
}
SwLocalCircularPatternFeatureData.SeedComponentArray = CompFeats;
CircleParFeat.ModifyDefinition(SwLocalCircularPatternFeatureData, SwDoc, null);
}
catch//出錯就退出修改
{
SwLocalCircularPatternFeatureData.ReleaseSelectionAccess();
}
}
}
運(yùn)行效果
實(shí)例分析:
使用特征數(shù)據(jù)對象的AccessSelections方法讓特征處于編輯狀態(tài)宅楞,此時,即可對特征數(shù)據(jù)對象中的參數(shù)進(jìn)行修改袱吆,所有參數(shù)修改完畢后厌衙,通過Feature:: ModifyDefinition完成對特征的修改。如果需要取消修改绞绒,則使用特征數(shù)據(jù)對象的ReleaseSelectionAccess方法即可婶希。