AnsweredAssumed Answered

I want to make an old macrocode a new macrocode

Question asked by 福 谷 勇 時 on Apr 14, 2020
Latest reply on Apr 14, 2020 by Tapani Sjoman

Please tell me.

Please change this macrocode into the cord which is readable in SolidWorks2020

We would greatly appreciate your response.

 

 

Dim intDocType As Integer
        Dim intVersion As Integer
        Dim intOptions As Integer
        Dim intErrors As Integer
        Dim intWarnings As Integer
        Dim blnRetval As Boolean

 

        If ParentModelDoc2.GetType = swDocumentTypes_e.swDocASSEMBLY Then
            Dim swConfMgr As SldWorks.ConfigurationManager = ParentModelDoc2.ConfigurationManager
            Dim swConf As SldWorks.Configuration = swConfMgr.ActiveConfiguration
            Dim swComp As SldWorks.Component2 = swConf.GetRootComponent
            Dim CiledCompornents() As Object = swComp.GetChildren()
            If CiledCompornents.Length > 0 Then
                For i As Integer = 0 To CiledCompornents.GetUpperBound(0)

 

                    Dim CiledCompornent As SldWorks.Component2 = CiledCompornents(i)
                    Dim CiledFilePath As String = CiledCompornent.GetPathName
                    Dim CiledFileExtention As String = New FileInfo(CiledFilePath).Extension.ToLower.Replace(".", "")
                    Select Case CiledFileExtention
                        Case "sldprt" : intDocType = swDocumentTypes_e.swDocPART
                        Case "sldasm" : intDocType = swDocumentTypes_e.swDocASSEMBLY
                        Case "slddrw" : intDocType = swDocumentTypes_e.swDocDRAWING
                    End Select
                    intOptions = swOpenDocOptions_e.swOpenDocOptions_Silent Or swOpenDocOptions_e.swOpenDocOptions_AutoMissingConfig
                    intErrors = 0
                    intWarnings = 0
                    Dim swModelDoc2 As SldWorks.ModelDoc2 = swApp.OpenDoc6(CiledFilePath, intDocType, intOptions, "", intErrors, intWarnings)
                    If intWarnings = SwConst.swFileLoadWarning_e.swFileLoadWarning_AlreadyOpen Then
                        swModelDoc2 = swApp.ActivateDoc2(CiledFilePath, True, intErrors)
                    End If
                    My.Application.DoEvents()

 

                    Call SaveComponentDiver(swModelDoc2)

 

                    swModelDoc2 = Nothing
                    CiledCompornent = Nothing
                Next
            End If
            CiledCompornents = Nothing
            swComp = Nothing
            swConf = Nothing
            swConfMgr = Nothing
        End If

 


        ParentModelDoc2.ForceRebuild3(True)
        My.Application.DoEvents()

 

        Dim FileName As String = ""
        If ParentModelDoc2.GetPathName <> "" Then
            FileName = New FileInfo(ParentModelDoc2.GetPathName).Name
        Else
            Select Case ParentModelDoc2.GetType
                Case swDocumentTypes_e.swDocPART : FileName = ParentModelDoc2.GetTitle & ".sldprt"
                Case swDocumentTypes_e.swDocASSEMBLY : FileName = ParentModelDoc2.GetTitle & ".sldasm"
                Case swDocumentTypes_e.swDocDRAWING : FileName = ParentModelDoc2.GetTitle & ".slddrw"
            End Select
        End If
        Dim FilePath As String = TextBox1.Text.TrimEnd("\") & "\" & FileName

 

        intVersion = swSaveAsVersion_e.swSaveAsCurrentVersion
        intOptions = swSaveAsOptions_e.swSaveAsOptions_Silent
        blnRetval = ParentModelDoc2.SaveAs4(FilePath, intVersion, intOptions, intErrors, intWarnings)
        My.Application.DoEvents()

 

        swApp.CloseDoc(ParentModelDoc2.GetTitle)
        ParentModelDoc2 = Nothing
        My.Application.DoEvents()

Outcomes