반응형
ICustomPropertyManager 인터페이스를 통해 다양한 종류의 사용자 정의 속성을 일관되게 관리할 수 있지만, 각 속성 유형에 맞게 인터페이스의 인스턴스를 적절히 가져와야 합니다.파일별(일반) 사용자 정의 속성에 연결하려면 IModelDocExtension::CustomPropertyManager 속성을 호출하고 속성 매개변수로 빈 문자열("")을 전달해야 합니다.이렇게 하면 해당 문서에 대한 일반적인 사용자 정의 속성 관리자를 얻을 수 있습니다. 아래 코드를 사용 합니다
Dim swModel As SldWorks.ModelDoc2
Dim swExtension As ModelDocExtension
Dim customPropManager As CustomPropertyManager
Set swExtension = swModel.Extension
Set customPropManager = swExtension.Extension.CustomPropertyManager("")
ddebug.print customPropManager.count '// 모델에 저장된 Property 수량
▷ 보다 자세한 내용은 블로그를 참고 하세요.
□ 모델의 Property 값들을 가져오고, 수정 하는 프로그램
일반 Part 파일의 Property 이름들 및 유형, 값들을 가져 올수 있고, 값들을 수정 할수 있습니다.
▷ Solidwork 연결 모듈 Code (모듈 이름 : SolidworksStart)
Public swApp As SldWorks.SldWorks
Public swModel As ModelDoc2
Public Sub SolidworksStart()
On Error Resume Next
'// Setting up SolidWorks application objects
Set swApp = GetObject(, "SldWorks.Application")
On Error GoTo 0
If swApp Is Nothing Then
MsgBox "Make sure SolidWorks is running.", vbCritical
Exit Sub
End If
'// Get currently active document
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "There are no active SolidWorks documents.", vbCritical
Exit Sub
End If
End Sub
▷ Solidwork Property Name, Type, Value
1. Reflash Button Code
Option Explicit
Dim WS As Worksheet
Dim swExtension As ModelDocExtension
Dim customPropManager As CustomPropertyManager
Dim vPropertyNames As Variant
Sub ExportPropertyToExcel()
On Error Resume Next
Call SolidworksStart.SolidworksStart
Set WS = ThisWorkbook.Worksheets("Parameter01")
On Error GoTo 0
Set swExtension = swModel.Extension
Set customPropManager = swExtension.CustomPropertyManager("")
'// GetProperty names and values
vPropertyNames = customPropManager.GetNames
Dim i As Long
If Not IsEmpty(vPropertyNames) Then
For i = LBound(vPropertyNames) To UBound(vPropertyNames)
WS.Cells(i + 10, "A") = i + 1
WS.Cells(i + 10, "B") = vPropertyNames(i)
WS.Cells(i + 10, "C") = customPropManager.GetType2(vPropertyNames(i))
WS.Cells(i + 10, "D") = customPropManager.Get(vPropertyNames(i))
Next i
Else
swApp.SendMsgToUser "This model has noProperty."
End If
'// Display model name
WS.Cells(8, "C").value = swModel.GetTitle
MsgBox "SOLIDWORKS model data has been exported to Excel..", vbInformation
End Sub
2. Update Button Code
Sub PropertyUpdate()
Dim WS As Worksheet
Dim swCustPropMgr As CustomPropertyManager
Dim swExtension As ModelDocExtension
Dim propertyName As String
Dim propertyValue As String
On Error Resume Next
Call SolidworksStart.SolidworksStart
Set WS = ThisWorkbook.Worksheets("Parameter01")
On Error GoTo 0
' Import Custom Property Manager
Set swExtension = swModel.Extension
Set swCustPropMgr = swExtension.CustomPropertyManager("")
Dim lastRow As Range
Dim j As Long
Dim result As Long
Set lastRow = WS.Range("B10", Cells(Rows.Count, "B").End(xlUp))
For j = 0 To lastRow.Count - 1
propertyName = WS.Cells(j + 10, "B")
propertyValue = WS.Cells(j + 10, "D")
result = swCustPropMgr.Add3(propertyName, swCustomInfoType_e.swCustomInfoText, propertyValue, swCustomPropertyAddOption_e.swCustomPropertyReplaceValue)
Next j
' Model Update
swModel.ForceRebuild3 False
MsgBox "Updated the properties of the SOLIDWORKS model..", vbInformation
End Sub
3. Reset Button Code
Sub DeleteRowsBelow02()
Dim WS As Worksheet
Dim shp As Shape
Dim Count As Integer
Dim TargetRange As Range
Set WS = ThisWorkbook.Worksheets("Parameter01")
Count = 0
'// Clear the contents of Part Name
WS.Range("C8:D8").ClearContents
' Clear the contents of rows from row 10 to the last row
WS.Rows(10 & ":" & WS.Rows.Count).ClearContents
' Display a message box
MsgBox "Cell has been initialized!", vbInformation, "https://tool-2020.tistory.com/"
End Sub
by korealionkk@gmail.com
'VBA SOLIDWORK' 카테고리의 다른 글
Get the name of the currently open file (0) | 2024.12.30 |
---|---|
이미지 만들기 -SAMPLE (0) | 2024.12.26 |
Change Dimension Example (VBA) (0) | 2024.12.25 |
모델의 Feature Name, Type, ID 및 Dimensions Name, value 가져오기 (0) | 2024.12.25 |
3.SldWorks.Feature 개념 (0) | 2024.12.25 |