Hi all
I'm looking for a way to open a userform when opening a new part file.
A bit like in Excel with WorkbookOpen(), but I don't see anything that would look like apartOpen().
Anyone have an idea
Hi all
I'm looking for a way to open a userform when opening a new part file.
A bit like in Excel with WorkbookOpen(), but I don't see anything that would look like apartOpen().
Anyone have an idea
Hello
This topic deals with it, however, the constraint is that it will only apply to new files.
Run VBA macro on model load using macro feature and SOLIDWORKS API (codestack.net)
Another method would be to play with SW events to capture file opening information, but for that you need to modify the SW launch executable to have a macro that runs in the background
Thanks @Cyril.f , yes that's exactly what I want, that it only runs when creating a new file to force the draftsman to choose a predefined material in a combobox of the userform.
So we only need it for the creation of the new piece.
I'll study it, but the code at first glance looks pretty hard!!
There may be a way to make it a bit simpler than the code offered by Codestack, I'm looking at this because I already have codes that use SW events but I don't manage it for the moment when launching SW directly (I launch SW and a macro from Excel)
Thank you, it's nice to give me a hand on this specific subject.
In the meantime I'll look at the Codestack code.
I don't understand how to create a Feature macro, apparently you have to open a sketch in the model.
But I don't see what to do next.
EDIT: Sorry, I should have watched the video !!
After several tries, the Codestack code doesn't work for my use.
The macro runs before the file is opened and so I can't edit the material since the feature manager folder isn't active.
Another idea to solve my problem?
Hello @treza88
I'm not going to answer the question but a little more to the problem. An alternative could settle it differently;
Creating document templates for new documents. With a template for each material, and by deleting the original default template since it is a question of forcing the designer's choice, he will only be able to open new documents with one of the predefined templates, therefore only with one of the predefined materials. And this is done directly from the SW opening window.
Hello and thank you @Sylk,
The problem is that it would make me at least thirty models, because my material defines the type of material but also the thickness of my sheet metal, of the " Inox_2.0 " type.
This allows me to retrieve this information for my DXF exports.
On the other hand, I have a solution that suits me and that is quite simplistic, which is to create a macro that creates a new part and after the creation opens my userform.
Or rather in this order: A macro that opens the userform and then creates a new room with the options chosen in the userform.
Basically, what I would do, a priori, is:
PS: in case of incorrect parameters or closure (cancel) of the userform/macro, closing the "in creation " doc without saving it seems necessary to avoid docs without viable configuration.
Hello
The problem with macros that don't launch autonomously is that it remains dependent on the user (I have some very useful ones that users don't use and that from time to time would prevent them from encountering some problems on their files).
So having a macro feature could have been the solution but the problem remains that it must be in all document templates.
The " easiest " way to force the use is to launch a macro when SW is opened, which intercepts SW events and would thus allow you to set the desired behavior.
That being said, this solution requires you to modify the way SW is launched by adding arguments to the command line opening SW so that it launches the macro when it is opened and a very robust code to overcome all the cases that could be encountered.
Maybe easier to manage and less restrictive for the user (sometimes you need a part to put an idea): check at registration that the materials are in the list and if necessary open the userform.
With an add-in you can intercept Solidworks events, you just have to install it on all workstations.
Personally, I find it surprising to incorporate thickness into the material.
There are other ways to retrieve this thickness automatically. (just like the material)
Example noted in the room and then the MEP:
In the room:
" Epaisseur@Pièce1.SLDPRT "
In the MEP:
Thickness $PRPSHEET: " Thickness " mm
The result:
=> Big sigh ... That said, I suddenly feel less alone...
To answer @treza88's question:
I'm generally opposed to " Macro Features " it's often heavy (for the size of the file), they are complicated to share (especially with external people who don't have the same version of Solidworks or simply administrative restrictions on their workstation)...
To avoid all of this, depending on the Solidworks version you are using (From Solidworks 2019):
look at the " Sheet metal" tab when editing materials... I think this answers your request:
Well, maybe I'm getting ahead of myself a little since, as you can see, I don't use it... (Solidworks 2022).
@treza88 ... I am not at all opposed to the multiplication of sources of information (quite the contrary), only it would be fair play to post the results (in case of resolution) on the different forums where you made your requests:
Below screenshot of the Solidworks forum
Kind regards.
The SW forum response doesn't solve the " it's user-dependent" problem.
Creating a macro that launches a userform and creating a file is basic, but users still have to deign to click on the icon.
@Cyril.f , exactly the remark I was making to myself.
The solution proposed by @sbadenis seems to me to be interesting (beyond the fact that the drawing seems to be a great middle finger )
Personally, it's what we use. When the material is not filled in, Sldw insults us about the drawing, which alerts the eye
You can, in addition, embellish with visual cues. Everything that needs to be verified by the user is set to red by default in your native file. And the user passes them in black to validate the fact of having checked.
Even though we put elements in red and bold, it jumps out at nobody. I must have blind people in my users
[HS On] The only time we got a result was on files in our PDM that are in a trash folder, when the assemblies point to them we replaced the 3D with an extruded text of the type " This is not the right file ". As they have trouble with the " get the version " and not " get the latest version " strangely they ended up with an ASM with beautiful texts and constraint errors and there it made [HS Off] react