VBA SOLIDWORK
모델의 치수 이름 및 값을 가져오는 기능
ToolBOX01
2024. 12. 17. 12:09
□ SolidWorks Dimension
SolidWorks에서 치수는 스케치나 피처에 연결된 객체로, 특정 형식의 이름을 가지며 이는 고유한 구조를 따릅니다.
▷ 모델의 SolidWorks 치수 구조
SolidWorks에서 치수 이름은 "치수ID@스케치명(ProfileFeature)" 또는 "치수ID@피처명(Extrusion,Fillet . .. )" 형식으로 되어 있습니다.
D1@Sketch1: Sketch1에 있는 첫 번째 치수
D2@Boss-Extrude1: Boss-Extrude1 피처에 있는 두 번째 치수
치수의 ID는 해당 스케치나 피처 내에서 고유하며, 스케치 또는 피처에 따라 다르게 할당됩니다.
▷ 모델에서 치수 이름은 중복 가능 ?
치수 이름은 모델 전체에서 중복될 수 없습니다. 동일한 스케치 (ProfileFeature) 나 Feature 내에서는 치수 이름이 중복될 수 없지만, 다른 스케치 또는 Feature 에서는 동일한 이름이 허용됩니다.
예: D1@Sketch1과 D1@Sketch2는 공존 가능
그러나 동일 스케치 내에서 D1@Sketch1과 또 다른 D1@Sketch1은 불가능
▷ 프로그램 실행
▷ code
Dim swApp As Object
Dim swModel As ModelDoc2
Dim swFeature As Feature
Dim swDispDim As DisplayDimension
Dim swDim As Dimension
Dim featureName As String
Option Explicit
Sub Dimension01()
' // Import SolidWorks Application References
Set swApp = GetObject(, "SldWorks.Application")
Set swModel = swApp.ActiveDoc
'// Check the activated document
If swModel Is Nothing Then
MsgBox "There are no active models.", vbCritical
Exit Sub
End If
Dim i As Long
i = 0
'// Navigate the Feature List in a Part File
Set swFeature = swModel.FirstFeature
Do While Not swFeature Is Nothing
featureName = swFeature.Name
Debug.Print "Feature: " & swFeature.GetTypeName
If swFeature.GetTypeName <> "ProfileFeature" Then
'// Explore dimensions in that feature
Set swDispDim = swFeature.GetFirstDisplayDimension
Do While Not swDispDim Is Nothing
' // Get dimension object
Set swDim = swDispDim.GetDimension
'// Output dimension names and values
Worksheets("Program03").Cells(i + 5, "A") = i + 1
Worksheets("Program03").Cells(i + 5, "B") = swDim.FullName
Worksheets("Program03").Cells(i + 5, "C") = swDim.Value
' //Move to next dimension
Set swDispDim = swFeature.GetNextDisplayDimension(swDispDim)
i = i + 1
Loop
End If
' // Go to next feature
Set swFeature = swFeature.GetNextFeature
Loop
MsgBox "Dimension extraction complete!", vbInformation
End Sub