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?
Solved! Go to Solution.
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?
Solved! Go to Solution.
Solved by Sean_Page. Go to Solution.
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;
}
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;
}
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?
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?
figured out, need to have separate idling events too
figured out, need to have separate idling events too
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
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
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?
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.