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: 

Freezing sketch when I moved object (add-ins)

7 REPLIES 7
Reply
Message 1 of 8
raterWBBQB
217 Views, 7 Replies

Freezing sketch when I moved object (add-ins)

I use GUI library wxWidgets.

My add-ins have simple GUI(window and 1 button(create object)).

 

7 REPLIES 7
Message 2 of 8
marshaltu
in reply to: raterWBBQB

Hello,

 

It would be great if you can provide some sample codes and detailed steps to reproduce the issue you mentioned.

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 8
raterWBBQB
in reply to: marshaltu

main.cpp

 

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>

#include "MainWindow.h"

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

Ptr<Application> app;
Ptr<UserInterface> ui;
Ptr<Sketch> sketch;
Ptr<Component> rootComp;
Ptr<Sketches> sketches;

static wxAppConsole *wxCreateApp()
{
	wxAppConsole::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "my app");
	return new Win(rootComp);
}


void RunApp()
{
	wxApp::SetInitializerFunction(wxCreateApp);
	wxEntry(0, NULL);
}
extern "C" XI_EXPORT bool run(const char* context)
{
	Ptr<Application> app = Application::get();
	if (!app)
		return false;

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

	Ptr<Design> design = app->activeProduct();
	rootComp = design->rootComponent();
	sketches = rootComp->sketches();
	sketch = sketches->add(rootComp->xYConstructionPlane());
	
	

	RunApp();
	return true;
}

extern "C" XI_EXPORT bool stop(const char* context)
{
	if (ui)
	{
		ui->messageBox("Stop addin");
		ui = nullptr;
	}

	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

 

 

MainWindow.h

 

#pragma once
#include <wx\wx.h>
#include <Fusion\FusionAll.h>
#include <Core\CoreAll.h>

using namespace adsk::fusion;
using namespace adsk::core;
class Win :public wxApp
{
	wxFrame*window;
	wxButton *button;
public:
	Ptr<Component> rootComp;
	Win(Ptr<Component> comp):rootComp(comp)
	{
	
	}
	bool OnInit()
	{
		window = new wxFrame(nullptr, -1, "hi", wxPoint(100, 100), wxSize(840, 640));
		window->Show();
		button = new wxButton(window, -1, "create", wxPoint(100, 100), wxSize(100, 50));
		button->Bind(wxEVT_BUTTON, &Win::func1, this);

		

		return true;
	}
	void func1(wxCommandEvent&)
	{

		Ptr<Sketches> sketches = rootComp->sketches();
		if (!sketches)
			return ;
		Ptr<ConstructionPlane> xyPlane = rootComp->xYConstructionPlane();
		if (!xyPlane)
			return ;

		Ptr<Sketch> sketch = sketches->add(xyPlane);
		if (!sketch)
			return ;

		// Draw a circle.
		Ptr<SketchCurves> sketchCurves = sketch->sketchCurves();
		if (!sketchCurves)
			return ;
		Ptr<SketchCircles> circles = sketchCurves->sketchCircles();
		if (!circles)
			return ;
		Ptr<Point3D> centerPoint = Point3D::create(0, 0, 0);
		if (!centerPoint)
			return ;
		Ptr<SketchCircle> circle1 = circles->addByCenterRadius(centerPoint, 2);
		if (!circle1)
			return ;

		// Get the profile defined by the circle.
		Ptr<Profiles> profs = sketch->profiles();
		if (!profs)
			return ;
		Ptr<Profile> prof = profs->item(0);
		if (!prof)
			return ;

		// Define that the extent is a distance extent of 5 cm.
		Ptr<ValueInput> distance = ValueInput::createByReal(5);
		if (!distance)
			return ;

		// Create the extrusion.
		Ptr<Features> feats = rootComp->features();
		if (!feats)
			return ;
		Ptr<ExtrudeFeatures> extrudes = feats->extrudeFeatures();
		if (!extrudes)
			return ;
		Ptr<ExtrudeFeature> ext = extrudes->addSimple(prof, distance, FeatureOperations::NewComponentFeatureOperation);
		if (!ext)
			return ;
	}
};

When I spin object sketch freezing

 

 

Message 4 of 8
marshaltu
in reply to: raterWBBQB

Hello,

 

Thank you for the sample codes.

 

I can run it in my local machine. It seems that a form window with one button will pop up when run codes. A couple of sketches and features will be created after clicking the button. You have to close the window to be back to Fusion because it seems that UI/Main thread is occupied by the new Window. I am not clear what's the issue you mentioned. 

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 5 of 8
raterWBBQB
in reply to: marshaltu

the problem is I have very small FPS(when  move, spin, etc in sketch) when window work. If closed window, all good

Message 6 of 8
marshaltu
in reply to: raterWBBQB

Hello,

 

Ok, got it. It should be because your window occupied UI/main thread and Fusion itself cannot execute any operations(even by APIs). Most of API need be run in main/UI thread as well.

 

Thanks,

Marshal 



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 7 of 8
raterWBBQB
in reply to: marshaltu

How I can do it? Do you have sample?

Message 8 of 8
marshaltu
in reply to: raterWBBQB

Hello,

 

I am not familiar with wxWidget. We provides APIs to let clients create custom UI by HTML/CSS and work with worker thread as well. Please refer to the following two threads.

 

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-6C0C8148-98D0-4DBC-A4EC-D8E03A8A3B5B - Using Palettes

http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-F9FD4A6D-C59F-4176-9003-CE04F7558CCC - Working in a Worker Thread

 

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

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