Painting Setting

I want to trigger the painting setting through the code in the following code, but it fails to execute properly and shows an error. Where did I make a mistake? Thank you.

        private void PrpareForPainting_click(object sender, RoutedEventArgs e)
        {

            ICommandRegistry cmd = IoC.Get<ICommandRegistry>();
            IActionItem extractCmd = cmd.FindItem("PrpareForPainting");
            extractCmd.Execute();
        }

Error : System.NullReferenceException:“Object reference not set to an instance of an object.”

That command takes a bool parameter, and only opens or closes the UI for it. I think there is no API to prepare components for painting programmatically.

So there is no way to set the Prepare Selected Components method?
Thank you

What the “Prepare for painting” does is collect all triangle meshes (ITriangleSet) from all node’s geometry (ISimNode.Geometry) of the selected component and then call

ITriangleSet.SubdivideMesh(MaxEdgeLength, int.MaxValue);
ITriangleSet.ResetTextureCoordinateValues();

Then it sets (or creates) a boolean property in the component called “PaintPrepared” to true.

So, even though you can not use the command directly, you can do the same using the .NET API.

I’m not sure how to use it. Can you give me some examples?
Thanks

Something like this (did not test it):

private void PrpareForPainting_click(object sender, RoutedEventArgs e)
{
    var c = IoC.Get<ISelectionManager>().GetSelected<ISimComponent>();
    double maxEdgeLength = 50;
    SubvideMesh(c.RootNode);

	var componentPreparedProp = c.Properties.FirstOrDefault(p => p.Name == PaintProperties.PAINT_PREPARED);
	if (componentPreparedProp == null)
	{
		componentPreparedProp = c.CreateProperty(typeof(bool), PropertyConstraintType.NotSpecified);
		componentPreparedProp.Name = PaintProperties.PAINT_PREPARED;
		componentPreparedProp.IsVisible = false;
	}
	componentPreparedProp.Value = true;

	IoC.Get<IPaintColorMapsEditorViewModel>().AddMaterialToComponent(c, true, true);

}

private void SubvideMesh(ISimNode node, double maxEdgeLength)
{
    var sets = node.Geometry.GeometrySets.OfType<ITriangleSet>();
    foreach (var triangleset in sets)
    {
        NotificationBar();
        triangleset.SubdivideMesh(maxEdgeLength, int.MaxValue);
        triangleset.ResetTextureCoordinateValues();
    }

    var children = node.Children;
    foreach (var n in children)
    {
        SubvideMesh(n, maxEdgeLength);
    }
}

1 Like

Thank you, I have tested it and it works

1 Like

PaintProperties.PAINT_PREPARED This is an error

Uploading: net.png…

You can use the value directly which is a string “PaintPrepared”.

Thank you. I tried, but still got an error. Please take a screenshot or attach a program

Thank you very much,Thank you very much

What error do you get? you should simply change the code with something like this

I cannot see the screenshot, can you publish it again if you still get an error?

1 Like

Thank you very much for your answer

In your .NET code you should change PaintProperties.PAIN_PREPARED to “PaintPrepared”.
Remove the code you have about getting and executing “PrpareForPaiting”, there is no need.

In your Python script, you should check if the component has the PaintPrepared property.

component = getComponent()
PaintPreparedProperty = component.getProperty("PaintPrepared")

Then check if PaintPreparedProperty is not None, otherwise it means it was not set.

1 Like

Many thanks,Many thanks

This component is being sprayed, can it be changed to another color

A

Can this be done in a Python script

How does this get back to its old color
I want to use python program to achieve this, I have studied for a long time, I will pay you, can you help me to achieve it? Thank you very much