Search found 47 matches

by Stefan Sterk
Sat Mar 08, 2025 5:40 am
Forum: Macro Library
Topic: Reset Light Sources
Replies: 10
Views: 5158

Re: Reset Light Sources

But . . . you have to do that for each configuration. That seems odd because when you open the scene properties window and edit it there, the setting applies to all the configurations. I didn't know you could even have different scenes for different configurations. Dwight Hi Dwight, use this code i...
by Stefan Sterk
Tue Mar 04, 2025 11:56 am
Forum: API
Topic: PDM Searching for files that have blank variable value (never been set)
Replies: 5
Views: 2073

Re: PDM Searching for files that have blank variable value (never been set)

Hi bnemec, Not sure if this will help, but try compare it "1/1/1800" instead of a empty string. If you add a date (for example, DrawnDate), as a property, the software does not require you to enter a date for Value / Expression. However, if you do not enter a date, Microsoft interprets the...
by Stefan Sterk
Wed Feb 12, 2025 4:36 pm
Forum: API
Topic: Can you create Subfolders in the Feature Tree?
Replies: 5
Views: 2286

Re: Can you create Subfolders in the Feature Tree?

Hi Loeb, You could use ReorderFeature ' to place a new 'sub' folder within a folder. As shown in the code below. Sub main() Set swApp = Application.SldWorks Set swDoc = swApp.ActiveDoc If swDoc Is Nothing Then End If swDoc.GetType <> 1 And swDoc.GetType <> 2 Then End Set swDocExt = swDoc.Extension S...
by Stefan Sterk
Tue Jan 28, 2025 3:43 am
Forum: Macro Library
Topic: Gemini for macro code?
Replies: 17
Views: 11520

Re: Gemini for macro code?

Hi Petertha, First thing, this topic has a better fit under the API section rather than the Macro Library . I've tried using ChatGPT, but I often had to make adjustments. I wouldn't recommend it for beginners, as it can sometimes lead you in the wrong direction. As for the 'o' in oDoc, I believe it ...
by Stefan Sterk
Tue Jan 14, 2025 7:19 am
Forum: SW General
Topic: Forced Update to Win11
Replies: 18
Views: 5644

Re: Forced Update to Win11

For me Quick Access does works fine on Win11.
by Stefan Sterk
Tue Jan 14, 2025 7:17 am
Forum: API
Topic: Slice macro modification
Replies: 1
Views: 1069

Re: Slice macro modification

Thx for sharing :)

By the way, you should call it Fruit Ninja ()
by Stefan Sterk
Sun Jan 12, 2025 12:30 pm
Forum: How To Questions
Topic: How to control the display of Annotations in the model
Replies: 1
Views: 1023

Re: How to control the display of Annotations in the model

@mihkov

RMB on the Annotations folder in the feature design tree and then disable 'Show Feature Dimensions'
image.png
by Stefan Sterk
Fri Jan 10, 2025 2:28 am
Forum: Macro Library
Topic: Assembly Sort
Topic: Assembly Sort
Replies: 6
Views: 2157

Re: Assembly Sort

Can you help me understand the first line: Declare PtrSafe Function StrCmpLogicalW Lib "shlwapi" (ByVal s1 As String, ByVal s2 As String) As Integer -Thank You Hi Loeb, Just declaring a function from the shlwapi.dll . Having this line makes the code more copy past friendly. Otherwise you ...
by Stefan Sterk
Thu Jan 09, 2025 3:09 pm
Forum: Macro Library
Topic: Assembly Sort
Topic: Assembly Sort
Replies: 6
Views: 2157

Re: Assembly Sort

Funny you ask, there was some activity on my solution at the SOLIDWORKS forum yesterday. The code below should do the trick. UU Option Explicit Declare PtrSafe Function StrCmpLogicalW Lib "shlwapi" (ByVal s1 As String, ByVal s2 As String) As Integer Sub main() Dim swApp As SldWorks.SldWork...
by Stefan Sterk
Tue Oct 29, 2024 9:11 am
Forum: SW General
Topic: 2024 SP05 is now available for download
Replies: 23
Views: 10351

2024 SP05 is now available for download

