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: 

postable command usage

44 REPLIES 44
SOLVED
Reply
Message 1 of 45
Ning_Zhou
3679 Views, 44 Replies

postable command usage

Ning_Zhou
Advocate
Advocate

seems postable command usage is quite limited, for instance

1) can only send warning message instead of disable command?

2) OOTB duplicate view will name that duplicated view w/ suffix Copy 1, is it possible to name it differently?

0 Likes

postable command usage

seems postable command usage is quite limited, for instance

1) can only send warning message instead of disable command?

2) OOTB duplicate view will name that duplicated view w/ suffix Copy 1, is it possible to name it differently?

44 REPLIES 44
Message 41 of 45
Sean_Page
in reply to: Ning_Zhou

Sean_Page
Collaborator
Collaborator

You need to factor and add some "IF" statements in here so you can control what it is doing for different Commands.

 

Here is an example of how I have several setup in one of my Apps. You will need to adjust based on your needs and Events, but the idea here is that you need to control the flow based on which Command the user posts.

private Result AddCommandBindings(UIControlledApplication application, string name)
        {
            RevitCommandId rCommandId = RevitCommandId.LookupCommandId(name);
            if (rCommandId.CanHaveBinding)
            {
                try
                {
                    if (name == "ID_INPLACE_COMPONENT")
                    {
                        application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.DisableCommand);
                    }
                    else if (name == "ID_FILE_IMPORT")
                    {
                        application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.DisableCommand);
                    }
                    else if (name == "ID_WORKSETS_RELOAD_LATEST")
                    {
                        application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.ReloadLatestUpdaters);
                    }
                    //else if (name == "ID_EDIT_ELEVATION_SKETCH")
                    //{
                    //    application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.EditProfileUpdaters);
                    //}
                }
                catch
                {
                    MessageBox.Show("Command " + name + " is already bound.");
                }
            }
            return Result.Succeeded;
        }

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect

You need to factor and add some "IF" statements in here so you can control what it is doing for different Commands.

 

Here is an example of how I have several setup in one of my Apps. You will need to adjust based on your needs and Events, but the idea here is that you need to control the flow based on which Command the user posts.

private Result AddCommandBindings(UIControlledApplication application, string name)
        {
            RevitCommandId rCommandId = RevitCommandId.LookupCommandId(name);
            if (rCommandId.CanHaveBinding)
            {
                try
                {
                    if (name == "ID_INPLACE_COMPONENT")
                    {
                        application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.DisableCommand);
                    }
                    else if (name == "ID_FILE_IMPORT")
                    {
                        application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.DisableCommand);
                    }
                    else if (name == "ID_WORKSETS_RELOAD_LATEST")
                    {
                        application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.ReloadLatestUpdaters);
                    }
                    //else if (name == "ID_EDIT_ELEVATION_SKETCH")
                    //{
                    //    application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.EditProfileUpdaters);
                    //}
                }
                catch
                {
                    MessageBox.Show("Command " + name + " is already bound.");
                }
            }
            return Result.Succeeded;
        }

 

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 42 of 45
Ning_Zhou
in reply to: Sean_Page

Ning_Zhou
Advocate
Advocate

thanks spage, that's what i thought about before but don't know where to add.

i added switch in AddCommandBind, but still no luck, is it because i added multiple AddCommandBind in idling events? well, i added the followings in both startup and idling:

AddCommandBinding(a, PostableCommand.ImportCAD);
AddCommandBinding(a, PostableCommand.DuplicateView);
AddCommandBinding(a, PostableCommand.ReferencePlane);

i suspect these should also be condition based, at least in idling, isn't it?

0 Likes

thanks spage, that's what i thought about before but don't know where to add.

i added switch in AddCommandBind, but still no luck, is it because i added multiple AddCommandBind in idling events? well, i added the followings in both startup and idling:

AddCommandBinding(a, PostableCommand.ImportCAD);
AddCommandBinding(a, PostableCommand.DuplicateView);
AddCommandBinding(a, PostableCommand.ReferencePlane);

i suspect these should also be condition based, at least in idling, isn't it?

Message 43 of 45
Ning_Zhou
in reply to: Ning_Zhou

Ning_Zhou
Advocate
Advocate

figured out, need to have separate idling events too

0 Likes

figured out, need to have separate idling events too

Message 44 of 45
Ning_Zhou
in reply to: Ning_Zhou

Ning_Zhou
Advocate
Advocate

Merry Christmas and Happy New Year to all!

 

revisit this old thread, recently i noticed a small glitch, i tried to use PostableCommand.DuplicateWithDetailing, works great just like PostableCommand.DuplicateView, except when i do it using right mouse click on the view (say "myView") which is not active, i cannot catch the default duplicated view which should be "myView Copy 1", only original view which is "myView".

PostableCommand.DuplicateView doesn't have this issue, those 2 commands should behavior similar, any clue?

 

below my snippet and comment FYI

private void OnViewActivated(object sender, ViewActivatedEventArgs args)
{
UIApplication uiApp = sender as UIApplication;
Document doc = args.Document;
View v = args.CurrentActiveView;
string n = v.Name;
// n = "myView Copy 1" for DuplicateView
// n = "myView" for DuplicateWithDetailing
// evething is OK if original view "myView" is activated beforehand

0 Likes

Merry Christmas and Happy New Year to all!

 

revisit this old thread, recently i noticed a small glitch, i tried to use PostableCommand.DuplicateWithDetailing, works great just like PostableCommand.DuplicateView, except when i do it using right mouse click on the view (say "myView") which is not active, i cannot catch the default duplicated view which should be "myView Copy 1", only original view which is "myView".

PostableCommand.DuplicateView doesn't have this issue, those 2 commands should behavior similar, any clue?

 

below my snippet and comment FYI

private void OnViewActivated(object sender, ViewActivatedEventArgs args)
{
UIApplication uiApp = sender as UIApplication;
Document doc = args.Document;
View v = args.CurrentActiveView;
string n = v.Name;
// n = "myView Copy 1" for DuplicateView
// n = "myView" for DuplicateWithDetailing
// evething is OK if original view "myView" is activated beforehand

Message 45 of 45
Ning_Zhou
in reply to: Ning_Zhou

Ning_Zhou
Advocate
Advocate

managed to make it work via workaround, throw an exception in OnViewActivated event when default "myView Copy 1" is not created, don't know why it happens, maybe there's better way?

0 Likes

managed to make it work via workaround, throw an exception in OnViewActivated event when default "myView Copy 1" is not created, don't know why it happens, maybe there's better way?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report