怡宁塑胶模具设计

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C++

//用户头文件

#include <NXOpen/Features_Block.hxx>
#include <NXOpen/Features_ChamferBuilder.hxx>
#include <NXOpen/Features_Feature.hxx>
#include <NXOpen/Features_FeatureBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/DisplayManager.hxx>
#include <NXOpen/DisplayModification.hxx>
#include <NXOpen/DisplayableObject.hxx>
#include <NXOpen/Features_BlockFeatureBuilder.hxx>
#include <NXOpen/Edge.hxx>
#include <NXOpen/EdgeDumbRule.hxx>
#include <NXOpen/Features_EdgeBlendBuilder.hxx>
#include <NXOpen/ScCollector.hxx>
#include <NXOpen/ScCollectorCollection.hxx>
#include <NXOpen/ScRuleFactory.hxx>
#include <NXOpen/SelectionIntentRule.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <NXOpen/EdgeMultipleSeedTangentRule.hxx>

 

 

//用户代码
Session *theSession = Session::GetSession(); //获取绘画窗口
Part *workPart = theSession->Parts()->Work();//获取工作部件
Part *displayPart = theSession->Parts()->Display();//获取显示部件

//创建空特征
Features::Feature *nullNXOpen_Features_Feature(NULL);
Features::BlockFeatureBuilder *blockFeatureBuilder1;
blockFeatureBuilder1 = workPart->Features()->CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);
//设置block参数
blockFeatureBuilder1->SetType(Features::BlockFeatureBuilder::TypesOriginAndEdgeLengths);
Point3d originPoint1(0.0, 0.0, 0.0);
blockFeatureBuilder1->SetOriginAndLengths(originPoint1, "30", "40", "50");
//创建
Features::Feature *feature1;
feature1 = blockFeatureBuilder1->CommitFeature();

blockFeatureBuilder1->Destroy(); //释放block

//转换
Features::Block *bodys(dynamic_cast<Features::Block*> (feature1)); //方体特征转换body

vector<Body *> body1(1);//定义体容器
vector<Edge *> edges ;//定义边容器
vector<Face *> faces;//定义竖面容器
vector<Edge *> vertacledge;//定义竖边容器
vector<Edge *> horizontaledge;//定义水平边容器

if(bodys != NULL)
{
body1 = bodys->GetBodies();
edges = bodys->GetEdges();
faces = bodys->GetFaces();
}


//输出边和边端点的信息

Edge *edge1;
NXOpen::Edge::EdgeType type;
double len;
char msg[60];
NXOpen::Point3d p1;//端点1
NXOpen::Point3d p2;//端点2

theSession->ListingWindow()->Open(); //打开信息窗口
for(int i=0;i < edges.size();i++ )
{
edge1 = edges[i];
//edge1->Highlight(); //高亮所有邊
type = edge1->SolidEdgeType(); //获取类型
len = edge1->GetLength(); //获取长度
edge1->GetVertices(&p1,&p2); //由边获取端点
sprintf(msg,"类型:%d\n",type);
theSession->ListingWindow()->WriteLine(msg);
sprintf(msg,"长:%.2f.\n",len);
theSession->ListingWindow()->WriteLine(msg);
sprintf(msg,"x:%.2f.y:%.2f.z:%.2f.\n",p1.X,p1.Y,p1.Z);
theSession->ListingWindow()->WriteLine(msg);
sprintf(msg,"x:%.2f.y:%.2f.z:%.2f.\n\n",p2.X,p2.Y,p2.Z);
theSession->ListingWindow()->WriteLine(msg);

if ( len == 50 )
{
vertacledge.push_back(edges[i]); //通过边长判断把竖边塞到竖边容器
}
else
{
horizontaledge.push_back(edges[i]);//通过边长判断把水平边塞到水平边容器

}


}

//创建倒圆
Features::Feature *nullNXOpen_Features_Feature2(NULL); //创建空特征
Features::EdgeBlendBuilder *edgeBlendBuilder1;
edgeBlendBuilder1 = workPart->Features()->CreateEdgeBlendBuilder(nullNXOpen_Features_Feature2);

//创建集合
NXOpen::ScCollector *scCollector1;
scCollector1 = workPart->ScCollectors()->CreateCollector();

//边数组加到
EdgeMultipleSeedTangentRule *edgeMultipleSeedTangentRule1;
edgeMultipleSeedTangentRule1 = workPart->ScRuleFactory()->CreateRuleEdgeMultipleSeedTangent(vertacledge, 0.05, true);

std::vector<SelectionIntentRule *> rules1(1);
rules1[0] = edgeMultipleSeedTangentRule1;
scCollector1->ReplaceRules(rules1, false);

edgeBlendBuilder1->AddChainset(scCollector1, "3"); //设置半径
Features::Feature *feature2 = edgeBlendBuilder1->CommitFeature(); //创建


edgeBlendBuilder1->Destroy(); //释放倒圆

//创建倒角
Features::Feature *nullFeatures_Feature3(NULL); //创建空特征
Features::ChamferBuilder *chamferBuilder1;
chamferBuilder1 = workPart->Features()->CreateChamferBuilder(nullFeatures_Feature3);
//设置倒角参数
chamferBuilder1->FirstOffsetExp()->SetRightHandSide("3");
chamferBuilder1->SecondOffsetExp()->SetRightHandSide("3");
chamferBuilder1->AngleExp()->SetRightHandSide("45");
chamferBuilder1->SetOption(Features::ChamferBuilder::ChamferOptionSymmetricOffsets);
chamferBuilder1->SetMethod(Features::ChamferBuilder::OffsetMethodEdgesAlongFaces);
chamferBuilder1->SetFirstOffset("3");
chamferBuilder1->SetSecondOffset("3");
chamferBuilder1->SetAngle("45");
chamferBuilder1->SetTolerance(0.001);

//创建集合
NXOpen::ScCollector *scCollector2;
scCollector2 = workPart->ScCollectors()->CreateCollector();
//线数组加到
EdgeMultipleSeedTangentRule *edgeMultipleSeedTangentRule2;
edgeMultipleSeedTangentRule2 = workPart->ScRuleFactory()->CreateRuleEdgeMultipleSeedTangent(horizontaledge, 0.05, true);

std::vector<SelectionIntentRule *> rules2(1);
rules2[0] = edgeMultipleSeedTangentRule2;
scCollector2->ReplaceRules(rules2, false);

chamferBuilder1->SetSmartCollector(scCollector2);

Features::Feature *feature3 = chamferBuilder1->CommitFeature(); //创建

chamferBuilder1->Destroy(); //释放倒角

 

 

posted on 2021-01-03 14:31  怡宁塑胶模具设计  阅读(666)  评论(0编辑  收藏  举报