Automatically running a Solidworks macro

Hello

 

Is it possible to automatically run a macro linked to a part when it is inserted into a Solidworks assembly?

 

Thank you in advance!

 

 

I put the post I did in the other question 

 

to do this kind of automation, it's more complicated, you have to make a SW add-in that manages the events of the application. In fact, you have to program more than a macro, you have to go through a development tool like Microsoft Visual Studio.

 

There is a myCAD tool for this called CustomToolBar, in which it is possible to trigger a macro in relation to events (insertion of a component for example)

 

But simpler without this tool is to create a macro shortcut in the toolbars.

 

or create a macro that launches the insert function of this component and then displays the sizing window...

5 Likes

Hello

I would be tempted to say that a single macro would not be enough but with a succession of macros it could do it.

Unless you can link several macros together but I don't know enough about it.

For the opening when inserting a part into an assembly, it depends on whether you want:

 

  • make it in a particular assembly (depending on the name),
  • do it for a particular part,
  • do it all the time.

 

For the latter case it's simple, you can then replace the SolidWorks insert button with a button for your macro !

1 Like

Concretely, I would like that when I insert my railing into any assembly, the sizing window (and therefore the macro associated with the railing) runs.

I will then create other standard elements for us (gate, ladder,...) and I would like it to be the same with these parts.

 

I'm really open to all types of ideas, the end goal being to make the end user's life easier:D

 

Hello

 

Why not use the standard SolidWorks features to do this rather than developing macros that will need to be updated in future versions of SolidWorks.

To insert a part or assembly with a dialog box to manage parameters, you can use either DriveWorks xpress or the configuration manager (in the configurations tab).

 

@+

3 Likes

This video explains the macros built into assemblies:

http://www.youtube.com/watch?v=zbvp1v7_bec

 

The solution, a bit complicated, would be to create the macro in your assembly as shown in the video.

 

Create a custom "railing" property at 0.

 

Add a condition to the macro: detect when the "railing" part is added.

 

The macro does its job, then changes the "railing" property to 1 to no longer launch the macro.

 

Problem: this macro will check the custom property "guardrail" and if you insert the part at each rebuild: overload for the processor!

 

Verdict: a lot of work for not much... a button would really be simpler!

Other possibilities for launching macros:

 

By an equation, from the design binder, from a feature macro:

 

http://www.cadsharp.com/blog/4-ways-to-run-solidworks-api-macro-without-run-button/

 

Macro feature: http://www.youtube.com/watch?v=I-cIGMFSBOg

Coyote

 

I tested the DriveWorksXpress method, by defining a model, by capturing the dimensions I want to vary, but I don't understand how to make this configuration window appear when inserting the part into the assembly afterwards?

@jfaradon,

 

I'm bugging on your idea of creating a macro to insert the part and generate the opening of the window.

 

If you can give me a clue or the program:D

The idea is simply to add in the macro ta the insertion of the part at the beginning!

With Add component:

http://help.solidworks.com/2012/English/api/sldworksapi/Add_Components_Example_VB.htm

Re

 

Indeed with DriveWorks Xpress I said something stupid the window does not open during insertion.

On the other hand, with my second method indicated, namely the configuration manager, it works like this, at the time of inserting the model the configuration window appears in the feature manager.

 

@+

 

There are two ways to program the insertion of a component, either you program everything (AddComponent)

or you just run the command as if you were clicking on the "Insert components" button

 

To do this, you need to use the RunCommnand method, which allows you to run SW commands

Example in your case

 

swDoc.Extension.RunCommand(swCommands_e.swCommands_InsertComponents, "")

 

you need the swCommands reference added to the project

 

Be careful, the command is asynchronous, i.e. the code continues without waiting for the insertion command to be completed...

 

 

2 Likes

 Hi everyone.

 

Sorry I didn't follow the thread but I had to be away for a while.

Well, I'm still stagnating and that's where I meet that I'm really a novice;)

 

Well, if a charitable soul can try directly on my macro, I would forever be indebted to him:D

 

Thank you in advance to all.


garde-corps.zip