VBA script to import acs CONNECT Edition

I have a vba script to import an acs saved in a file that I would like to import. I have recorded the macro and converted it to vba. However the code doesn't include which model is selected and which acs is to be selected from the model.

These are the lines I'm referring to

    If DialogBoxName = "Select Models" Then

    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK

    End If  ' Select Models

    If DialogBoxName = "Select Auxiliary Coordinate Systems to Import" Then

    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK

    End If  ' Select Auxiliary Coordinate Systems to Import

Here is the class module

Implements IModalDialogEvents
Private Sub IModalDialogEvents_OnDialogClosed(ByVal DialogBoxName As String, ByVal DialogResult As MsdDialogBoxResult)

End Sub

Private Sub IModalDialogEvents_OnDialogOpened(ByVal DialogBoxName As String, DialogResult As MsdDialogBoxResult)

    If DialogBoxName = "Import Auxiliary Coordinate Systems" Then

        CadInputQueue.SendKeyin "MDL COMMAND MGDSHOOK,fileList_setDirectoryCmd F:\IOP\EW\02_Plant\99_CAD\Dev\DEV_FMG_WorkSpace_V2\BuildingDatasets\Dataset_ANZ\data\"

        CadInputQueue.SendKeyin "MDL COMMAND MGDSHOOK,fileList_setFileNameCmd ACS_EWPG.dgn"

    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK

    End If  ' Import Auxiliary Coordinate Systems

    If DialogBoxName = "Select Models" Then

    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK

    End If  ' Select Models

    If DialogBoxName = "Select Auxiliary Coordinate Systems to Import" Then

    '   Remove the following line to let the user close the dialog box.
        DialogResult = msdDialogBoxResultOK

    End If  ' Select Auxiliary Coordinate Systems to Import

End Sub

Parents
  • Hi Simon,

    I agree with Jan´s response on this issue, there is no guarantee that recorded code is complete and always directly can be used.
    Here a code example which follows the suggestions Jan gave.
    This worked for me also in CONNECT Edition.

    Bets regards,

    Artur

    Option Explicit
    
    Sub importACSTest()
    Dim sPath As String
    Dim oWorkDgn As DesignFile
    Dim oMod As ModelReference
    Dim oMods As ModelReferences
    Dim ee As ElementEnumerator
    Dim bFound As Boolean
    Dim oACS As AuxiliaryCoordinateSystemElement
    Dim oCC As CopyContext
        
        sPath = ActiveDesignFile.Path  ' path to the workfile with ACS to import
        Set oWorkDgn = OpenDesignFileForProgram(sPath + "/" + "acsfrom.dgn", True)  ' full filename to search for ACS
       
        Set oMod = oWorkDgn.Models("3D Metric Design") ' Modelname to search for
        If Not oMod Is Nothing Then
            Set ee = oMod.ControlElementCache.Scan()
            bFound = False
            Do While ee.MoveNext
                If ee.Current.IsAuxiliaryCoordinateSystemElement Then
                    If ee.Current.AsAuxiliaryCoordinateSystemElement.Name = "test1" Then ' ACS name to search for
                        Set oACS = ee.Current.AsAuxiliaryCoordinateSystemElement
                        bFound = True
                        Exit Do
                    End If
                End If
            Loop
            If bFound Then
                ActiveModelReference.CopyElement oACS, oCC
            End If
        End If
        oWorkDgn.Close
    End Sub
    
    
    

Reply
  • Hi Simon,

    I agree with Jan´s response on this issue, there is no guarantee that recorded code is complete and always directly can be used.
    Here a code example which follows the suggestions Jan gave.
    This worked for me also in CONNECT Edition.

    Bets regards,

    Artur

    Option Explicit
    
    Sub importACSTest()
    Dim sPath As String
    Dim oWorkDgn As DesignFile
    Dim oMod As ModelReference
    Dim oMods As ModelReferences
    Dim ee As ElementEnumerator
    Dim bFound As Boolean
    Dim oACS As AuxiliaryCoordinateSystemElement
    Dim oCC As CopyContext
        
        sPath = ActiveDesignFile.Path  ' path to the workfile with ACS to import
        Set oWorkDgn = OpenDesignFileForProgram(sPath + "/" + "acsfrom.dgn", True)  ' full filename to search for ACS
       
        Set oMod = oWorkDgn.Models("3D Metric Design") ' Modelname to search for
        If Not oMod Is Nothing Then
            Set ee = oMod.ControlElementCache.Scan()
            bFound = False
            Do While ee.MoveNext
                If ee.Current.IsAuxiliaryCoordinateSystemElement Then
                    If ee.Current.AsAuxiliaryCoordinateSystemElement.Name = "test1" Then ' ACS name to search for
                        Set oACS = ee.Current.AsAuxiliaryCoordinateSystemElement
                        bFound = True
                        Exit Do
                    End If
                End If
            Loop
            If bFound Then
                ActiveModelReference.CopyElement oACS, oCC
            End If
        End If
        oWorkDgn.Close
    End Sub
    
    
    

Children