Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1229280
Did you mean that?
OldFcuk Dec 2, 2022
bca5c7c
Update index.md
OldFcuk Apr 5, 2023
d10b4ed
Update Macro.vba
OldFcuk Jul 18, 2023
af29110
Update index.md
OldFcuk Jul 27, 2023
aecb10a
Added export and export individual bodies macro+
artem1t Dec 12, 2023
b038f71
Added the macro to set read-only state for all dimensions in the feature
artem1t Dec 27, 2023
11d447a
Updated defeature part macro
Jan 12, 2024
afa2a13
Update index.md
OldFcuk Jan 29, 2024
0f09346
Updated export vb script to output messages to console
artem1t Feb 9, 2024
894e396
Solved return empty cut-list-item
stefan-sterk Feb 20, 2024
a58b43a
Merge pull request #251 from andrMollo/change-output-parameter
artem1t Feb 28, 2024
29f4e5e
Merge pull request #252 from andrMollo/Fix-WriteByteArrToFile
artem1t Feb 28, 2024
09dec0f
Merge pull request #232 from OldFcuk/patch-13
artem1t Feb 28, 2024
c1bf65b
Merge pull request #261 from OldFcuk/patch-14
artem1t Feb 28, 2024
6bc2ffe
Merge pull request #264 from OldFcuk/patch-15
artem1t Feb 28, 2024
1d86155
Merge pull request #301 from OldFcuk/patch-16
artem1t Feb 28, 2024
bad5474
Merge pull request #306 from stefan-sterk/patch-1
artem1t Feb 28, 2024
99dc0ad
Merge pull request #184 from OldFcuk/patch-12
artem1t Feb 28, 2024
c341774
Added option to select multiple paths
artem1t Feb 28, 2024
11b6bd2
Updated copy cut-list custom properties macro to specify the target p…
artem1t May 15, 2024
cd1f7f3
Added get note format text macro
artem1t May 22, 2024
3096338
Added the macro to calculate total area of all faces
artem1t Jul 24, 2024
66878f0
Added save as previous version macro
artem1t Aug 4, 2024
3241734
Added export individual cut-lists macro
artem1t Aug 7, 2024
4156c77
Removed debug.assert
artem1t Aug 7, 2024
3ca3b6f
Added remove flat pattern configuration
artem1t Sep 16, 2024
5de6fef
Updated set bom qty macro to also optionally process configurations
artem1t Oct 10, 2024
4d3f177
Added macro for aligning assembly configurations
artem1t Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion edrawings-api/output/export/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Please see below example of parameters
* Export all SOLIDWORKS files (matching the filter *.sld*, i.e. extension starts with .sld) from the *SW Drawings* and *SW Models* folders in drive C (including sub folders) to the *C:\EDRW* folder in eDrawings format (.eprt for parts, .easm for assemblies, .edrw for drawing) and html format.

~~~
> export.exe -input "C:\SW Drawings" "C:\SW Models" -output C:\EDRW -filter *.sld* -format .e .html
> export.exe -input "C:\SW Drawings" "C:\SW Models" -outdir C:\EDRW -filter *.sld* -format .e .html
~~~

* Export *C:\Models\Part.sldprt* into *C:\Models\Part.eprt*
Expand Down
2 changes: 1 addition & 1 deletion edrawings-api/output/print-to-pdf/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ group: Import/Export

This console application developed in VB.NET allows to export SOLIDWORKS, DXF, DWG files to PDF using free version of SOLIDWORKS eDrawings via its API. It is not required to have SOLIDWORKS installed or use its license to use this tool. This tool is supported on Windows 8.1 onwards.

