Applying color to CustomGraphicsGroup

Applying color to CustomGraphicsGroup

joshM57CN
Contributor Contributor
537 Views
2 Replies
Message 1 of 3

Applying color to CustomGraphicsGroup

joshM57CN
Contributor
Contributor

With the project I am working on, the end result could display anywhere from 4 to 400 graphics curves/lines. When this is on the smaller side, setting each curve's color is fine. As this gets larger, this method becomes much slower. 

 

Alternatively, I've tried to apply the color to the Group (see the last line), but I can't seem to figure out why this returns false. 

Edit: I should not that if I try to set the group color 'before" I add the curves, I will get a true. But the resulting display is still black (no color). 

 

Has anyone had a similar issue or is there a more effecient way of changing the color of a large collection of entities?

 

Thanks!

 

Relevant code snippet of what I have been trying. 

 

	Ptr<CustomGraphicsGroup> pathGraphics = GetOrCreateGraphicsGroup(testGraphics, ToolpathId);

	// Create color effects
	Ptr<CustomGraphicsSolidColorEffect> orange = CustomGraphicsSolidColorEffect::create(FusionInter.ColorDefinitions[path]); //Ptr<Color> ColorDefinitions
	Ptr<CustomGraphicsColorEffect> pathColor = orange->color();
	// Function to add curves efficiently
	auto addCurves = [](Ptr<CustomGraphicsGroup> group, const vector<Ptr<Curve3D>>& curves,
		const Ptr<CustomGraphicsSolidColorEffect>& color, double weight) {
			for (const auto& curve : curves) {
				Ptr<CustomGraphicsCurve> graphicsCurve = group->addCurve(curve);
				graphicsCurve->color(color);
				graphicsCurve->weight(weight);
			}
		};

	// Add main display curves
	addCurves(pathGraphics, InLowerPath, orange, 1.1);
	addCurves(pathGraphics, InUpperPath, orange, 1.1);
	for (const auto& line : InSyncLines) {
		Ptr<CustomGraphicsCurve> graphicsCurve = pathGraphics->addCurve(line);
		graphicsCurve->color(orange);
		graphicsCurve->weight(1.1);
	}

	bool result = pathGraphics->color(FusionInter.ColorDefinitions[path]);

 

 

0 Likes
538 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

I can reproduce the problem and will see that a bug is filed. I'm unsure what the behavior should be when a color is assigned to a group. The custom graphics object can have a color and there can be nested groups, each one with a color. What I'm unsure about is what should win. If a line is colored green but a group it's in is red, should the line be red or green? I think probably red, that the highest level color assignment would override any lower level colors. But then if you want everything green and one thing red, you would have to create that one thing in a different group.

 

The other option is that the lowest level where a color is assigned would take precedence. If a color is not assigned, it would use the color assignment of the lowest group it's in.

 

One thing you can do now is create all of your lines as a single CustomGraphicsLines object so you can color them all at once. However, that won't help for other curve shapes.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 3

joshM57CN
Contributor
Contributor
I'll keep an eye out for a fix then.
Would be nice if there was a 'curves' group. Will have to wait to see how they handle which color applies.
Thanks!
0 Likes