"Type Properties" with preview on, triggers add new views in Revit

"Type Properties" with preview on, triggers add new views in Revit

bmz
Participant Participant
824 Views
4 Replies
Message 1 of 5

"Type Properties" with preview on, triggers add new views in Revit

bmz
Participant
Participant

Hi

 

I have a trigger to track when user adds a new view, when the view is added it trigger a naming tool to help user naming the views in a specifc way.

 

My problem is that Revit also creates some kind of internal views when “Type Properties” dialog is opened with Preview shown.

 

On the attached picture of "Type Properties" dialog, all the views are created temporary for showing the family.

When Revit creates those views it also triggers the add new view code.

How do I distinguish between views made for this “Type Properties” dialog and views created by users in Revit?

 

The code line for adding the trigger:

UpdaterRegistry.AddTrigger(updaterClass.GetUpdaterId(), New ElementClassFilter(GetType(View)), Element.GetChangeTypeElementAddition)

 

(This problem is currently in Revit 2018.)

0 Likes
825 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

Dear Bettina,

 

Thank you for your query and nice to hear from you again after a long break.

 

There may be several approaches to address what you describe.

 

It depends on your entire context.

 

For instance, if you can guarantee that the views you are interested in are never named the same as those generated temporarily be Revit, you can simply ignore them by name.

 

Alternatively, if you go the other way around, if you can identify the views you are interested in by name somehow, you can ignore all the others.

 

It would obviously be better to use something language independent rather than the name.

 

There may be other properties that you can use as well.

 

Another approach might be based on the context.

 

Again, you could suppress your updater reaction when the type properties command is launched, or while it is active (X).

 

Alternatively, you could suppress your updater reaction always, except when you really need it. When do you need it? What is it used for?

 

Returning to the suggestion X, you might be able to use the .NET or Windows API to determine that the Type Properties dialogue is being displayed and use that notification to turn off your updater until after the dialogue is closed.

 

The WH_SHELL hook should give you a notification when any window/dialog is going to be activated. You have to find some method of identifying the right dialog, e.g., the window caption "Type Properties" and maybe additional criteria.

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5

bmz
Participant
Participant

Hi Jeremy

 

I see my problem description was not detailed enough.

 

I already listen to PreviewExecute and itemExecuted events, and exclude my Naming function for certain commandId’s if a view is created between those two events.

 

Example if the user press “Type Properties” button in the ribbon the PreviewExecute shows button id "Dialog_Revit_FamilyBar:Control_Revit_PropertyPanelTypePropBtn" is pressed, and I don’t show any naming tool dialog for any of the views created from “Type Properties”.

 

But “Type Properties” can be opened from the “Project Browser” by double clicking on a family type or right clicking on a family type and chose “Type Properties…” in the right click menu. In this case no previewExecute event is triggered.

 

It could be very nice if actions in “Project Browser” also triggers PreviewExecute events like the ribbon buttons.

 

About win api: In this case I don’t like the solution of having win api listening in on dialogs, because it will be when a rvt document is open it should listen. The setting, if it should listen for Naming, is set per rvt document.

 

I found a solution

I listen to dialog showing, and if dialog with id "IDD_SYMBOL_ATTRIB" is showing I know its “Type Properties”, and I then listen to idle event to see when user close dialog, when idle event is triggered the user has closed dialog, then I know in this time period, while this dialog is open, i should not show the user any Naming function to rename the views.

 

Thanks for making me look at my code one more time.

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk

Dear Bettina,

 

Thank you for your update and appreciation, and congratulation on finding such a simple and effective solution without taking recourse to the Windows API.

 

Would you like to share a couple of short code snippets from the main relevant parts of the solution?

 

I am sure that others will be interested and can make use of this approach as well.

 

Thank you!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 5

bmz
Participant
Participant

Hi Jeremy

 

Here is a tiny simplified snippet of code, explaining my workaround for the problem.

 

 

Public Class RevitDialogListner

 

    Private WithEvents uiApp As UIApplication

    Private mUiIdleApp As UIApplication

 

    Public Sub AddDialogListner(app As Application)

        Try

            uiApp = New UIApplication(app)

            _IllegalViewCreationCommandInProgress = False

        Catch ex As Exception

        End Try

    End Sub

 

    Private Sub uiApp_DialogBoxShowing(sender As Object, e As DialogBoxShowingEventArgs) Handles uiApp.DialogBoxShowing

        If e.DialogId = "IDD_SYMBOL_ATTRIB" Then 'Dialog “Type Properties” are showing

            Try

                _IllegalViewCreationCommandInProgress = True

                AddHandler mUiIdleApp.Idling, AddressOf mUiIdleApp_Idling

            Catch ex As Exception

            End Try

        End If

    End Sub

 

    Private Sub mUiIdleApp_Idling(sender As Object, e As Autodesk.Revit.UI.Events.IdlingEventArgs)

        'When this is triggered “Type Properties” are closed

        Try

            RemoveHandler mUiIdleApp.Idling, AddressOf mUiIdleApp_Idling

        Catch ex As Exception

        End Try

        _IllegalViewCreationCommandInProgress = False

    End Sub

End Class

 

I use the variable _IllegalViewCreationCommandInProgress  to check if its a view the Naming tool should rename.

 

The Naming tool renames new views when the below trigger is fired.

 

UpdaterRegistry.AddTrigger(updaterClass.GetUpdaterId(), New ElementClassFilter(GetType(View)), Element.GetChangeTypeElementAddition)

 

This trigger catches newly added views in Revit.

 

(Of cores there is a lot of situation when the trigger is not Naming views, but the list is so long it will take long time to explain.)