Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

RE: Displaying levels in attachment using OpenDesignForProgramming

$
0
0

[quote user="James Manfield"]

Hi Barry.

Sorry for the lack of clarity.  I will explain (hopefully) a little more clearly.  I have several hundred files each containing three models; "3D-modell", "Drawing" and "Ritdef".  The "3D-modell" model is referenced into the "Drawing" model.  What  I need to do is go through each of these "Drawing" models  and (amongst other things) ensure that all of the levels for the reference attachment "3D-modell" are displayed. Sorry for the mixture of the English "Drawing" and Swedish "Modell".... I did not create these files..

I have a script which does the job nicely as long as I am working in the ActiveModelReference, but I want to automate this process to go through every dgn file in a number of sub-folders and perform the same action upon them.

I hope that makes it a bit clearer....

/James

[/quote]

Ok understood,

I've found that OpenDesignFileForProgram won't work for this operation so you need to use OpenDesignFile. Additionally your original code did not include a rewrite line so had you been able to access the levels collection in the reference file, your changes would not have been written to the file. Finally the use of IsDisplayed turns on global display of a level not view display so I've added code for the levels to be visible in view 1.

The following code does work though I'm sure it could be improved and perhaps split down further as per Jan's example but it should give you a working start. I've tested it on a test folder structure with 2 No. top-level folders with sub-folders within and it has been turning on all levels with the 3d-modell reference file attached to Drawing model in each test dgn file.

I've added some code in the Main procedure to create a temporary MS_DESIGNDIR variable as that's a custom variable that doesn't form part of my workspace so you'll have no issue removing those lines and any associated variables.

Option Explicit

Const CfgVar_sDesignDirPath                  As String = "$(MS_DESIGNDIR)"
Public oMSAPP                                As MicroStationDGN.Application

Sub Main()
Dim myFSO                                    As FileSystemObject
Dim myFSORoot                                As folder
Dim sDesignDirPath                           As String

    Set myFSO = CreateObject("Scripting.FileSystemObject")
    Set oMSAPP = New MicroStationDGN.Application

    CadInputQueue.SendCommand "expand set MS_DESIGNDIR = C:\Users\bla76925\Desktop\DesignDir\"
    sDesignDirPath = ActiveWorkspace.ExpandConfigurationVariable(CfgVar_sDesignDirPath)

    Set myFSORoot = myFSO.GetFolder(ActiveWorkspace.ConfigurationVariableValue("MS_DESIGNDIR", True))

    ProcessFolder myFSORoot
    oMSAPP.Quit
End Sub

Sub ProcessFolder(ByVal TargetFolder As folder)
Dim SubFolder                                As folder
    Debug.Print TargetFolder.Path
    ProcessFiles TargetFolder
    For Each SubFolder In TargetFolder.SubFolders
        ProcessFolder SubFolder
    Next SubFolder
End Sub

Sub ProcessFiles(ByVal ParentFolder As folder)
Dim FSOFile                                  As File
Dim lViewIndex                               As Long
Dim myDGN                                    As DesignFile
Dim oAttachment                              As Attachment
Dim oLevel                                   As Level
Dim oLevels                                  As Levels
Dim oModel                                   As ModelReference
Dim oView                                    As View

    For Each FSOFile In ParentFolder.Files
        If Right(FSOFile.Name, 4) = ".dgn" Then
            Debug.Print FSOFile.Name
            Set myDGN = oMSAPP.OpenDesignFile(FSOFile.Path, False)

            For Each oModel In myDGN.Models
                If oModel.Name = "Drawing" Then
                    For Each oAttachment In oModel.Attachments
                        Set oLevels = oAttachment.Levels
                        If oAttachment.AttachName = myDGN.Name Then
                            If oAttachment.AttachModelName = "3D-modell" Then

                                lViewIndex = 1
                                Set oView = myDGN.Views(lViewIndex)

                                For Each oLevel In oAttachment.Levels
                                    If oLevel.IsDisplayedInView(oView) = False Then
                                        oLevel.IsDisplayedInView(oView) = True
                                    End If
                                    oLevels.Rewrite
                                    RedrawAllViews
                                Next oLevel
                            End If
                        End If
                    Next oAttachment
                End If
            Next oModel
            myDGN.Save
            myDGN.Close
        End If
    Next FSOFile
End Sub

Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>