Hi,

 

I would like to know what kind of event is fired when replacing a component through the replace component command?

 

I am storing the name of a component in a file and I would like to update it when the component is replaced.

 

With thanks and regards,

Ben


Categories: API∕Macros

Comments
Last comment By: Michael Spens   Fri, 10 Aug 2018 22:11:57 GMT
Re: What event is fired when calling replace component?

Hi Benjamin,

With a little testing, it looks like RenameItemNotify is triggered.  As you've likely found, there isn't a specific notification for replace components.

 

Mike

By: Michael Spens  Mon, 06 Aug 2018 21:55:15 GMT
Re: What event is fired when calling replace component?

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System.Runtime.InteropServices;

using System;

 

 

 

namespace ReplaceComponents.csproj

{

    public partial class SolidWorksMacro

    {

        public void Main()

        {

            swApp.CommandCloseNotify += new DSldWorksEvents_CommandCloseNotifyEventHandler(OnCommandCloseNotify);

        }

 

 

 

        int OnCommandCloseNotify(int Command, int reason)

        {

            //defined in swCommands_e

            const int swCommands_ReplaceComponents = 575;

            const int Ok = -2;

 

 

            if(Command == swCommands_ReplaceComponents)

            {

                if (reason == Ok)

                {

                    swApp.SendMsgToUser("Component replaced");

                }

            }

 

 

            return 0;

        }

 

 

        public SldWorks swApp;

    }

}

 

 

 

By: Artem Taturevych  Mon, 06 Aug 2018 23:30:36 GMT
Re: What event is fired when calling replace component?

Hi Michael,

 

This is exactly what I was looking for.

At the beginning I thought that DeleteItemNotify then AddItemNotify were fired (to replace you must remove existing and add new) but I didn't thought of using renameItemNotify.

 

@Artem, your answer is good too and to be honest I tried it. But it was complicate to get the previous and new component name.

 

Thanks,

Ben

By: Benjamin Roux  Tue, 07 Aug 2018 09:17:19 GMT
Re: What event is fired when calling replace component?

Good call Artem Taturevich!

By: Michael Spens  Fri, 10 Aug 2018 22:11:57 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.