How to block explode CAD?

How to block explode CAD?

structure1EKNKU
Enthusiast Enthusiast
445 Views
5 Replies
Message 1 of 6

How to block explode CAD?

structure1EKNKU
Enthusiast
Enthusiast

I want to block Explode CAD.

 

I searched through the forum, found that:

Solved: Hide or block explode import instance (CADS) - Autodesk Community - Revit Products

and then followed the comment to go there:

Re: Make instance and its parameters NOT editable - Autodesk Community - Revit Products

 

But this doesn't seem to fit here. There is no such thing as PostableCommand.ExplodeCAD so I extracted all the possible command identifiers and bound them one by one to BeforeExecuted in such a way that every time I click anything in Revit it logs a name of the command to the text file. I then opened the file and ran explode CAD. Everything I saw in my log, however, was ID_BUTTON_SELECT and it's not that. When I tried to block this command by assigning an adequate BeforeExecuted and Execute functions to it, it turned out that it's triggered virtually every time I do anything (or even nothing at all) in Revit.

 

What is the ID of the exploding CAD comment or how to obtain it? The journal files aren't helpful as well.

0 Likes
446 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor

It likely wouldn't be one you can post since the link would have to be selected (contextual).

 

There is no way of exploding as far as I'm aware.

 

Worth looking at the 2014 what's new section for more information:

 

· UIApplication.PostCommand()

posts a command to Revit. Revit will invoke it when control returns from the current API context. Only certain commands can be posted using this method:

1. Commands listed in the Autodesk.Revit.UI.PostableCommand enumerated type

2. External commands created by any add-in

 

This restriction prevents posting of contextual commands (because Revit's command framework cannot directly access the accessibility of some contextual commands).

 

Note that only one command may be posted to Revit at a given time. If a second command is posted from any API application, the method throws an InvalidOperationException.

 

The command must be accessible to be executed. This is determined only at the point where Revit returns from the API context, and therefore a failure to execute the command because the command is not currently accessible will not be reported directly back to the application that posted the command.

 

To use this API, the application must obtain a RevitCommandId handle for the command. This can be done using either

· RevitAddInCommand.LookupCommandId(String)

· RevitAddInCommand.LookupPostableCommandId(PostableCommand)

 

The method

· UIApplication.CanPostCommand

identifies if the given command can ever be posted (that is, it is a member of PostableCommand or an external command). It does not identify the command can be posted at the given timeframe (that is, it will not attempt to determine if the command is currently accessible).

 

0 Likes
Message 3 of 6

structure1EKNKU
Enthusiast
Enthusiast

Er, but I wanted to block it rather than invoke it.

0 Likes
Message 4 of 6

RPTHOMAS108
Mentor
Mentor

I think you have a similar problem regardless.

 

If you can't get a valid command id via string (since it likely isn't postable so not part of that enum) then you will not be able to bind to it.

 

You get similar issues with the commands that come off of the context menu in project browser e.g. the push button version of delete is ok but right click delete wasn't. Generally you are going to have issues with the buttons that appear after another action such as picking links.

0 Likes
Message 5 of 6

structure1EKNKU
Enthusiast
Enthusiast

I got it, although I am not happy with the conclusion 😉

 

Are you familiar with any workaround?

0 Likes
Message 6 of 6

RPTHOMAS108
Mentor
Mentor

Yes via failures processing event considering culture specific transaction name:

230815.PNG

Here is the code:

 

Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI

Public Class exClass1
    Implements IExternalApplication

    Public Shared FDefId As New FailureDefinitionId(New Guid("789DA294-36A0-4C1E-8A76-D998F2F257BC"))
    Public Sub Fpro(s As Object, e As Events.FailuresProcessingEventArgs)
        Dim FA = e.GetFailuresAccessor
        Dim NM As String = FA.GetTransactionName
        Select Case NM.ToLower
            Case "Explode Import Instance".ToLower
                'For this type of transaction there should be no 'DocumentCorruption'
                'Failure if there is then I don't need to post this if there isn't then I do.
                'Failure processing is recursive so only post once by checking.
                If FA.GetFailureMessages(FailureSeverity.DocumentCorruption).Count = 0 Then
                    FA.PostFailure(New FailureMessage(FDefId))
                End If
            Case Else
        End Select
    End Sub

    Public Function OnStartup(ByVal application As Autodesk.Revit.UI.UIControlledApplication) As Autodesk.Revit.UI.Result _
        Implements Autodesk.Revit.UI.IExternalApplication.OnStartup

        Dim FF As FailureDefinition = FailureDefinition.CreateFailureDefinition(FDefId, FailureSeverity.DocumentCorruption,
                          "Explode block warning. I say no that is a bad idea, I'm the authority on block exploding! 
                          Come and pester me to remove this message...")

        AddHandler application.ControlledApplication.FailuresProcessing, AddressOf Fpro

        Return Result.Succeeded
    End Function

    Public Function OnShutdown(application As UIControlledApplication) As Result Implements IExternalApplication.OnShutdown
        'I don't know this matters but I like to do it anyway.
        RemoveHandler application.ControlledApplication.FailuresProcessing, AddressOf Fpro

        Return Result.Succeeded
    End Function
End Class

 

There is a technician that doesn't have AutoCad but they have a dwg with 1000 layers. They import it to Revit on drafting view then they explode it and isolate the layers they care about to copy to another view. To avoid the mess they've done this in a separate model so they can just copy the few lines they are interested in or plot a fresh dwg from Revit and import that elsewhere.

 

But alas no more...someone has stuck a road block in the middle of their workflow.

 

Therefore perhaps you can put some more intelligence into the code above by making is document specific etc.

0 Likes