Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
66 changes: 66 additions & 0 deletions solidworks-api/import-export/scale-imported-part/Macro.vba
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Const SCALE_FACTOR As Double = 2.5

Dim swApp As SldWorks.SldWorks

Sub main()

Set swApp = Application.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim errs As Long
Set swModel = swApp.ActiveDoc

If Not swModel Is Nothing Then

Dim swFeat As SldWorks.Feature

Dim i As Integer
i = -1

Do
i = i + 1
Set swFeat = swModel.FeatureByPositionReverse(i)

If swFeat.GetTypeName2() = "BaseBody" Then

Dim swBody As SldWorks.Body2

Set swBody = swFeat.GetFaces()(0).GetBody
Set swBody = swBody.Copy

ApplyScale swBody, SCALE_FACTOR

swFeat.SetBody swBody

End If

If swFeat.GetTypeName2() = "OriginProfileFeature" Then
Exit Do
End If

Loop While Not swFeat Is Nothing

Else
Err.Raise vbError, "", "Failed to load model: " & errs
End If

End Sub

Sub ApplyScale(body As SldWorks.Body2, scaleFactor As Double)

Dim dMatrix(15) As Double
dMatrix(0) = 1: dMatrix(1) = 0: dMatrix(2) = 0: dMatrix(3) = 0
dMatrix(4) = 1: dMatrix(5) = 0: dMatrix(6) = 0: dMatrix(7) = 0
dMatrix(8) = 1: dMatrix(9) = 0: dMatrix(10) = 0: dMatrix(11) = 0
dMatrix(12) = scaleFactor: dMatrix(13) = 0: dMatrix(14) = 0: dMatrix(15) = 0

Dim swMathUtils As SldWorks.MathUtility
Set swMathUtils = swApp.GetMathUtility

Dim swMathTransform As SldWorks.MathTransform
Set swMathTransform = swMathUtils.CreateTransform(dMatrix)

body.ApplyTransform swMathTransform

End Sub
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions solidworks-api/import-export/scale-imported-part/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
caption: Scale Imported Geometry
title: VBA macro to scale the geometry of the imported features using SOLIDWORKS API
description: VBA macro scales the bodies from the imported features of the foreign formats (e.g. STEP, IGES) with the specified scale factor
image: imported-feature.png
---
![Imported geometry feature](imported-feature.png){ width=250 }

This VBA macro scales all bodies form the imported features in active SOLIDWORKS part file. THe imported features will be generated if file is loaded from neutral formats like STEP, IGES, Parasolid unless 3D Interconnect option is used.

Set the scale factor in the **SCALE_FACTOR** constant.

{% code-snippet { file-name: Macro.vba } %}