Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linear Dimension Style Does Not Duplicate In 2018

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
683 Views, 2 Replies

Linear Dimension Style Does Not Duplicate In 2018

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.

2 REPLIES 2
Message 2 of 3
matthew_taylor
in reply to: Anonymous

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?
Message 3 of 3
Anonymous
in reply to: matthew_taylor

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.

Post to forums  

Forma Design Contest


Rail Community