Just noticed SW24 SP05 is downloadable. Who has tried already?
They have addressed 23 SPR's for this SP.
by Stefan Sterk
Sun Aug 11, 2024 11:04 am
Forum: API
Topic: Batch export to Iges/Step based on Display States
Replies: 11
Views: 3158

Re: Batch export to Iges/Step based on Display States

I have tried running the new macro, but when importing the userform, I get the following error. image.png UserForm1.log Line 8: Property OleObjectBlob in UserForm1 had an invalid file reference. I see. Got the same error when importing. Not sure why it's doing that. I have edited the post, you need...
by Stefan Sterk
Fri Aug 09, 2024 11:38 am
Forum: API
Topic: Batch export to Iges/Step based on Display States
Replies: 11
Views: 3158

Re: Batch export to Iges/Step based on Display States

ok ... this might be a big ask ... im really not sure. feel free to tell me to bugger off if it is. Im just wondering if you might be able to modify this macro so that a selection box would pop up and allow you to select which display states you would want the macro to process? Is that doable? Yes ...
by Stefan Sterk
Thu Aug 08, 2024 5:07 am
Forum: API
Topic: Batch export to Iges/Step based on Display States
Replies: 11
Views: 3158

Re: Batch export to Iges/Step based on Display States

Well, these are the changes you need to make to make that happen. These are just quick edits, so keep in mind that the code can still be optimized. But it will do the job. UU Simply change the following line with in Main() ExportFile swModel, OUT_NAME_TEMPLATES, ALL_CONFIGS, outFolder to ' ####### L...
by Stefan Sterk
Wed Aug 07, 2024 7:39 am
Forum: API
Topic: Batch export to Iges/Step based on Display States
Replies: 11
Views: 3158

Re: Batch export to Iges/Step based on Display States

Thanks Stefan! It looks like this one will only export configurations .. but not display states. I have seen a few of these, but cant find any that will work with display states. Like a said, you would need to make some changes to the code. Use the following line for for OUT_NAME_TEMPLATES OUT_NAME...
by Stefan Sterk
Wed Aug 07, 2024 6:19 am
Forum: API
Topic: Batch export to Iges/Step based on Display States
Replies: 11
Views: 3158

Re: Batch export to Iges/Step based on Display States

Hi Bradrordzzz,

Have you seen this macro from codestack.net?
https://www.codestack.net/solidworks-api/import-export/export-multi-formats/

Only need some changes, so it adds the name of the current/active display state to the name.
by Stefan Sterk
Mon Jun 03, 2024 11:51 am
Forum: Macro Library
Topic: Macro idea
Replies: 4
Views: 2547

Re: Macro idea

josh wrote: Mon Jun 03, 2024 11:42 am ...
Relations deleted using this macro cannot be un-deleted by exiting the sketch with the red "X".
...
Not sure, but couldn't this be fixed by using the following StartRecordingUndoObject Method (IModelDocExtension) - 2024 - SOLIDWORKS API Help?
by Stefan Sterk
Tue Jan 30, 2024 4:24 pm
Forum: API
Topic: WasResolved from Get6 (CustomPropertyManager)
Replies: 4
Views: 2596

Re: WasResolved from Get6 (CustomPropertyManager)

I also tried to imitated these conditions, and also got only TRUE values for WasResolved, since the value cleary wasn't as is shown in the attached image below. Using SOLIDWORKS 2023. image.png Used the code below to create the resultes in immediate windows. Option Explicit Sub main() Dim swApp As S...
by Stefan Sterk
Tue Jan 30, 2024 4:48 am
Forum: API
Topic: macro features: what are they for?
Replies: 6
Views: 3356

Re: macro features: what are they for?

Hi mp3-250 , There are a few examples on codestack.net Macro Feature - Add Watermark Feature - Model Configurator - Link And Auto Update General Table To Excel - Generate Box Geometry - Link Cut-List Custom Properties To File Custom Properties - Automatically Run Macro On Model Load - Create MultiBo...
by Stefan Sterk
Fri Jan 26, 2024 5:08 pm
Forum: Macro Library
Topic: Creat a Macro to Add colors to each feature in a a part
Replies: 4
Views: 3178

Re: Creat a Macro to Add colors to each feature in a a part

