Skip to content

Commit cd4a660

Browse files
committed
Added the scale imported file example
1 parent d38e92c commit cd4a660

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Const SCALE_FACTOR As Double = 2.5
2+
3+
Dim swApp As SldWorks.SldWorks
4+
5+
Sub main()
6+
7+
Set swApp = Application.SldWorks
8+
9+
Dim swModel As SldWorks.ModelDoc2
10+
11+
Dim errs As Long
12+
Set swModel = swApp.ActiveDoc
13+
14+
If Not swModel Is Nothing Then
15+
16+
Dim swFeat As SldWorks.Feature
17+
18+
Dim i As Integer
19+
i = -1
20+
21+
Do
22+
i = i + 1
23+
Set swFeat = swModel.FeatureByPositionReverse(i)
24+
25+
If swFeat.GetTypeName2() = "BaseBody" Then
26+
27+
Dim swBody As SldWorks.Body2
28+
29+
Set swBody = swFeat.GetFaces()(0).GetBody
30+
Set swBody = swBody.Copy
31+
32+
ApplyScale swBody, SCALE_FACTOR
33+
34+
swFeat.SetBody swBody
35+
36+
End If
37+
38+
If swFeat.GetTypeName2() = "OriginProfileFeature" Then
39+
Exit Do
40+
End If
41+
42+
Loop While Not swFeat Is Nothing
43+
44+
Else
45+
Err.Raise vbError, "", "Failed to load model: " & errs
46+
End If
47+
48+
End Sub
49+
50+
Sub ApplyScale(body As SldWorks.Body2, scaleFactor As Double)
51+
52+
Dim dMatrix(15) As Double
53+
dMatrix(0) = 1: dMatrix(1) = 0: dMatrix(2) = 0: dMatrix(3) = 0
54+
dMatrix(4) = 1: dMatrix(5) = 0: dMatrix(6) = 0: dMatrix(7) = 0
55+
dMatrix(8) = 1: dMatrix(9) = 0: dMatrix(10) = 0: dMatrix(11) = 0
56+
dMatrix(12) = scaleFactor: dMatrix(13) = 0: dMatrix(14) = 0: dMatrix(15) = 0
57+
58+
Dim swMathUtils As SldWorks.MathUtility
59+
Set swMathUtils = swApp.GetMathUtility
60+
61+
Dim swMathTransform As SldWorks.MathTransform
62+
Set swMathTransform = swMathUtils.CreateTransform(dMatrix)
63+
64+
body.ApplyTransform swMathTransform
65+
66+
End Sub
29.8 KB
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
caption: Scale Imported Geometry
3+
title: VBA macro to scale the geometry of the imported features using SOLIDWORKS API
4+
description: VBA macro scales the bodies from the imported features of the foreign formats (e.g. STEP, IGES) with the specified scale factor
5+
image: imported-feature.png
6+
---
7+
![Imported geometry feature](imported-feature.png){ width=250 }
8+
9+
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.
10+
11+
Set the scale factor in the **SCALE_FACTOR** constant.
12+
13+
{% code-snippet { file-name: Macro.vba } %}

0 commit comments

Comments
 (0)