Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Picture boxes or canvas tools in Dialogs?

Mihalcea Bogdan
Contributor
Hello!
Which part of the API Reference I need to read about picture boxes?
Is there any "canvas" like elements for Archicad?
I really need a picture container or an canvas container where I can display and interact a .PNG, or a .SVG file.
After some user input is made, the AddOn will create a query on a database(online) which will result in an image, after that i need to update that image and so on ...

Is there any possibility to actually draw on the Dialog box?

I attached a picture where I would like to have a picture box or a canvas element so you can have an ideea. .
A C# example:
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Viktor Kovacs
Graphisoft
Graphisoft
Unfortunately there is no easy example among the example add-ons, but here are the basics.

1. Define a user item in the grc:

/* [ 1] */ UserItem			  100 100  50 50	ClientEdge

2. Initialize it in the dialog constructor:

myUserItem (GetReference (), MyUserItemID)

3. Attach to event listener.

4. Implement the UserItemUpdate function.

void MyDialog::UserItemUpdate (const DG::UserItemUpdateEvent& ev)
{
	NewDisplay::UserItemUpdateNativeContext context (ev);
	// ...
	context.DrawImage (image, width, height, 0.0f, 0.0f, 0.0f, false);
	// ...
}

View solution in original post

10 REPLIES 10
Viktor Kovacs
Graphisoft
Graphisoft
It is possible with DG::UserItem. Create one in your dialog, and than use NewDisplay::UserItemUpdateNativeContext to draw on it in the UserItemUpdate event.
Mihalcea Bogdan
Contributor
Thanks for the fast reply.
Can you point me where I can find some documentation/help on DG::UserItem?

Solution
Viktor Kovacs
Graphisoft
Graphisoft
Unfortunately there is no easy example among the example add-ons, but here are the basics.

1. Define a user item in the grc:

/* [ 1] */ UserItem			  100 100  50 50	ClientEdge

2. Initialize it in the dialog constructor:

myUserItem (GetReference (), MyUserItemID)

3. Attach to event listener.

4. Implement the UserItemUpdate function.

void MyDialog::UserItemUpdate (const DG::UserItemUpdateEvent& ev)
{
	NewDisplay::UserItemUpdateNativeContext context (ev);
	// ...
	context.DrawImage (image, width, height, 0.0f, 0.0f, 0.0f, false);
	// ...
}
Mihalcea Bogdan
Contributor
Thank you very much Viktor Kovacs! I owe you a coffee-beer-pizza, if you have a buymeacoffe account I will send you a coffee.
I was thinking about buying the Developer Support for a year. Where can I find some information about the services included in this subscription from GRAPHISOFT?
Mihalcea Bogdan
Contributor
Viktor wrote:
Unfortunately there is no easy example among the example add-ons, but here are the basics.

void MyDialog::UserItemUpdate (const DG::UserItemUpdateEvent& ev)
{
	NewDisplay::UserItemUpdateNativeContext context (ev);
	// ...
	context.DrawImage (image, width, height, 0.0f, 0.0f, 0.0f, false);
	// ...
}
If someone arrives to this post and does not know where the UserItemUpdateNativeContext is located it is here: AC_DEV_KIT_PATH\Support\Modules\DGGraphix
Akos Somorjai
Graphisoft
Graphisoft
Mihalcea wrote:
I was thinking about buying the Developer Support for a year. Where can I find some information about the services included in this subscription from GRAPHISOFT?
Hi Michalcea,

The subscription includes a "priority lane" via the official support channel https://graphisoft.atlassian.net/servicedesk/customer/portal/5, meaning that we guarantee a short, 72 hour feedback to your questions.

Best, Akos
Mihalcea Bogdan
Contributor
Thank you!
I will think about this service!
Mihalcea Bogdan
Contributor
Viktor wrote:

void MyDialog::UserItemUpdate (const DG::UserItemUpdateEvent& ev)
{
	NewDisplay::UserItemUpdateNativeContext context (ev);
	// ...
	context.DrawImage (image, width, height, 0.0f, 0.0f, 0.0f, false);
	// ...
}
This code works only inside the "UserItemUpdate" function when the UserItem updates. I am having a real hard time figuring out how to pass this context to a function like

virtual void UserItemClicked(const DGUserItemClickEvent &ev)
{
	//draw something when user clicks
}
virtual void SpecDragStarting(const ItemDragSourceEvent &ev)
{
	//do something when user starts dragging like fetch an image from Google Earth based on the new coordinates
}
I tried to reference it, but obviously I get Memory Access Exception.
Viktor Kovacs
Graphisoft
Graphisoft
It's a general rule for all applications that they should draw only when the operating system requests them to do so. In your case it means that you can draw only in the UserItemUpdate function, so the context can't be reused. Fortunately, you can request the operating system to redraw. Call the userItem.Redraw (true, true) function which will force the call of UserItemUpdate.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!