Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I encountered a weird bug, in the command upon body selection I change its opacity. When selecting the faces of the body, the opacity of that body changes back for some reason. This does not happen if body selection input has lower limit of more than 0.
Demo code:
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <sstream>
using namespace adsk::core;
using namespace adsk::fusion;
Ptr<Application> app;
Ptr<UserInterface> ui;
// InputChange event handler.
class OnInputChangedEventHander : public InputChangedEventHandler
{
public:
void notify(const Ptr<InputChangedEventArgs>& eventArgs) override
{
Ptr<CommandInput> cmdInput = eventArgs->input();
if (!cmdInput)
return;
if (cmdInput->id() == "DemoBodySelectionInputId")
{
Ptr<SelectionCommandInput> selectionInput = cmdInput;
if (selectionInput->selectionCount() > 0)
{
Ptr<BRepBody> body = selectionInput->selection(0)->entity();
body->opacity(0.4);
}
}
}
};
// CommandCreated event handler.
class CommandCreatedEventHandler : public adsk::core::CommandCreatedEventHandler
{
public:
void notify(const Ptr<CommandCreatedEventArgs>& eventArgs) override
{
if (eventArgs)
{
// Get the command that was created.
Ptr<Command> command = eventArgs->command();
if (command)
{
// Connect to the input changed event.
Ptr<InputChangedEvent> onInputChanged = command->inputChanged();
if (!onInputChanged)
return;
const auto isOk = onInputChanged->add(&onInputChangedHandler);
if (!isOk)
return;
const auto commandInputs = command->commandInputs();
const auto bodySelection = commandInputs->addSelectionInput("DemoBodySelectionInputId", "Body selection", "");
bodySelection->addSelectionFilter("Bodies");
bodySelection->setSelectionLimits(0, 1); //Changing minimum to 1 solves the problem for some reason
const auto faceSelection = commandInputs->addSelectionInput("DemoFaceSelectionInputId", "Face selection", "");
faceSelection->addSelectionFilter("Faces");
faceSelection->setSelectionLimits(1);
}
}
}
private:
OnInputChangedEventHander onInputChangedHandler;
} _cmdCreatedHandler;
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
// Create the command definition.
Ptr<CommandDefinitions> commandDefinitions = ui->commandDefinitions();
if (!commandDefinitions)
return nullptr;
// Get the existing command definition or create it if it doesn't already exist.
Ptr<CommandDefinition> cmdDef = commandDefinitions->itemById("cmdInputsSample");
if (!cmdDef)
{
cmdDef = commandDefinitions->addButtonDefinition("cmdInputsSample",
"Command Inputs Sample",
"Sample to demonstrate various command inputs.");
}
// Connect to the command created event.
Ptr<CommandCreatedEvent> commandCreatedEvent = cmdDef->commandCreated();
if (!commandCreatedEvent)
return false;
commandCreatedEvent->add(&_cmdCreatedHandler);
// Execute the command definition.
cmdDef->execute();
return true;
}
#ifdef XI_WIN
#include <windows.h>
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // XI_WIN
Screencast:
Solved! Go to Solution.