Hi Craig, the code below will give a unique color to each component in a assembly. Thought I'd drop it here since you asked about it in our PMs. ' ################################################### ' # Title: Random Colorize Components # ' # Version: 24.1.26 # ' # Author: Stefan Sterk # ' #########...
by Stefan Sterk
Sat Jan 13, 2024 12:42 pm
Forum: API
Topic: Macro to find all files created in a given version
Replies: 9
Views: 4658

Re: Macro to find all files created in a given version

As gupta said, the code of artem will fit your need, straid out of the box.

Got some other info. The index for 'Last Saved With SW' doens't seems to be contant. On my Windows 11 system is is set on 330 instead of 336 (Windows 10). Not sure if it is Windows related or user setting.
by Stefan Sterk
Fri Jan 12, 2024 3:02 am
Forum: API
Topic: Macro to find all files created in a given version
Replies: 9
Views: 4658

Re: Macro to find all files created in a given version

Tera wrote: Thu Jan 11, 2024 8:09 pm I haven't reviewed @artem code yet, but your code returns null values.
What does 336 stands for?

Thanks.
336 is the index for 'Last Saved With SW' extended file attribute/detail. A value that can be shown in the file explorer. See image below. This is working for me
image.png
by Stefan Sterk
Thu Jan 11, 2024 4:59 am
Forum: API
Topic: Macro to find all files created in a given version
Replies: 9
Views: 4658

Re: Macro to find all files created in a given version

Hi Tera, Have a look at https://www.codestack.net/solidworks-api/document/versions-report/ artem code used the solidworks application to get the version history. Which limits the speed. A faster way is to get the file atribute 'Last Saved With SW' itself, see example code below Sub main() Debug.Prin...
by Stefan Sterk
Thu Nov 23, 2023 7:09 pm
Forum: Macro Library
Topic: Creat a Macro to Add colors to each feature in a a part
Replies: 4
Views: 3178

Re: Creat a Macro to Add colors to each feature in a a part

Hi Craig Makarowski , See code below. 2023-11-24-01-16-35.gif Option Explicit Sub main() Dim swApp As SldWorks.SldWorks Dim swDoc As SldWorks.ModelDoc2 Dim swFeat As SldWorks.Feature Dim R() As Double, G() As Double, B() As Double Dim vMatVal(8) As Double Dim i As Long: i = -1 Set swApp = Applicatio...
by Stefan Sterk
Thu Nov 23, 2023 11:50 am
Forum: Macro Library
Topic: Reset Light Sources
Replies: 10
Views: 5158

Reset Light Sources

Here is a simple macro which gives you the power to easily reset your light sources within a SOLIDWORKS Part or Assembly model by deleting the current light sources and adding back the 'default' (user specified) light sources. Option Explicit Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As ...
by Stefan Sterk
Thu Nov 16, 2023 3:55 pm
Forum: Macro Library
Topic: Save PDF and SLDDRW at same time
Replies: 2
Views: 2106

Re: Save PDF and SLDDRW at same time

Awesome Stuff @xitter. Keep up the work!

I noticed that there are a few lines you should remove at the start.
image.png
by Stefan Sterk
Thu Nov 02, 2023 4:35 am
Forum: Macro Library
Topic: My Macros
Replies: 20
Views: 17366

Re: My Macros

mme wrote: Tue Oct 24, 2023 9:42 am Open part or assemblies. Run the macro. Enter a new name. If there is a drawing, it will put the same name on the drawing.
Hi @mme,
Sounds the same as this macro; https://www.codestack.net/solidworks-ap ... t-drawing/
by Stefan Sterk
Mon Oct 09, 2023 2:49 pm
Forum: API
Topic: Multi Export Assembly and Parts with Structure
Replies: 2
Views: 1916

Re: Multi Export Assembly and Parts with Structure

Hi Mmike4 Here is a example on how you could get the name without the instance ID. Copy component name to the component reference using SOLIDWORKS API (codestack.net) '********************** 'Copyright(C) 2023 Xarial Pty Limited 'Reference: https://www.codestack.net/solidworks-api/document/assembly/...
by Stefan Sterk
Wed Sep 13, 2023 6:03 am
Forum: API
Topic: Macro throwing error
Replies: 9
Views: 2799

