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
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
Hi Artur
Thankyou for the code.
I'm having an issue the code runs fine, it finds the ACS but it doesn't copy into the active file. From the image below it has exited the loop and the If block but it still returns oCC = Nothing. Can you please advise what I might be doing wrong.
Here is the code I am using, its the same as per your example with the inclusion of a few debug statement
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 + "/" + "EW_ACS.dgn", True) ' full filename to search for ACS Set oMod = oWorkDgn.Models("Design Model") ' Modelname to search for Debug.Print oMod.Name 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 = "OPF_ACS" Then ' ACS name to search for Set oACS = ee.Current.AsAuxiliaryCoordinateSystemElement bFound = True Debug.Print oACS.Name Exit Do End If End If Loop If bFound Then ActiveModelReference.CopyElement oACS, oCC End If End If oWorkDgn.Close End Sub
Simon Biddle said:Here is the code I am using
Dim oCC As CopyContext
Simon Biddle said: it still returns oCC = Nothin
CopyContext is a VBA class. Until you create an object of that class your variable will be Nothing. Try this:
CopyContext
Nothing
Set oCC = New CopyContext
Regards, Jon Summers LA Solutions
Hi Jon
The code Artur provided worked and it also works by creating an object of the class as you suggested. The problem is the ACS that I am copying in doesn't display in the ACS manager unless I exit the file and reopen. Do I need to call redraw on the oACS?
Simon Biddle said:the ACS that I am copying in doesn't display in the ACS manager unless I exit the file and reopen
Does your new ACS show if you close and reopen the ACS manager?
Yes it does show up after closing. Is it possible to refresh the dialog without reopening it?