본문 바로가기
  • Welcome!
VBA SOLIDWORK

VBA API 설치 및 설정

by ToolBOX01 2024. 12. 11.
반응형

[SolidWorks API Option]

 

 

Macros for SOLIDWORKS: the absolute basics

If you have never written SOLIDWORKS macros before, this is the post for you. We'll explain variables, the VBA editor and debugging.

cadbooster.com

 

[API Hierarchy]

 

▷ SolidWorks를 실행 시키는 Code

Sub Opensw()
    Dim Ows As SldWorks.SldWorks
    Set Ows = CreateObject("sldworks.application")
    
    Ows.Visible = True
    Ows.SendMsgToUser "solidworks is open"
    
End Sub

 

▷ SolidWorks에 Open된 모델의 이름을 가져오는 Code

Option Explicit
Sub  GetModelName()
    
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim modelName As String
    
    '// 이미 실행 중인 SolidWorks 찾기
    Set swApp = GetObject(, "SldWorks.Application")
    Set swModel = swApp.IActiveDoc
    
    If Not swModel Is Nothing Then
        swApp.SendMsgToUser "현재 모델의 이름: " & swModel.GetTitle
    Else
        swApp.SendMsgToUser "활성화된 문서가 없습니다."
    End If
    
 End Sub