MacroFeature: SaveAs in the Rebuild function

Hello 

I'm creating a macro feature that adds a plan number to my drawings and saves a .pdf and .slddrw version in a specific location.

The code in my Rebuild and Edit function called by my feature macro is identical, but when I reconstruct my drawing, my plan is not saved (the SaveAs function returns False), whereas when I click on my feature macro and click on "Edit Definition", it works. I checked, my Rebuild function is called, but it doesn't save, while for Edit it works, being exactly the same code. Is there a dark spell that I don't know about?

Do you manage to save in the Rebuild function of your feature macros?

(I'm on Solidworks Pro 2017 Sp3.0)

Thanking you in advance,

Gauthik

Note that I use this method: http://help.solidworks.com/2017/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.imodeldocextension~saveas.html

And that the value of the "Errors" and "Warnings" parameters is 0 in the rebuild and edit function. The only difference is that on one side it returns False (Rebuild) and on the other hand True (Edit).

Hello

I've never done feature macros but from what I read here, there are obviously limitations to what can be done in the Rebuild function, the SaveAs function is probably one of them.

Kind regards

1 Like

Hello, thank you for your answer.

Indeed I also read that there were limitations on this function (link), on the other hand it is not really written that it is impossible to save. I tried to fake the thing by running a macro that saves in the rebuild function (RunMacro2 method), but it doesn't work either. One of the last avenues I have left is to check if the active document doesn't change during the rebuild function, and try with the GetSelections3 method, (as I read on this forum).

For the moment I have a macro button to click and it works perfectly, but my perfectionist side pushes me to have no macro button to click :), but at worst if I don't find it won't be a big deal.

Hello

I haven't tried, but it's probably possible to pair your macro feature with an event. All that remains is to put the registration code on the event.

Or create an event subscription macro that is launched when SW runs.

1 Like

Hello, indeed I had read somewhere that you could use events. At first glance, this is no longer a simple macro, it requires the creation of a solidworks add-in. When I have free time I will find out about it. Thank you for your answer.

Hello

No need to create an addin to manage the vents. You can manage them by a simple VBA macro that is executed when SW opens. Look on the net, you can find a lot of tutorials.

FeatureMacros are most used for updating data in a model.

In your case, I will go through the vents knowing that a part number does not need to be updated with each rebuild.

1 Like

Great, I didn't know this technique. Indeed I found examples of codes where they use events. It's what I wanted to do. I'll be able to create even more efficient macros with these new tools. Thank you for your help!