Dear VBA Experts,
I am trying to write some codes which will help me batch process levels visibility on multiple models in several DGN files. The codes I have written is posted below. My codes work perfectly fine when I open the DGN and activate each models at least once. But as a part of the batch process this code only works on the active model but throws error when I refer to other models in the DGN file. I come to realize that in non-active models the references are not loaded. How can I edit this code so I can tell MicroStation to load all references so that the codes will find whats it looking for. In this case the levels in the referenced file.
I tried activating models before it moves on to next model but with no luck. It breaks with an error message saying the reference index were not found. Any help or thoughts would be great.
Sincerely,
Rabi
Option Explicit Private Declare Function mdlModelRef_loadReferenceModels Lib "stdmdlbltin.dll" (ByVal modelRef As Long, _ ByVal loadCache As Long, ByVal loadRasterRefs As Long, ByVal loadUndisplayedRefs As Long) As Long Sub ControlLayerVisibility()
'On Error Resume Next Dim myDGN As DesignFile Set myDGN = Application.ActiveDesignFile Dim myActiveModel As ModelReference Dim oAtt As Attachment 'Determine the sheet model with msdModelTypeSheet property Dim modelCount As Integer Dim myModel As String Dim tempString As String Dim myView As View For modelCount = 1 To myDGN.Models.Count If myDGN.Models(modelCount).Type = msdModelTypeSheet Then tempString = myDGN.Models(modelCount).Name Dim myLevel As String Dim myModelLogicalName As String Dim myAttachmentIndex As Integer Dim i As Integer If InStr(1, tempString, "RECORD") > 0 Then myModel = myDGN.Models(modelCount).Name 'Determine the Attachment Index and run the levels. ' For i = 1 To myDGN.Models(myModel).Attachments.Count ' 'Debug.Print myDGN.Models(myModel).Attachments(i).AttachName ' If myDGN.Models(myModel).Attachments(i).AttachName = "50014746_TB 30x42.dgn" Then ' myAttachmentIndex = i ' myModelLogicalName = myDGN.Models(myModel).Attachments(myAttachmentIndex).AttachName ' End If ' Next Set myActiveModel = myDGN.Models(myModel) 'myActiveModel.Activate Set myActiveModel = myActiveModel.DesignFile.Models("50014746_TB 30x42.dgn") mdlModelRef_loadReferenceModels myActiveModel.MdlModelRefP, 1, 1, 1 Set oAtt = myActiveModel.Attachments("default") 'If myActiveModel.IsReadOnly = True Then 'myDGN.Models(myModel).Activate For Each myView In myDGN.Views oAtt.Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayed = True oAtt.Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayedInView(myView) = True oAtt.Levels("G-ANNO-TTLB-AS BUILT").IsDisplayed = False oAtt.Levels("G-ANNO-TTLB-AS BUILT").IsDisplayedInView(myView) = False ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayed = True ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayedInView(myView) = True ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-AS BUILT").IsDisplayed = False ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-AS BUILT").IsDisplayedInView(myView) = False ' 'myLevel = "LEVEL SET DISPLAY ON file:" & myModelLogicalName & " """ & Row.Value & """" myView.Redraw Next myView 'End If 'Close the file appropriately myDGN.Models(myModel).Levels.Rewrite CadInputQueue.SendCommand "FILEDESIGN" CadInputQueue.SendCommand "SAVE DESIGN" End If End If Next End Sub
'On Error Resume Next
Dim myDGN As DesignFile Set myDGN = Application.ActiveDesignFile
Dim myActiveModel As ModelReference Dim oAtt As Attachment
'Determine the sheet model with msdModelTypeSheet property Dim modelCount As Integer Dim myModel As String Dim tempString As String Dim myView As View
For modelCount = 1 To myDGN.Models.Count If myDGN.Models(modelCount).Type = msdModelTypeSheet Then tempString = myDGN.Models(modelCount).Name Dim myLevel As String Dim myModelLogicalName As String Dim myAttachmentIndex As Integer Dim i As Integer
If InStr(1, tempString, "RECORD") > 0 Then myModel = myDGN.Models(modelCount).Name 'Determine the Attachment Index and run the levels. ' For i = 1 To myDGN.Models(myModel).Attachments.Count ' 'Debug.Print myDGN.Models(myModel).Attachments(i).AttachName ' If myDGN.Models(myModel).Attachments(i).AttachName = "50014746_TB 30x42.dgn" Then ' myAttachmentIndex = i ' myModelLogicalName = myDGN.Models(myModel).Attachments(myAttachmentIndex).AttachName ' End If ' Next Set myActiveModel = myDGN.Models(myModel) 'myActiveModel.Activate Set myActiveModel = myActiveModel.DesignFile.Models("50014746_TB 30x42.dgn") mdlModelRef_loadReferenceModels myActiveModel.MdlModelRefP, 1, 1, 1
Set oAtt = myActiveModel.Attachments("default") 'If myActiveModel.IsReadOnly = True Then 'myDGN.Models(myModel).Activate For Each myView In myDGN.Views oAtt.Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayed = True oAtt.Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayedInView(myView) = True oAtt.Levels("G-ANNO-TTLB-AS BUILT").IsDisplayed = False oAtt.Levels("G-ANNO-TTLB-AS BUILT").IsDisplayedInView(myView) = False ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayed = True ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-NO AS BUILT").IsDisplayedInView(myView) = True ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-AS BUILT").IsDisplayed = False ' myDGN.Models(myModel).Attachments(myAttachmentIndex).Levels("G-ANNO-TTLB-AS BUILT").IsDisplayedInView(myView) = False ' 'myLevel = "LEVEL SET DISPLAY ON file:" & myModelLogicalName & " """ & Row.Value & """" myView.Redraw Next myView 'End If 'Close the file appropriately myDGN.Models(myModel).Levels.Rewrite
CadInputQueue.SendCommand "FILEDESIGN" CadInputQueue.SendCommand "SAVE DESIGN"
End If
Next
End Sub
Unknown said:ustn.OpenDesignFile(kvpFileDictionary.Key, True)
That line instructs MicroStation to open the file read-only! From VBA Help ...
Regards, Jon Summers LA Solutions
Jon,
I was sure I had the parameter as False at one time. That was it... Thanks. Now I only I have to deal with and live with the fact the each dgn file must be phyiscally opened to modify their respective models. I will call this a programmatic limitation.
Marty Robbins
Unknown said: Each dgn file must be phyiscally opened to modify their respective models. I will call this a programmatic limitation
You can't do anything to the contents of any file unless you open it first. For example, change 'DGN' to 'Word document'. To review, print or edit a document you must open it using an application (usually, in this example, Word), with minimum access right 'read-only'. If you want to edit a document you must open it with 'read-write' access. A DGN file is no different.
Marty,
You should look into batch process to apply all your changes to mulitiple files. Batch Process will open make the change close each file. It will take minutes to process many files.
Good luck, Roland
Roland
V8i SS4 v.08.11.09,829AECOsim BD V8i
Roland,
I am basically doing a batch process. However, initially I did not want to physicall open the file, The program does work now.
I have another question... For Roland, Jon or whomever. I could find a forum to post this question to, so if it is not the correct location for this question, please redirect me.
My addin works correct on local installs and I have a installation package that I send out to my end users. However, I have been attempting to install this on the network. Of course I get this message
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers.
at fwdptrem.fwdptrem.vbAddInMain..ctor(IntPtr mdlDesc)
The action that failed was:
Our IT department has our Intranet security set to low. This can not be changed.
I signed the dll using the Bentley SDK dllsign.exe and separatley signed the dll using the visual studio tools signtool.exe and I assigned the dll a Strong Name using the SN.exe tool and project propeties.
In my AssemblyInfo.vb, as shown, I am allowing partially trusted callers -
<Assembly: ComVisible(False)>
'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("6afecf8b-0653-4f64-b708-d0efe4db8a50")>
'<Assembly: AssemblyVersion("1.1.2.1")>
<Assembly: AssemblyFileVersion("1.1.2.1")>
'<Assembly: CLSCompliant(True)>
<Assembly: Security.AllowPartiallyTrustedCallers()>
Note this is signed with a test certificate, If this makes a difference. My digital signatures states that the signature is OK.
Unknown said:My addin works correct on local installs and I have a installation package that I send out to my end users. However, I have been attempting to install this on the network.
This is a Microsoft .NET generic question of security on networks. It doesn't apply specifically to MicroStation.
Microsoft prefers that a user cannot execute an EXE or DLL across a network. I believe that in the extreme case — where the executable resides on a public network — there's no way to get around that security. You can't execute a DLL on a public network, and that's that.
On 'trusted' networks, you (by which I mean network admin.) have the option of lowering security to permit invocation of remote DLLs. However, as you have found, this boils down to what your IT people think of as 'safe'. If IT have a policy that any DLL other than one installed locally is a security risk, then you have no option but to install your DLL individually on each & every computer, where needed, in the organisation. However, IT should also be able to tell you how to distribute your installation package, and they may even be able to deploy your DLL for you.
Signatures and manifests don't come into this.