Thanks for the help.
I ended up with the following code, which works, but has a problem.
When i run the command the MultiViewBLock is created with the ViewBLocks against the DisplayRepresentation.
In the StyleManager i can't see the MultiViewBlock at first. After a click on the Apply Button, the MultiViewblock appears.
And the symbol in front of de MultiViewBlock is different from the other MultiViewBlocks. There is something wrong with the code, but what?
<CommandMethod("CreateMvBlock")> _
Public Sub MyMvBlock()
Dim MyDB As Database = HostApplicationServices.WorkingDatabase
Dim MvBlockName As String = "Marcos_MVBlock"
Dim RoutingBlockName As String = "RoutingBlock"
Dim ProgrammatieBlockName As String = "ProgrammatieBlock"
Dim BekistingBlockName As String = "BekistingBlock"
Dim MvbStyleDict As New AecDb.DictionaryMultiViewBlockDefinition(MyDB)
Using trans As Transaction = MyDB.TransactionManager.StartTransaction
'Check if the MvBlock exists...
If Not MvbStyleDict.Has(MvBlockName, trans) Then
' Het MvBlock doesn't exist... create it...
Dim MyMvbDef As New MultiViewBlockDefinition
MyMvbDef.SetToStandard(MyDB)
MyMvbDef.SubSetDatabaseDefaults(MyDB)
''trans.Commit()
' Open the Database for Read...
Dim MyBT As BlockTable = MyDB.BlockTableId.GetObject(OpenMode.ForRead)
' Get the ID of the RoutingBlock
Dim AcBlockId = MyBT(RoutingBlockName)
' Set the DisplayRepresentationDef
SetDispRep(MyMvbDef, AcBlockId, "Model (KNS Routing)")
SetDispRep(MyMvbDef, AcBlockId, "Plan (KNS Routing)")
SetDispRep(MyMvbDef, AcBlockId, "General (KNS Routing)")
MvbStyleDict.AddNewRecord(MvBlockName, MyMvbDef)
trans.Commit()
MsgBox("Mvblock added")
End If
End Using
End Sub
Private Shared Sub SetDispRep(mvbDef As MultiViewBlockDefinition, blockId As ObjectId, dispRepName As String)
' Open all DisplayRepresentations for specified type and
' filter them by name
Dim dispRepMgr As New DisplayRepresentationManager()
Dim allDispReps As Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Dim ed As Autodesk.AutoCAD.EditorInput.Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim ids As Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection = DisplayRepresentationManager.GetActiveDisplayRepresentationSets(db)
Using trans
'Dim acds As DisplaySet
Dim ds As DisplaySet = New DisplaySet()
allDispReps = New Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection()
Dim id As ObjectId
' loop through the active disp sets (i.e., disp sets of active dis confid.)
For Each id In ids
Dim acds As DisplaySet = trans.GetObject(id, OpenMode.ForRead)
Dim drid As ObjectId
' look through the set of dispRep of the given disp set.
For Each drid In acds.DisplayRepresentationIds
Dim dr As DisplayRepresentation = trans.GetObject(drid, OpenMode.ForRead)
dr = trans.GetObject(drid, OpenMode.ForRead)
Dim rc As RXClass = dr.WorksWith
If (rc.Name.CompareTo("AecDbMvBlockRef") = 0) Then
If (ds.DisplayRepresentationIds.Contains(drid)) Then
Continue For
Else
'ds.DisplayRepresentationIds.Add(drid)
allDispReps.Add(drid)
End If
End If
Next drid
Next id
For Each dispRepId As ObjectId In allDispReps
Dim mvbViewDef As New MultiViewBlockViewDefinition()
With mvbViewDef
.BlockId = blockId
.SetAllViews(True)
Dim mvbDispRep As New MultiViewBlockDisplayRepresentationDefinition()
With mvbDispRep
.DisplayRepresentationId = dispRepId
mvbDispRep.ViewDefinitions.Add(mvbViewDef)
mvbDef.DisplayRepresentationDefinitions.Add(mvbDispRep)
End With
End With
Next
trans.Commit()
End Using
End Sub