Purge unused

Purge unused

Anonymous
Not applicable
1,629 Views
9 Replies
Message 1 of 10

Purge unused

Anonymous
Not applicable

Hola,

How I purge un used more than once is no easy? I try from my command and only succussefful once time. i want 3 times this. 

many thanxs muchachos!

0 Likes
1,630 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

How I call this twice from the external command, i tried more than once and it looks like it works in revit, yet nothing happens!

 

/// <summary>
/// Post a sequence of keystrokes.
/// </summary>
public static void Keys(string command)
{

IntPtr revitHandle = System.Diagnostics.Process
.GetCurrentProcess().MainWindowHandle;


foreach (char letter in command)
{
OneKey(revitHandle, letter);
}

}

0 Likes
Message 3 of 10

RPTHOMAS108
Mentor
Mentor

I think sending keys is not a good solution, not sure mine is better but it works:

 

1) Attach handler for dialogue showing event

2) Post the purge command

3) Handler then responds with OK to the purge dialogue and increments a shared integer count. If integer count is less than desired number of iterations it repeats step 2. If integer count is equal to desired number of iterations then it resets integer count, removes handler and exits loop.

 

I’ve written a command for processing models for export on this basis however even five purges in such a sequence often fails to remove all unused. Would be nice if the API had a direct purge call that would return information regarding what is left to purge (or even a Boolean return value indicating if 0 items remain). Processing models to remove clutter before creating IFC’s etc. is a ripe task for automation.

 

Similarly, you can leverage the built-in spell checker to check spelling of Revit parameters:

 

  1. Within the original external command context copy all text parameter values of a selected element or elements into new text elements in a drafting view. Create object in memory to store a link between the ElementID of each text element, the ElementID of the element containing the parameter and the thing that identifies the parameter. You have to check if it is BIP or Shared etc. to know what key you are storing for this (shared parameter GUID, BIP integer value etc). Would not advise using parameter name for a key but you may have to fall back on this if it is neither shared nor built in. If you do have to fall back on name then use the current text value of the parameter as an additional key.
  2. Make view with text elements current and add dialogue showing event handler
  3. Post spell check command
  4. Respond to dialogue event to remove handler and post new external event (to obtain valid context after spell check completion).
  5. Get active context from external event hander. You can then open a transaction to transfer values from the corrected text elements in the view back into the parameters (by mapping according to the stored relationship). You don’t even need to know if a spelling was accepted or not since that will be evident in the updated text elements, you can just transfer it as is.
  6. In same context delete the drafting view containing the text elements.

I’ve got this working and I am sure it will prevent the existence of many titled Stellwork G.A.s. Although I wonder why Revit does not have built-in spell-checking for parameters with text storage type?

Message 4 of 10

Anonymous
Not applicable
Hi,
Did you use the external event, can I call this from my on load method.
Cheers
Ben
0 Likes
Message 5 of 10

Anonymous
Not applicable
So that it happens on the load event. That is. Can I do other external event operations after this call? Or does it have to happen at the end?
0 Likes
Message 6 of 10

Anonymous
Not applicable

Hola,

What is de dialog showing event registering on, a purges unusedidad dialog?

Can you provide the example for this code block por favor?

Many thanx!

0 Likes
Message 7 of 10

RPTHOMAS108
Mentor
Mentor

I believe that when you are posting a command it typically has to be the last thing you do at the end of the IExternalCommand context. I outlined how you can respond to dialogues to post another built-in command which forms a loop after the context is initially finished. I believe this approach only works for posting built-in commands. You therefore have to design in a way that purging is the last thing you do, also it is critical to test the loop with an exit condition it will definitely meet.

 

My understanding of external events is that once they are registered at start-up they can be called at any time. Once you’ve called it you then wait for Revit to complete whatever it is doing to give you a valid context.

 

I should also say that responding to dialogues is not typically a good idea, take the following example:

 

Developer ‘A’ writes a routine for batch printing but as it prints the message comes up about the 3D shading using raster settings. Therefore, they add an event handler to handle dialogues showing during the batch printing. Meanwhile Developer ‘B’ is asking to update something before it is printed (with default equals cancel print). Since Developer ‘A’ dismissed the dialogue generated by Developer ‘B’ the print gets cancelled but it happens transparently. These things are hard to diagnose because it relates to the interaction of addins that may not be present when you are testing yours. So, if you add handler responding to dialogues you should remove it as soon as possible. You should also have a very good idea of what dialogues you are expecting to encounter. It is really the thing of last resort.

0 Likes
Message 8 of 10

Anonymous
Not applicable

How can I implement this, I think this is much improved way as only wrong happen using my command with developer A, B clash of dialog events.

 

http://thebuildingcoder.typepad.com/blog/2011/03/application-versus-command-event.html

 

Building coder tell someone subscribe same way

0 Likes
Message 9 of 10

Anonymous
Not applicable

hiya,

This is new to me...however i have made it work with send keys, id like to use postcommand

how can i get the return or result from the postcommand purgeunused dialog, that the dialog has completed ok? 

 

0 Likes
Message 10 of 10

matthew_taylor
Advisor
Advisor

I have found an existing simple solution for this (for Revit 2017+). See my code repository:

https://gitlab.com/MattTaylor/RevitPurgeUnused


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?
0 Likes