Hi Paul,
It's something to do with DimensionTypes that aren't user visible ones. You're trying to duplicate one of those, not a 'user visible' type.
There are probably other ways to check which ones they are, but I noticed that the non-user visible ones have no parameters in their ParameterMap. I'll leave it up to you to find a more dependable check.
Anyways, here's some working code:
Imports System.Linq
Imports Autodesk.Revit
Imports Autodesk.Revit.Attributes
<Transaction(TransactionMode.Manual)> _
<Regeneration(RegenerationOption.Manual)> _
<Journaling(JournalingMode.NoCommandData)> _
Public Class InternalDuplicateDimStyle
Implements UI.IExternalCommand
#Region "IExternalCommand Members Implementation"
Public Function Execute(ByVal commandData As UI.ExternalCommandData, ByRef message As String, ByVal elements As DB.ElementSet) As UI.Result Implements UI.IExternalCommand.Execute
Dim app As ApplicationServices.Application = commandData.Application.Application
Dim doc As DB.Document = commandData.Application.ActiveUIDocument.Document
Dim docUi As UI.UIDocument = commandData.Application.ActiveUIDocument
CreateDimensionStyle(doc)
Return UI.Result.Succeeded
End Function
Public Shared Function CreateDimensionStyle(ByVal doc As DB.Document) As DB.DimensionType
Dim dimensionType As DB.DimensionType = New DB.FilteredElementCollector(doc) _
.OfClass(GetType(DB.DimensionType)) _
.Cast(Of DB.DimensionType) _
.Where(Function(dt) dt.StyleType = DB.DimensionStyleType.Linear) _
.Where(Function(dt) dt.ParametersMap IsNot Nothing AndAlso dt.ParametersMap.Size > 0) _
.FirstOrDefault()
Using tx As DB.Transaction = New DB.Transaction(doc, "Create new dimension style")
tx.Start()
Dim dimensionType2 As DB.DimensionType = dimensionType.Duplicate("NewName1")
doc.Regenerate()
dimensionType2.Name = "NewName1"
tx.Commit()
MsgBox(dimensionType2.Name)
Return dimensionType2
End Using
End Function
#End Region
End Class
Cheers,
-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?