This functionality has been integrated into the [xPort](https://cadplus.xarial.com/xport/) utility.
This functionality has been integrated into the [eXport+](https://cadplus.xarial.com/export/) utility.

## Running the tool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class MyComVisibleControlHost : UserControl
}
~~~

It is recommended to use COM-visible controls when hosting Windows Presentation Foundation (WCF) control in [System.Windows.Forms.Integration.ElementHost](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.integration.elementhost?view=netframework-4.8) as keypresses might not be handled properly in com-invisible controls.
It is recommended to use COM-visible controls when hosting Windows Presentation Foundation (WPF) control in [System.Windows.Forms.Integration.ElementHost](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.integration.elementhost?view=netframework-4.8) as keypresses might not be handled properly in com-invisible controls.

## Defining Commands

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
Const ROOT_CONFS_ONLY As Boolean = True

Dim swApp As SldWorks.SldWorks

Sub main()

Set swApp = Application.SldWorks

Dim swModel As SldWorks.ModelDoc2

Set swModel = swApp.ActiveDoc

Dim swAssy As SldWorks.AssemblyDoc

Set swAssy = swModel

If Not swAssy Is Nothing Then

Dim vComps As Variant
vComps = GetSelectedRootComponents(swAssy)

If Not IsEmpty(vComps) Then

Dim vConfs As Variant
vConfs = swModel.GetConfigurationNames

Dim i As Integer

For i = 0 To UBound(vConfs)

Dim swConf As SldWorks.Configuration
Set swConf = swModel.GetConfigurationByName(CStr(vConfs(i)))

If swConf.GetParent() Is Nothing Or Not ROOT_CONFS_ONLY Then

Dim confParams() As String
Dim confParamVals() As String

ReDim confParams(UBound(vComps))
ReDim confParamVals(UBound(vComps))

Dim j As Integer

For j = 0 To UBound(vComps)

Dim swComp As SldWorks.Component2
Set swComp = vComps(j)

If HasConfiguration(swComp, swConf.Name) Then

confParams(j) = "$CONFIGURATION@" & GetComponentNameForParameter(swComp)
confParamVals(j) = swConf.Name

Else
Err.Raise vbError, "", swComp.Name2 & " does not contain configuration " & swConf.Name
End If

Next

swConf.SetParameters (confParams), (confParamVals)

End If

Next

Else
Err.Raise vbError, "", "Select components to process"
End If

Else
Err.Raise vbError, "", "Open assembly"
End If

End Sub

Function GetSelectedRootComponents(assm As SldWorks.AssemblyDoc) As Variant

Dim swComps() As SldWorks.Component2

Dim swSelMgr As SldWorks.SelectionMgr

Set swSelMgr = assm.SelectionManager

Dim i As Integer

For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)

Dim swComp As SldWorks.Component2
Set swComp = swSelMgr.GetSelectedObjectsComponent4(i, -1)

If Not swComp Is Nothing Then

If swComp.GetParent() Is Nothing Then

If (Not swComps) = -1 Then
ReDim swComps(0)
Else
ReDim Preserve swComps(UBound(swComps) + 1)
End If

Set swComps(UBound(swComps)) = swComp

Else
Err.Raise vbError, "", "Only top level components are supported"
End If

End If

Next

If (Not swComps) = -1 Then
GetSelectedRootComponents = Empty
Else
GetSelectedRootComponents = swComps
End If

End Function

Function GetComponentNameForParameter(comp As SldWorks.Component2) As String

Dim instId As Integer
Dim compName As String
compName = comp.Name2
instId = CInt(Right(compName, Len(compName) - InStrRev(compName, "-")))
compName = Left(compName, InStrRev(compName, "-") - 1)

GetComponentNameForParameter = compName & "<" & instId & ">"

End Function

Function HasConfiguration(comp As SldWorks.Component2, confName As String) As Boolean

Dim swRefModel As SldWorks.ModelDoc2
Set swRefModel = comp.GetModelDoc2

Dim vConfs As Variant

If Not swRefModel Is Nothing Then
vConfs = swRefModel.GetConfigurationNames
Else
vConfs = swApp.GetConfigurationNames(comp.GetPathName())
End If

HasConfiguration = Contains(vConfs, confName)

End Function

Function Contains(vArr As Variant, item As String) As Boolean

Contains = False

If Not IsEmpty(vArr) Then

Dim i As Integer

For i = 0 To UBound(vArr)
If LCase(CStr(vArr(i))) = LCase(item) Then
Contains = True
Exit Function
End If
Next

End If

End Function
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
caption: Align Referenced Configurations
title: VBA macro to align referenced configuration of components to assembly configurations
description: VBA macro aligns referenced configuration of selected components in the SOLIDWORKS assembly to the corresponding assembly configurations
image: modify-configurations.png
---

This VBA macro aligns the referenced configurations of all selected components to the corresponding assembly configuration. For example if assembly has 3 configurations **A**, **B** and **C**, then referenced configurations for all selected components will be set to **A**, **B** and **C** in the respective configuration of the assembly.

![Modify component configurations](modify-configurations.png){ width=600 }

Macro processes all root configurations (or optionally all configurations)

~~~ vb
Const ROOT_CONFS_ONLY As Boolean = False 'Process all assembly configurations
~~~

Multiple components can be selected and processed at the same time. Only top level-components are supported. For aligning configurations for sub-assembly, it is required to activate the sub-assembly in its own window.

Components in the lightweight mode are supported.

{% code-snippet { file-name: Macro.vba } %}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 40 additions & 25 deletions solidworks-api/document/assembly/components/copy-path/Macro.vba
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,70 @@ Dim swModel As SldWorks.ModelDoc2

Sub main()

try_:
On Error GoTo catch_

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Dim path As String

If Not swModel Is Nothing Then

Dim swSelMgr As SldWorks.SelectionMgr
Set swSelMgr = swModel.SelectionManager

Dim swComp As SldWorks.Component2
Dim i As Integer

