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: 

Temporarily highlight an element (without selecting)

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
jmlovelace
2469 Views, 8 Replies

Temporarily highlight an element (without selecting)

Is there any way to temporarily highlight an element through the API, other than by selection? I'm working on a script that shows the user the elements that don't have dimensions attached to them. Something similar to the way elements turn orange on an error would be great.

8 REPLIES 8
Message 2 of 9
JimJia
in reply to: jmlovelace

Dear Jake Lovelace,

 

You may try element graphic override, see code snippet below:

OverrideGraphicSettings overrideGraphicSettings = new OverrideGraphicSettings();
Color color = new Color(255, 0, 0);
overrideGraphicSettings.SetCutFillColor(color);
overrideGraphicSettings.SetCutLineColor(color);
overrideGraphicSettings.SetCutFillPatternVisible(true);
overrideGraphicSettings.SetProjectionFillColor(color);
overrideGraphicSettings.SetProjectionLineColor(color);
overrideGraphicSettings.SetProjectionFillPatternVisible(true);
doc.ActiveView.SetElementOverrides(elemId, overrideGraphicSettings);

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
Message 3 of 9
Revitalizer
in reply to: jmlovelace

Hi,

 

just an idea.

 

You could post a failure by yourself.

http://thebuildingcoder.typepad.com/blog/2010/11/failure-api-take-two.html

I've added a line for defining the elements to be highlighted.

I didn't test this.

 

transaction.Start();
FailureMessage fm = new FailureMessage( m_idWarning );
fm.SetFailingElements(yourElements); // <-- add your elements here
m_doc.PostFailure( fm );
transaction.Commit();

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 9
stever66
in reply to: jmlovelace

I think this is similar to the last suggestion, but maybe slightly different:

 

http://thebuildingcoder.typepad.com/blog/2010/06/highlight-elements.html

 

 

Message 5 of 9
jmlovelace
in reply to: stever66

Thanks guys! @JimJia's solution of overriding graphics seems to work well. Going to write it into an iterative script and see how fast it can process

Message 6 of 9
jlpgy
in reply to: jmlovelace

Hi @jmlovelace:

But I think @JimJia 's solution requires an open Transaction.

I was thinking of wrapping this Highlight operation into a sub transaction.

For example:

  1. Open a transaction
  2. Open a sub transaction
  3. Overwrite the settings of several elements to 'highlight' them
  4. Prompt user of some infomation or ask them to do some pick operation
  5. Rollback the subtransaction
  6. Continue other operations.

I will take my time to test if it's gonna work.

🙂

If you have already tried some good solutions, do you mind discussion? Man Happy

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
Message 7 of 9
jmlovelace
in reply to: jlpgy

I believe the problem there will be the persistent open transaction. I'm pretty sure Revit does not allow more than one open transaction at a time, and therefore would not be able to make any further edits to the model until the transaction is closed.

 

I managed to get this to work using @JimJia's solution but the downside is it does require an open transaction, meaning the highlight operation is listed in the undo menu once committed.

 

 

Message 8 of 9
jlpgy
in reply to: jmlovelace

Thank you for replying:

I have tried @JimJia's solution and the code ran without exceptions.

As I post, I wrap the 'highlight' operation into a sub-transaction. I did the following steps:

  1. Start transaction
  2. Pick an element (for example, a duct, I didn't tried many other elements because my work is focused on MEP)
  3. Start subtransaction
  4. Override the graphic settings of the picked Duct element
  5. Commit subtransaction
  6. Now we are back to the open 'main' transaction. I start another pick operation to prompt the user to pick something (for example, a point on the former picked element)
  7. Do other job, like modify the documents .

Codes ran well, no exception. But, in step 6, when picking, Revit does NOT display the correct graphic settings.

Here are my codes:

 

            using (SubTransaction subt = new SubTransaction(doc))
            {
// GetActiveUIView() is my own extension method View v = doc.GetElement(Workspace.UiDoc.GetActiveUIView().ViewId) as View; OverrideGraphicSettings oldOgs = new OverrideGraphicSettings(v.GetElementOverrides(mainRefer.Id)); OverrideGraphicSettings newOgs = new OverrideGraphicSettings(oldOgs); // 临时修改求出的参照主管的显示颜色
// Temporarily change line color subt.Start(); newOgs.SetProjectionLineColor(new Color(200, 0, 0)); v.SetElementOverrides(mainRefer.Id, newOgs);
// Workspace is my own Utility static class for easy approach of common API objects, such as doc, uidoc... Workspace.Doc.Regenerate(); Workspace.UiDoc.RefreshActiveView(); subt.Commit(); // 在参照主管上拾取一个用来求出行进方向的参照点 mainPickRef = Workspace.UiDoc.Selection.PickObject( ObjectType.PointOnElement, filter, "单击拾取一个参照点以确定偏移的行进方向"); // 复位参照图元的显示设置 subt.Start(); v.SetElementOverrides(mainRefer.Id, oldOgs); subt.Commit(); }

Here is the screen shot of Revit UI:

图像 1.png

In the View settings, all ducts should be displayed with blue line.

Notice there is a dark gray line duct. I picked that Duct ahead, and invoke another Pick operation. At this moment, it should be displayed with RED line.

 

I was thinking that perhaps it's because I had not commit the main Transaction.

If I override the graphic settings in a Transaction, it works. But in my former mentioned steps, it does NOT work as I demanded.

 

To be honest, I don't want this CHANGING COLOR operation to be listed in the UNDO list Man Frustrated

 

 

 

单身狗;代码狗;健身狗;jolinpiggy@hotmail.com
Message 9 of 9
jmlovelace
in reply to: jlpgy

https://thebuildingcoder.typepad.com/blog/2017/06/ai-news-and-sub-transaction-regen.html

 

See this post regarding transaction commits. Evidently the document won't regenerate changes made on the sub-transaction until the main transaction is committed.

 

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

Post to forums  

Autodesk Customer Advisory Groups


Rail Community