Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

slideValue is to slow

2 REPLIES 2
Reply
Message 1 of 3
FlyPT
278 Views, 2 Replies

slideValue is to slow

Hi,

 

Posting again, first was considered spam, don't know why.

I'm developing a software to control motion rigs for simulators.

There, we calculate the actuators positions.

The idea is to send those positions to Fusion360 and preview the result in the model.

Many use Fusion to design their rig, and that was a way to preview the result.

 

So I made a C DLL to get the values from shared memory, and update the joints.

Problem is that each time I update the joints, it takes around 3 seconds to update it in Fusion360.

Is there a way to make it faster?

 

The software:

Sem nome.jpg

 

 

 

 

 

 

 

 

Message box shows elapsed time to set 6 sliders...

 

The current code to test it:

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
#include <Fusion/Components/RevoluteJointMotion.h>
#include <Fusion/Components/SliderJointMotion.h>
#include <Fusion/Components/Component.h>

#include <windows.h>  // for mmf
#include <string>
#include <iostream>
#include <chrono>

using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;



Ptr<Application> app;
Ptr<UserInterface> ui;


HANDLE hMMF; // Memory file
LPVOID data; // Mapped view
const DWORD BUF_SIZE = 6; // Size of the info we are sending for now just bytes


extern "C" XI_EXPORT bool run(const char* context)
{
	app = Application::get();
	if (!app)
		return false;

	ui = app->userInterface();
	if (!ui)
		return false;

	// Get data from the shared memory
	hMMF = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"TESTEMMF");
	data = MapViewOfFile(hMMF, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);

	Ptr<Product> product = app->activeProduct();
	if (!product)
		return false;

	Ptr<Design> design = product;
	if (!design)
		return false;

	// Get the root component of the active design
	Ptr<Component> rootComp = design->rootComponent();
	if (!rootComp)
		return false;

	Ptr<Joints> joints = rootComp->joints();
	if (!joints)
		return false;

	// Get joints by name
	Ptr<SliderJointMotion> axis1a = joints->itemByName("Axis1a")->jointMotion();
	if (!axis1a)
		return false;
	Ptr<SliderJointMotion> axis2a = joints->itemByName("Axis2a")->jointMotion();
	if (!axis1a)
		return false;
	Ptr<SliderJointMotion> axis3a = joints->itemByName("Axis3a")->jointMotion();
	if (!axis1a)
		return false;
	Ptr<SliderJointMotion> axis4a = joints->itemByName("Axis4a")->jointMotion();
	if (!axis1a)
		return false;
	Ptr<SliderJointMotion> axis5a = joints->itemByName("Axis5a")->jointMotion();
	if (!axis1a)
		return false;
	Ptr<SliderJointMotion> axis6a = joints->itemByName("Axis6a")->jointMotion();
	if (!axis1a)
		return false;

	char text[200];
	double mult = 127.0/250.0;
	while (true)
	{

		// -250 to 250 in the joints 250->127
		std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
		
			double k = (((byte*)data)[0] - 127) * mult;
			axis1a->slideValue(k);

			k = (((byte*)data)[1] - 127) * mult;
			axis2a->slideValue(k);

			k = (((byte*)data)[2] - 127) * mult;
			axis3a->slideValue(k);

			k = (((byte*)data)[3] - 127) * mult;
			axis4a->slideValue(k);

			k = (((byte*)data)[4] - 127) * mult;
			axis5a->slideValue(k);

			k = (((byte*)data)[5] - 127) * mult;
			axis6a->slideValue(k);


			std::chrono::steady_clock::time_point middle = std::chrono::steady_clock::now();
			sprintf(text, "Elapsed: %dµs", std::chrono::duration_cast<std::chrono::microseconds>(middle - begin).count());
			if (ui->messageBox(text, "Test", adsk::core::MessageBoxButtonTypes::OKCancelButtonType, adsk::core::MessageBoxIconTypes::QuestionIconType) == adsk::core::DialogResults::DialogCancel) return true;

			adsk::doEvents();
	}



	return true;
}

#ifdef XI_WIN

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

 

2 REPLIES 2
Message 2 of 3
FlyPT
in reply to: FlyPT

So I would like to add that:

 

Moving the joint in the interface is smooth,

but moving it from the API with slideValue is really slow.

 

Can't we go over the slideValue and avoid some calculations to make it faster?

I'm sorry, been looking around for a solution, but might be something out of the usual if possible.

 

Sorry for my ignorance in this.

But would love to have some light to follow at the end of the tunnel 🙂

Thank's

Message 3 of 3
FlyPT
in reply to: FlyPT

Small video with drag vs API:

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report