If TypeOf swModel Is SldWorks.AssemblyDoc Then

Set swComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)

ElseIf TypeOf swModel Is SldWorks.DrawingDoc Then

Dim swDrawComp As SldWorks.DrawingComponent
Set swDrawComp = swSelMgr.GetSelectedObjectsComponent4(1, -1)
For i = 1 To swSelMgr.GetSelectedObjectCount2(-1)

Dim swComp As SldWorks.Component2
Set swComp = Nothing

If swDrawComp Is Nothing Then
'for entities selected in graphics view - first seleciton is a view itself
Set swDrawComp = swSelMgr.GetSelectedObjectsComponent4(2, -1)
If TypeOf swModel Is SldWorks.AssemblyDoc Then

Set swComp = swSelMgr.GetSelectedObjectsComponent4(i, -1)

ElseIf TypeOf swModel Is SldWorks.DrawingDoc Then

Dim swDrawComp As SldWorks.DrawingComponent
Set swDrawComp = swSelMgr.GetSelectedObjectsComponent4(i, -1)

If Not swDrawComp Is Nothing Then
Set swComp = swDrawComp.Component
End If

Else
Err.Raise vbError, "", "Only parts and drawings are supported"
End If

If Not swDrawComp Is Nothing Then
Set swComp = swDrawComp.Component
If Not swComp Is Nothing Then
If path <> "" Then
path = path & vbLf
End If
path = path & swComp.GetPathName
End If

Else
MsgBox "Only parts and drawings are supported"
End
End If
Next

If Not swComp Is Nothing Then

Dim path As String
path = swComp.GetPathName
If path <> "" Then
Debug.Print path
SetTextToClipboard path

Else
MsgBox "Please select component"
Err.Raise vbError, "", "Please select components"
End If

Else
MsgBox "Please open document"
Err.Raise vbError, "", "Please open document"
End If

GoTo finally_

catch_:
swApp.SendMsgToUser2 Err.Description, swMessageBoxIcon_e.swMbStop, swMessageBoxBtn_e.swMbOk
finally_:

End Sub

Sub SetTextToClipboard(text As String)
Expand Down
10 changes: 5 additions & 5 deletions solidworks-api/document/assembly/components/copy-path/index.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
layout: sw-tool
title: Macro to copy path of SOLIDWORKS component to clipboard
title: Macro to copy path of SOLIDWORKS components to clipboard
caption: Copy Component Path
description: Macro copies the path of the selected component in assembly or drawing into the clipboard using SOLIDWORKS API
description: Macro copies the path of the selected components in assembly or drawing into the clipboard using SOLIDWORKS API
image: copy-component-path.png
labels: [path, clipboard, component]
group: Assembly
---
![Component selected in the feature tree](selected-component.png){ width=250 }

This macro copies the full path to the selected component into the clipboard using SOLIDWORKS API.
This macro copies the full path to the selected components into the clipboard using SOLIDWORKS API.

* Component can be selected in assembly or drawing document
* Component can be selected in the feature tree or in the graphics area
* Components can be selected in assembly or drawing document
* Components can be selected in the feature tree or in the graphics area
* It is also possible to select a component entity (i.e. face or edge) to get the path to the component

{% code-snippet { file-name: Macro.vba } %}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ image: purged-components-result1.png
labels: [component, replace, purge]
group: Assembly
---
In some cases it might be required to remove (purge) all unused configurations from the components in the assembly. It is in particular useful for the fastener or toolbox components as file can contains thousands of configurations but only few are used in the assembly.
In some cases it might be required to remove (purge) all unused configurations from the components in the assembly. It is in particular useful for the fastener or toolbox components as file can contain thousands of configurations but only few are used in the assembly.

This macro allows to create a copy of all selected components, purge their configurations and replace them in the assembly.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Sub main()
End If

If path <> "" Then
Shell "explorer.exe /select, " & """" & path & """"
Shell "explorer.exe /select, " & """" & path & """", vbMaximizedFocus
Else
MsgBox "Model is not saved"
End If
Expand All @@ -35,4 +35,4 @@ Sub main()
MsgBox "Please open assembly document and select the component"
End If

End Sub
End Sub
6 changes: 3 additions & 3 deletions solidworks-api/document/assembly/compose-flat-bom/Macro.vba
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ Function GetPropertyValue(model As SldWorks.ModelDoc2, conf As String, prpName A
Dim prpVal As String
Dim prpResVal As String

confSpecPrpMgr.Get3 prpName, False, "", prpVal
confSpecPrpMgr.Get3 prpName, False, prpVal, prpResVal

If prpVal = "" Then
If prpResVal = "" Then
genPrpMgr.Get3 prpName, False, prpVal, prpResVal
End If

GetPropertyValue = prpResVal

End Function
End Function
Loading