When duplicating a linear dimension style in Revit 2018, the name of the duplicated type is not (eg) "MyType" but some obscure string "SecretInternalLinAngDimStyle...". This was working fine in 2017 and previous. Please find the code to reproduce this behaviour in the attached file.
Thanks.
Solved! Go to Solution.
Solved by matthew_taylor. Go to Solution.
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
Hi Matt,
Fantastic! I guess one of these 'hidden styles' got introduced in 2018 as it was working before then.
Best regards
Paul
Can't find what you're looking for? Ask the community or share your knowledge.