Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Inventor getting slower when running API Asynchronous

bouchahouaimen
Explorer

Inventor getting slower when running API Asynchronous

bouchahouaimen
Explorer
Explorer

Hi All,

I'm trying to call some API methods in an asynchronous way, but when running my program, the Inventor is getting slower, and I also detect high CPU usage. 

Thank you !!

        TextGraphics textGraphics = null;
        GraphicsNode oGraphicNode;
        static void CreateTextGraphic(GraphicsNode oGraphicNode, string Text)
        {
            DeleteClientGraphicPrimitive();
            if (textGraphics != null)
            {
                textGraphics.Delete();
            }
            Point Origin = oApp.TransientGeometry.CreatePoint(0, 0, 0);
            Point2d AnchoredPoint = oApp.TransientGeometry.CreatePoint2d(100, 0);

            //Create text graphics.
            textGraphics = oGraphicNode.AddTextGraphics();
            textGraphics.Text = Text;
           
            textGraphics.SetViewSpaceAnchor(Origin, AnchoredPoint, ViewLayoutEnum.kTopLeftViewCorner); ;
            textGraphics.SetTransformBehavior(Origin, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling, 100);
            oApp.ActiveView.Update();
          
        }
         static async Task UpdateTextGraphics()
        {
            int i = 0;
            try
            {
                do
                {

                    await Task.Run(() => CreateTextGraphic(oGraphicNode,i.ToString()));
                    i++;

                } while (true);


            }
            catch (OperationCanceledException)
            {
                Console.WriteLine($"\n{nameof(OperationCanceledException)} thrown\n");
            }
        }

 

0 Likes
Reply
Accepted solutions (1)
446 Views
1 Reply
Reply (1)

Dev_rim
Advocate
Advocate
Accepted solution

Hi There,

I can definitely say Inventor API is not designed for multitasking or parallel programming. I don't know if its really fits your situation but If there is really necessary to tasks being processed in async, I think the best way is running multiple Inventor sessions. But in this scenario you need to manage cores/threads really carefully. 

 

But there are ways to make API work faster.

 

invApp.Visible = false; //Makes Application invisible 
invApp.SilentOperation = true; // Blocks the popup windows
invApp.AssemblyOptions.DeferUpdate = false;  // Blocks the DeferUpdates
invApp.ScreenUpdating = false; // Blocs the Screen Updating
invApp.UserInterfaceManager.UserInteractionDisabled = true; //Disables the user interaction

 

When you start the process you can use this settings to make inventor run faster. If you need view or user interaction, you can open them and close again during the process.

 

I hope it helps.

 

Best Regards

Devrim

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
0 Likes