我在使用Selection控件的block对象调用PickPoint(),编译出现了这个错误error C2039: 'PickPoint' : is not a member of 'NXOpen::BlockStyler::UIBlock'
时间: 2024-03-27 13:35:15 浏览: 45
Discord-Selection-Menu:我在代码中留下了错误 xd
是的,您在使用Selection控件的block对象调用PickPoint时会出现这个错误,因为Selection控件的block对象是UIBlock类型的对象,而UIBlock类型并没有PickPoint函数。
要在BlockStyler中使用PickPoint函数,您可以使用BlockStyler::Utilities::PickPoint方法,该方法可用于选择工作区中的点,并返回所选点的坐标。
下面是一个使用BlockStyler::Utilities::PickPoint的示例代码:
```cpp
#include "NXOpen/BlockStyler_UIBlock.hxx"
#include "NXOpen/BlockStyler.hxx"
#include "NXOpen/NXMessageBox.hxx"
#include "NXOpen/Part.hxx"
#include "NXOpen/PartCollection.hxx"
#include "NXOpen/Point.hxx"
#include "NXOpen/Point3d.hxx"
#include "NXOpen/Selection.hxx"
#include "NXOpen/SelectionResponse.hxx"
#include "NXOpen/TaggedObject.hxx"
using namespace NXOpen;
using namespace NXOpen::BlockStyler;
class MyClass
{
public:
static void OnButtonClick(const NXOpen::BlockStyler::UIBlock* block)
{
Part* workPart = NXOpen::Session::GetSession()->Parts()->Work();
// 获取Selection控件的block对象
UIBlock* selectionBlock = block->FindBlock("mySelection");
Selection* selection = static_cast<Selection*>(selectionBlock->GetReference());
// 获取选择的点的坐标
Point3d pickedPoint = BlockStyler::Utilities::PickPoint(workPart);
// 将选择的点的坐标设置为选择集中的对象的坐标
SelectionResponse::ObjectInfo objectInfo;
selection->PickObject("Select an object", "Point", Selection::SelectionScope::AnyInAssembly,
Selection::SelectionAction::ClearAndEnableSpecific, false, false, objectInfo);
TaggedObject* pickedObject = TaggedObject::GetTaggedObject(objectInfo.objectTag);
Point* point = dynamic_cast<Point*>(pickedObject);
if (point != nullptr)
{
point->SetCoordinates(pickedPoint.X, pickedPoint.Y, pickedPoint.Z);
workPart->ModelingViews()->WorkView()->Regenerate();
}
}
};
extern "C" DllExport int ufusr_ask_unload()
{
return (int)Session::LibraryUnloadOptionImmediately;
}
extern "C" DllExport void ufusr(char* param, int* retCode, int paramLen)
{
NXOpen::Part* part = NXOpen::Session::GetSession()->Parts()->BaseWork();
NXOpen::BlockStyler::BlockDialog* dialog = NXOpen::BlockStyler::BlockDialog::Create();
NXOpen::BlockStyler::UIBlock* selectionBlock = dialog->TopBlock()->FindBlock("mySelection");
selectionBlock->SetDouble("MinimumWidth", 120.0);
selectionBlock->SetLogical("AllowMultiple", false);
selectionBlock->SetAllowedClass("Point");
NXOpen::BlockStyler::UIBlock* button = dialog->TopBlock()->FindBlock("myButton");
button->SetDouble("MinimumWidth", 120.0);
button->SetHandler(MyClass::OnButtonClick);
dialog->Show();
delete dialog;
}
```
在上面的示例中,我们首先获取Selection控件的block对象,然后获取Selection对象。接下来,我们使用BlockStyler::Utilities::PickPoint方法选择一个点,并将选择的点的坐标设置为选择集中的对象的坐标。请注意,我们使用SelectionResponse::ObjectInfo和TaggedObject类获取所选对象,并将其转换为Point类以设置其坐标。
最后,我们更新显示以查看结果。
阅读全文