读取电极属性,创建注释

发布时间:2024年01月23日

#include <uf.h>
#include <NXSigningResource.cpp>
#include <uf_drf.h>
#include <uf_ui.h>
#include <uf_attr.h>
#include<uf_obj.h>
#include<uf_part.h>
#include<uf_ugfont.h>
#include<string>
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Annotations_AnnotationManager.hxx>
#include <NXOpen/Annotations_BreakSettingsBuilder.hxx>
#include <NXOpen/Annotations_DimensionStyleBuilder.hxx>
#include <NXOpen/Annotations_DraftingNoteBuilder.hxx>
#include <NXOpen/Annotations_ForeshorteningSymbolBuilder.hxx>
#include <NXOpen/Annotations_ForeshorteningSymbolSettingsBuilder.hxx>
#include <NXOpen/Annotations_FrameBarElementStyleBuilder.hxx>
#include <NXOpen/Annotations_FrameBarStyleBuilder.hxx>
#include <NXOpen/Annotations_HatchStyleBuilder.hxx>
#include <NXOpen/Annotations_HoleCalloutSettingsBuilder.hxx>
#include <NXOpen/Annotations_LeaderBuilder.hxx>
#include <NXOpen/Annotations_LeaderData.hxx>
#include <NXOpen/Annotations_LeaderDataList.hxx>
#include <NXOpen/Annotations_LetteringStyleBuilder.hxx>
#include <NXOpen/Annotations_LineArrowStyleBuilder.hxx>
#include <NXOpen/Annotations_Note.hxx>
#include <NXOpen/Annotations_OrdinateStyleBuilder.hxx>
#include <NXOpen/Annotations_OriginBuilder.hxx>
#include <NXOpen/Annotations_PlaneBuilder.hxx>
#include <NXOpen/Annotations_RadialStyleBuilder.hxx>
#include <NXOpen/Annotations_SingleSidedDisplayBuilder.hxx>
#include <NXOpen/Annotations_StyleBuilder.hxx>
#include <NXOpen/Annotations_SymbolStyleBuilder.hxx>
#include <NXOpen/Annotations_TextWithEditControlsBuilder.hxx>
#include <NXOpen/Annotations_TextWithSymbolsBuilder.hxx>
#include <NXOpen/Annotations_UnitsStyleBuilder.hxx>
#include <NXOpen/BasePart.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/DisplayableObject.hxx>
#include <NXOpen/Drawings_DraftingView.hxx>
#include <NXOpen/Drawings_SelectDraftingView.hxx>
#include <NXOpen/FontCollection.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/ObjectList.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/SelectDisplayableObject.hxx>
#include <NXOpen/SelectDisplayableObjectList.hxx>
#include <NXOpen/SelectObject.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/TaggedObject.hxx>
#include <NXOpen/Xform.hxx>
#include <NXOpen/NXObjectManager.hxx>
using namespace NXOpen;
void ufusr(char*parm, int*returnCode, int rlen)
{

//遍历实体,读取实体属性ELE_F_SG的值,就是电极的精工。
?? ?UF_initialize();?? ??? ?
?? ?tag_t BodyTag = NULL_TAG;
?? ?UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &BodyTag);//? ?
?? ?char name[256];
?? ?UF_OBJ_ask_name(BodyTag, name);//? ? ??
?? ?UF_ATTR_value_t value1;
?? ?UF_ATTR_read_value(BodyTag, "ELE_F_SG", UF_ATTR_any, &value1);//??

? //转换一下DOUBLE,去掉后置0,因为电极使用外挂属性。低版本的属性值后面有0,去掉显得简洁。

?? ?double AA=atof(value1.value.string);

?? ?char BB[256];

?? ?sprintf(BB,"%.2g",AA);

?//创建?注释 ,电极名称+火花间隙

?? ?char* TextString[] = { strcat(name,BB) };//? ?
?? ?double Origin3d[3] = { 0,8,0 };//?
?? ?tag_t NoteTag = NULL_TAG;
?? ?UF_DRF_create_note(1, TextString, Origin3d, 0, &NoteTag);//? ??
?? ?UF_OBJ_set_color(NoteTag, 186);//? ? ??
?? ?UF_OBJ_set_name(NoteTag, "F");// ?

//设置字体和大小,? ??
?? ?NXOpen::Session *theSession = NXOpen::Session::GetSession();
?? ?NXOpen::Part *workPart(theSession->Parts()->Work());
?? ?NXOpen::Part *displayPart(theSession->Parts()->Display());
?? ?NXOpen::Annotations::Note *note1(dynamic_cast<NXOpen::Annotations::Note *>(NXOpen::NXObjectManager::Get(NoteTag)));//? ??
?? ?NXOpen::Annotations::DraftingNoteBuilder *draftingNoteBuilder1;
?? ?draftingNoteBuilder1 = workPart->Annotations()->CreateDraftingNoteBuilder(note1);?? ?
?? ?int fontIndex1;
?? ?fontIndex1 = workPart->Fonts()->AddFont("blockfont_v1", NXOpen::FontCollection::TypeNx);//? ?
?? ?draftingNoteBuilder1->Style()->LetteringStyle()->SetGeneralTextFont(fontIndex1);//? ? ? ? ? ??
?? ?draftingNoteBuilder1->Style()->LetteringStyle()->SetGeneralTextSize(1.5);//?
?? ?draftingNoteBuilder1->Style()->LetteringStyle()->SetGeneralTextCharSpaceFactor(0.5);//??
?? ?draftingNoteBuilder1->Style()->LetteringStyle()->SetGeneralTextAspectRatio(0.5);//??
?? ?NXOpen::NXObject *nXObject1;
?? ?nXObject1 = draftingNoteBuilder1->Commit();
?? ?draftingNoteBuilder1->Destroy();//??
?? ?UF_terminate();
}
int ufusr_ask_unload(void)
{
?? ?return (UF_UNLOAD_IMMEDIATELY);
}

//这个插件我已经用了

文章来源:https://blog.csdn.net/qq_57268243/article/details/135739269
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。