Re: Macro throwing error

I believe the selected component is Ligthweight, which will throw an error when pulling the custom properties.
by Stefan Sterk
Thu Aug 31, 2023 6:14 am
Forum: API
Topic: What is the image size for the macro button?
Replies: 16
Views: 7466

Re: What is the image size for the macro button?

Codestack.net also says to use 20x20px for SOLIDWORKS newer then 2015. "Optionally specify the icon. For SOLIDWORKS 2015 or older use 16 by 16 bitmap, for all newer version use 20 by 20 bitmap. Use white color as the transparency key." SOLIDWORKS icon size on macro features also starts at ...
by Stefan Sterk
Wed Aug 09, 2023 3:51 am
Forum: API
Topic: Macro to adjust the partnames in a STEP export
Replies: 5
Views: 3274

Re: Macro to adjust the partnames in a STEP export

Rather than muck around with temporarily renaming things, you can simply post process the STEP file. It's text after all. The components are identified by the name followed by an underscore and then the configuration name. If you use C# or VB.NET you have a Regex.Replace method you can use to prepe...
by Stefan Sterk
Tue Aug 08, 2023 11:33 am
Forum: API
Topic: Macro to adjust the partnames in a STEP export
Replies: 5
Views: 3274

Re: Macro to adjust the partnames in a STEP export

simple answer, yes you can. check Name2 . 1. open assembly 2. traverse through components 2.a rename component with Name2 . 2.b list comp in already renamed list 3.SaveAs (Export) 4.close assembly without saving. aslong as you dont save the document(s) the name changes wil only be in memory. other l...
by Stefan Sterk
Tue Jun 20, 2023 7:53 am
Forum: API
Topic: Save As 3mf macro
Replies: 8
Views: 3069

Re: Save As 3mf macro

Does using the SaveAs3 method from IModelDocExtension give a different result?
by Stefan Sterk
Wed Nov 16, 2022 5:21 am
Forum: API
Topic: using openDoc6 browse for missing file.
Replies: 4
Views: 1476

Re: using openDoc6 browse for missing file.

Hi colt , Replace swOpenDocOptions_e.swOpenDocOptions_Silent with Empty or -1 . swOpenDocOptions_e.swOpenDocOptions_Silent suppresses the warning dialogs like missing file. Set res = swApp.OpenDoc6(fileP , swDocumentTypes_e.swDocDRAWING, Empty, "", err, warn) Instead of Set res = swApp.Ope...
by Stefan Sterk
Sun Oct 30, 2022 6:11 pm
Forum: SW General
Topic: What is the most efficient way to see where a file is saved?
Replies: 11
Views: 2552

Re: What is the most efficient way to see where a file is saved?

I got this macro (Code below) that opens the file location in the Windows Explorer for the selected component. Option Explicit Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swSelMgr As SldWorks.SelectionMgr Dim swComponent As SldWorks.Component2 Dim Path As String S...
by Stefan Sterk
Thu Sep 29, 2022 11:19 am
Forum: API
Topic: Change custom properties without opening the component from the drawing?
Replies: 7
Views: 2793

Re: Change custom properties without opening the component from the drawing?

Yes you can. I got a macro that give me the ability to change the properties of a compenent that is selected in a drawing BOM.
by Stefan Sterk
Wed Aug 10, 2022 5:16 am
Forum: SW General
Topic: What should the behavior of ‘Dissolve part level rows’ be?
Replies: 1
Views: 2219

What should the behavior of ‘Dissolve part level rows’ be?

I made this post to express my dissatisfaction with how Solidworks and our VAR are handling this, and I'd like to hear your thoughts. I mean, is it just me? () So Solidworks introduced the ‘ Dissolve part level rows ’ option under ‘Detailed cut list’ in the bill of materials (BOM) options for Solidw...
by Stefan Sterk
Fri Jul 08, 2022 6:22 am
Forum: API
Topic: Macro to Mate Origin - Origin
Replies: 5
Views: 3461

Re: Macro to Mate Origin - Origin

I contacted API Support and they suggest using AddMate5 with swMateCOORDINATE, which will align the axes. The code snippet below works as expected. Have fun with it ;) Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swAsm As SldWorks.AssemblyDoc Dim swSelMgr As SldWor...
by Stefan Sterk
Fri Jul 08, 2022 3:44 am
Forum: API
Topic: Macro to Mate Origin - Origin
Replies: 5
Views: 3461

Re: Macro to Mate Origin - Origin

Hi Zhen, The code that follows fulfills your request. The only issue I can identify is that the Origin Axes don't align as they would if I did it manually. grumph Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swAsm As SldWorks.AssemblyDoc Dim swSelMgr As SldWorks.Se...
by Stefan Sterk
Sat May 21, 2022 4:25 pm
Forum: API
Topic: How to skip identical parts with GetComponents
Replies: 3
Views: 1539

Re: How to skip identical parts with GetComponents

I start by making a list of unique components and then loop through it. as demonstrated by the code below Option Explicit Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim swUniqueCompList() As SldWorks.Component2 Dim swComp As SldWorks.Component2 Dim vComp As Variant S...
by Stefan Sterk
Sun Feb 13, 2022 2:14 pm
Forum: API
Topic: Bug? Units VBA macro turns on Scene Reflections and Shadows
Replies: 4
Views: 1663

Re: Bug? Units VBA macro turns on Scene Reflections and Shadows

I'm running SW2021 SP5.1 and i do get the same behavior, and not just with the API calls, it also happens when just going to ⚙️ Options and click ing on the OK button does enable the floor shadow and reflection on none active configurations. ChangingDocumentPropertiesEnablesFloorShadowForNoneActiveC...
by Stefan Sterk
Sun Oct 10, 2021 10:30 am
Forum: Macro Library
Topic: Need macro to export to 2 diffrent locations
Replies: 10
Views: 6789

Re: Need macro to export to 2 diffrent locations

Why would you perform the export twice and not just copy paste the file that you have exported with the FileCopy function? FirstPathName = FilePath & SaveFileName & "-" & Rev & ".STEP" SecondPathName = FilePathDump & SaveFileName & "-" & Rev ...
by Stefan Sterk
Fri Oct 08, 2021 6:40 am
Forum: Macro Library
Topic: Body names from a PRT
Replies: 7
Views: 5087

Re: Body names from a PRT

The code below will put the bodies in a cut-list and add a custom property with the name of the body. Which you can link to a drawing note. And it also change the name of the cutlist folder to the name off the body with an extra space at the end. Let me know how it goes. Option Explicit ' Name of th...
by Stefan Sterk
Thu Oct 07, 2021 12:59 pm
Forum: Macro Library
Topic: Body names from a PRT
Replies: 7
Views: 5087

Re: Body names from a PRT

Hi Peter, Have you tried making a Cut-List by going to the Weldments tab and then clicking on the Weldment command. image.png You can then add properties to the cut list item, a partname for example. image.png image.png Which then can be linked to the drawing notes. image.png I believe there are som...
by Stefan Sterk
Tue Sep 07, 2021 9:23 am
Forum: Macro Library
Topic: Open Drawing From BOM
Replies: 19
Views: 8534

Re: Open Drawing From BOM

Hey Stefan! I am using Resolved, but my SolidWorks is in french rather then english. Could that be the cause? This is the error I get on Visual Basic. 2nd image to show how I selected. 3rd image to show file location. image.png image.png image.png language shouldn't be the issue. That error you get...
by Stefan Sterk
Mon Sep 06, 2021 8:03 am
Forum: Macro Library
Topic: Open Drawing From BOM
Replies: 19
Views: 8534

Re: Open Drawing From BOM

Hi Stephan, I've followed the instructions in your video, but nothing happens when I use the mouse gesture; no feedback of any sort. The drawings are in the same directory as the models and the filenames are identical. Any suggestions? Thanks Stefan, I've downloaded the macro and shared it with my ...
by Stefan Sterk
Tue Aug 10, 2021 3:06 am
Forum: Macro Library
Topic: Open Drawing From BOM
Replies: 19
Views: 8534

Open Drawing From BOM

Well Hello, For those who wanna open a drawing directly from another drawing BOM. Stop searching for a solution because this post will give you on. Happy reading, wachting and opening drawings. Note: The drawings needs to be in the same folder and having the same filename as the part/assembly you wa...