Maybe it's Idling, it's usually not safe to run long processes in there.
You could use ExternalEvent and verify if that works.
Some sample code like this:
Maybe it's Idling, it's usually not safe to run long processes in there.
You could use ExternalEvent and verify if that works.
Some sample code like this:
@saugat_karki wrote:Jeremy,
I still cannot find the method where I can specify voltage and phase. Could you please direct me to where that is?
There is no method to specify the voltage and phase.
The only way would be selection the instance family, find the instance parameter for the voltage and phase, change the values and execute the method to create the ElectricalSystem.
When using the OpenDocumentFile() method to open a document in memory, the ExportImage() method ignores hidden elements. Specifically, methods such as HideCategoriesTemporary(), HideElements(), and HideElementsTemporary() do not have any effect on the visibility of elements during the image export process
Steps to Reproduce:
Open a document in memory using the OpenDocumentFile() method.
Use any of the hiding methods (HideCategoriesTemporary(), HideElements(), HideElementsTemporary()) to hide specific elements or categories.
Call the ExportImage() method to export an image of a view.
Workaround:
Interestingly, if the view.Outline property is accessed before calling ExportImage(), the hidden elements are correctly excluded from the exported image. The fact that accessing view.Outline resolves the issue suggests that there may be an internal state or initialization step that is not being triggered correctly when ExportImage() is called directly. view.get_BoundingBox(null); also works in the same way
Impact:
This behavior disrupts the expected CodeFlow, as the document visibility is changed unintentionally. This issue is particularly critical for one application with over 100,000 users, as it can lead to inconsistent user experiences and potential workflow interruptions.
Affected Revit Versions:
2022-2025, Preview
Hello @scgq425 !
Sorry for the late reply and thank you for your suggesion.
When I use BoundingBoxIsInsideFilter(), it doesn't work for me that I wanted.
But thank you for your helps!
Hello @jeremy_tammik !
Thank you for your help.
It was difficult to solve my problem with what you sent me.
I will continue to look for other ways.
But thank you for your helps!
Perfect thank you so much. I needed to seperate it out of OnStartup, however its essentally the same:
OnStartup is useful to register event handlers and set up add-ins and stuff, but it is not the optimal time and place to start executing code. ApplicationInitialized is a later and probably more suitable choice:
Subscribe to this event to get notified after the Revit application has been initialized.
Hi @jmcouffin,
Thank you for reporting this. I will raise the matter with the Revit Engineering team and ensure it is resolved.
Oh dear, sorry that it remains tricky. I asked Gemini for you, as described in my blog, and it replies:
Let's dive into efficiently retrieving visible elements in the active Revit view. You're right, VisibleInViewFilter
and WhereElementIsViewIndependent
alone aren't sufficient when crop regions or other visibility overrides are in play. They indicate potential visibility, not actual, rendered visibility within the current view's context. We need a more robust approach.
Here's a breakdown of the problem and a practical solution, combining best practices and leveraging the Revit API:
The Challenge:
The Revit API doesn't offer a single, direct method to get precisely what's visually rendered in the active view, especially considering crop regions, temporary view templates, and element overrides. VisibleInViewFilter
only checks if an element could be visible in some view, not the current one with its specific settings. WhereElementIsViewIndependent
filters elements that are view-specific, but it doesn't filter based on visibility.
The Solution: Combining Filters and Bounding Box Intersections
The most reliable approach involves a combination of filtering and geometric checks. We'll use the view's crop box (or its equivalent if it's not rectangular) to define the visible region and then check if element bounding boxes intersect with this region. This approach is accurate and handles crop boxes effectively.
using Autodesk.Revit.DB;using Autodesk.Revit.UI;using System.Collections.Generic;using System.Linq;publicclassVisibleElementsInView
{publicstatic List<Element> GetVisibleElements(Document doc, View activeView)
{
List<Element> visibleElements = new List<Element>();// 1. Get the View's Crop Box (or its equivalent for non-rectangular crops)// For simplicity, assuming a rectangular crop box here. Adapt as needed for more complex shapes.
BoundingBoxXYZ cropBox = activeView.CropBox;
XYZ minPt = cropBox.Min;
XYZ maxPt = cropBox.Max;// Create an outline for the cropbox.
Outline cropOutline = new Outline(minPt, maxPt);// 2. Collect all elements in the view (filtering can improve performance)// You can add more specific filters here if you know element categories you are interested in.
FilteredElementCollector collector = new FilteredElementCollector(doc, activeView.Id);// Example: Filter for model elements only:
collector.OfClass(typeof(FamilyInstance)); // Or other relevant classes// 3. Iterate and check for intersectionforeach (Element element in collector)
{// Get the element's bounding box (handles various element geometries)
BoundingBoxXYZ elementBox = element.get_BoundingBox(activeView);if (elementBox != null) // Handle cases where bounding box is null
{// Check for intersection with the crop boxif (cropOutline.Intersects(new Outline(elementBox.Min, elementBox.Max)))
{
visibleElements.Add(element);
}
}
}
return visibleElements;
}// Example usage (in an external command or application):publicvoidExecute(ExternalCommandData commandData, refstring message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
View activeView = doc.ActiveView;
List<Element> visibleElements = GetVisibleElements(doc, activeView);
TaskDialog.TaskDialog.Show("Visible Elements", $"Found {visibleElements.Count} visible elements.");// Do something with the visibleElements list...
}
}
Explanation and Key Improvements:
Crop Box Retrieval: We retrieve the CropBox
of the active view. For non-rectangular crop regions, you'll need to get the CurveLoop
representing the crop boundary and use more advanced geometric intersection methods.
Efficient Element Collection: The FilteredElementCollector
with the activeView.Id
is crucial. This limits the initial collection to elements in the view, significantly improving performance compared to collecting all elements in the model. You can further refine this collector with additional filters (e.g., OfClass
, OfCategory
) to target specific element types for even better performance.
Bounding Box Intersection: The core logic uses Outline.Intersects
. This checks if the element's bounding box intersects with the view's crop box. This is a robust way to determine visibility within the cropped region.
Null Bounding Box Handling: The code now includes a check for elementBox != null
. Some elements (like annotation elements far from the view) might have null bounding boxes. Handling this prevents exceptions.
Example Usage: The provided Execute
method demonstrates how to use the GetVisibleElements
function within a Revit command.
Further Considerations:
Performance: For extremely large models, you might consider spatial partitioning techniques (e.g., using the SpatialElement
classes) to further optimize the intersection checks.
Non-Rectangular Crops: For complex crop shapes, you'll need to work with the CurveLoop
of the crop region and implement more sophisticated geometric intersection tests (e.g., using the XYZ.DistanceTo
method or other geometric utilities).
Temporary View Modes: Be aware that temporary view modes (like Reveal Hidden Elements) can affect visibility. You might need to adjust your logic based on the current view's temporary view mode if your add-in needs to handle these cases.
This approach provides a practical and reliable way to get truly visible elements in the active Revit view, addressing the limitations of simpler visibility filters. Remember to adapt the crop region handling for non-rectangular shapes if needed. Let me know if you have any other questions!
I hope that this explanation can prove useful in your further research. Please let us know how it goes. Thank you and good luck!
Automating drawing creation in Revit is definitely possible and a powerful way to boost productivity. It involves a combination of techniques, from simple scripting to more advanced add-in development. Let's explore the options and I'll point you to resources that demonstrate these techniques.
Methods for Drawing Sheet Automation in Revit:
Revit API (Add-in Development): This is the most flexible and powerful approach. Using the Revit API (C# or Python), you can programmatically create views, place them on sheets, set parameters, and even control annotations. This is ideal for complex, customized workflows.
Dynamo: Dynamo is a visual programming tool that integrates with Revit. It allows you to create scripts (graphs) to automate tasks, including drawing creation. Dynamo is great for less complex automations where you don't want to dive into full add-in development.
Built-in Revit Features (Less Automated): Revit itself has some features that assist in drawing creation, like view templates and the ability to duplicate views. While not fully automated, these can streamline parts of the process.
Example Scenario (Revit API - C#):
Let's outline a simplified C# example using the Revit API to create sheets and place views on them. This is a basic illustration, but it can be extended for more complex scenarios.
using Autodesk.Revit.DB;using Autodesk.Revit.UI;using System.Collections.Generic;using System.Linq;publicclassCreateDrawings
{publicvoidExecute(ExternalCommandData commandData, refstring message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;// 1. Get or create a Title Block family
FamilySymbol titleBlock = GetTitleBlock(doc, "YourTitleBlockName"); // Replace with your title block name// 2. Define view information (e.g., view names, view types, levels)
List<ViewInfo> viewInfos = GetViewInformation(); // Function to define your views// 3. Create sheets and place viewsusing (Transaction t = new Transaction(doc, "Create Drawings"))
{
t.Start();foreach (ViewInfo viewInfo in viewInfos)
{// Create a new sheet
ViewSheet newSheet = ViewSheet.Create(doc, titleBlock.Id);
newSheet.Name = viewInfo.SheetName;
newSheet.SheetNumber = viewInfo.SheetNumber;// Get the view to place (assuming it exists)
View viewToPlace = doc.GetElement(viewInfo.ViewId) as View;if (viewToPlace != null)
{// Place the view on the sheet (adjust location as needed)
XYZ viewLocation = new XYZ(2, 2, 0); // Example location
Viewport.Create(doc, newSheet.Id, viewToPlace.Id, viewLocation);
}
}
t.Commit();
}
}
// Helper functions (implementation omitted for brevity - you'll need to define these)private FamilySymbol GetTitleBlock(Document doc, string titleBlockName) { /* ... */ }private List<ViewInfo> GetViewInformation() { /* ... */ }// Inner class to hold view informationpublicclassViewInfo
{publicstring SheetName { get; set; }publicstring SheetNumber { get; set; }public ElementId ViewId { get; set; }
}
}
Key Concepts and Improvements:
ViewInfo
class (or a similar structure) is essential to organize the data for each sheet and the views to be placed. You'll need to populate this with your specific view names, sheet numbers, and view IDs.Viewport.Create
method places the view on the sheet at a specified location.Dynamo Approach:
Dynamo offers a more visual way to achieve similar automation. You would use nodes to:
Dynamo is generally easier to learn for basic automation tasks, while the Revit API provides more flexibility for complex scenarios.
Video Demonstration and Resources:
Searching YouTube for "Revit drawing automation" or "Revit API sheet creation" will yield numerous tutorials and demonstrations. Look for videos covering both the Revit API and Dynamo approaches.
Recommendation:
I hope this helps you get started with drawing sheet automation in Revit!
Let us know if you have more questions.
Please note that this discussion forum is dedicated to programming desktop Revit using the desktop Revit API.
However, in spite of the wrong place for this discussion, I quickly posted your query to Gemini for you, and it replies:
Let's troubleshoot why Revit 2023 isn't recognizing your NVIDIA 940, even though you have DirectX 12. This is a common issue, and we'll go through the likely causes and solutions step by step.
1. Driver Issues (Most Likely Culprit):
Clean Install of Drivers: A corrupted or outdated driver is the most frequent cause. Don't just update; perform a clean install:
Driver Compatibility: Although you have DirectX 12, Revit might be looking for specific driver features related to DirectX 11. Ensure you're using a driver that's compatible with both DirectX 11 and 12. The latest drivers usually are, but sometimes older ones can cause conflicts.
2. Revit Hardware Acceleration Settings:
Check Revit Options:
Advanced Graphics Settings (If Available):Some Revit versions have an "Advanced Graphics" button.1 If you see it, click it and ensure your NVIDIA card is selected there as well.
3. Windows Graphics Settings:
C:\Program Files\Autodesk\Revit 2023\Revit.exe
).4. BIOS Settings (Less Common):
5. DirectX Installation (Unlikely, but Check):
6. Revit Installation (Last Resort):
Troubleshooting Steps:
Regarding DirectX 11 Flag:
The red flag on DirectX 11 in Revit's hardware configuration might not be a major concern initially. Revit often uses DirectX 11 for certain tasks even if your system supports DirectX 12. The key is to get Revit to recognize your NVIDIA card. Once that's done, the DirectX 11 flag might disappear, or it might remain, but the hardware acceleration should still work correctly.
After each step, restart Revit to see if the changes take effect. If you still have problems, please provide more details about your system (Windows version, exact NVIDIA driver version you're trying, etc.) and raise your issue in one of the more appropriate non-API, product related forums:
Thank you!
Dear Roman,
Thank you for your report, clear description and sample material.
Sorry to hear about this.
I logged the issue REVIT-232472 [OpenDocumentFile + ExportImage ignores hidden elements] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.
You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.
If it is especially important and urgent for you, you might also want to mention this ticket number in the preview discussion forum, where you have more access to chat directly with the development team.
Best regards,
Jeremy
Dear Roman,
Thank you for your report, clear description and sample material. Sorry to hear about this.
I logged the issue REVIT-232473 [ExportImage unintentionally displays BIM to user violating official docs] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.
You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.
If it is especially important and urgent for you, you might also want to mention this ticket number in the preview discussion forum, where you have access to chat directly with the development team.
Best regards,
Jeremy
Hi All,
I am implementing a spell check feature in my Revit add-in using WPF. The issue I am facing is that when I click "Ignore All", the spell check window still opens for each word instead of stopping immediately.
External Command
WPF Spell Check Window Code (Behind Code)
Expected Behavior:
Issue:
Even after setting _stopProcessing = true, the spell check window still opens for each remaining word instead of stopping immediately.
Question:
How can I ensure that clicking "Ignore All" stops the process immediately and prevents additional spell check windows from opening?
Would love to hear any suggestions or best practices! Thanks.
Thanks. 🙂
What about the GetFaceMidpoint(face) method, do you have its code or is it something from Revit API?
Oh dear. That was part of the first answer, and I did not keep it. I'll check for you later, or you can ask Gemini yourself.
I asked Gemini for you, and it replies:
You've hit a classic WPF and threading issue combined with the modal dialog behavior. The ShowDialog()
method blocks the execution of your loop, and even though you set the stopProcessing
flag in the IgnoreAllButton_Click
event, the loop only checks this flag after the dialog is closed. This is why the next window still opens. Here's a breakdown of the problem and a robust solution:
Problem:
ShowDialog()
Blocking:spellCheckWindow.ShowDialog()
is a modal call. Your OpenSpellCheckWindowForWord
method is stuck waiting for the dialog to close before it can check the stopProcessing
flag.
Event Handling on UI Thread: WPF events (like IgnoreAllButton_Click
) are typically handled on the UI thread. While the flag is set on the UI thread, the blocking ShowDialog()
call prevents the loop on the same thread from checking it.
Solution:
The core idea is to use asynchronous programming to avoid blocking the UI thread and allow the loop to respond to the stopProcessing
flag change. We'll leverage Task
and async/await
for this:
using System.Threading.Tasks;// In your External Commandpublicbool stopProcessing = false;publicasync Task OpenSpellCheckWindowForWord(List<string> incorrectWords)
{// Make a copy to avoid modifying the original list during iteration
List<string> wordsToProcess = new List<string>(incorrectWords);foreach (string word in wordsToProcess)
{if (stopProcessing)
{break; // Exit the loop if stopProcessing is true
}
SpellCheckWindow spellCheckWindow = new SpellCheckWindow(word, ref stopProcessing); // Pass the word directly// Show the dialog asynchronously and get the resultbool? dialogResult = await Task.Run(() => spellCheckWindow.ShowDialog());// Check the result and the stopProcessing flag AFTER the dialog closesif (stopProcessing || dialogResult == false) // dialogResult can be null if the window is closed by the user clicking the X
{break; // Exit the loop if Ignore All was clicked or the window was closed
}
}
}// In your SpellCheckWindow.xaml.cs (Code-behind)privatevoidIgnoreAllButton_Click(object sender, RoutedEventArgs e)
{
_stopProcessing = true;this.DialogResult = true; // Set DialogResult to true so that the await in the external command will be unblocked.this.Close(); // Close the window
}privatevoidIgnoreButton_Click(object sender, RoutedEventArgs e)
{if (IncorrectWords.Any())
{
IncorrectWords.RemoveAt(0);
}this.DialogResult = true; // Important to unblock the loopthis.Close();
}// Instead of bool, use a nullable bool to handle the case where the user closes the window with the X.// The result can be true, false or null.publicbool? ShowDialog();
Explanation and Key Improvements:
async
and await
: The OpenSpellCheckWindowForWord
method is now async
. The await Task.Run(() => spellCheckWindow.ShowDialog())
line is crucial. It allows the code execution to "yield" while the dialog is open without blocking the UI thread. This means the UI thread remains responsive and can process the IgnoreAllButton_Click
event. Crucially, the loop continues after the dialog is closed.
Task.Run
: The ShowDialog()
is wrapped in Task.Run()
. This ensures that the dialog is shown and handled on a background thread, preventing it from blocking the UI thread.
Passing word
Directly: The OpenSpellCheckWindowForWord
method now passes the word
directly to the SpellCheckWindow
constructor, simplifying the code.
DialogResult
: Setting this.DialogResult = true;
in both button click handlers is essential. This sets the result of the ShowDialog()
method, unblocking the await
call in your external command. If you don't set the DialogResult
and the user just closes the window with the X, the result will be null. You should handle this case to avoid an exception.
Nullable bool?
: The ShowDialog()
method returns a bool?
(nullable boolean). This is important to handle the case where the user closes the dialog by clicking the 'X' instead of using the buttons. In this case, the DialogResult will be null.
Checking stopProcessing
afterawait
: The if (stopProcessing)
check now happens after the await
, ensuring that the loop can immediately react to the flag change.
Simplified IgnoreButton_Click
: The IgnoreButton_Click
now also sets the DialogResult
to true and closes the window. This is important to unblock the loop and allow the next word to be displayed.
Practical Demonstration:
SpellCheckWindow
(WPF) with the provided code.This revised approach leverages asynchronous programming to solve the blocking issue and provides a clean and efficient way to handle the "Ignore All" functionality in your WPF spell check dialog. This is the standard pattern for handling modal dialogs in WPF applications when you need to react to events that might occur while the dialog is open.
Hi everyone,
I'm experiencing a strange issue. A specific family fails to load using the .LoadFamilySymbol() method.
However, when I load the family manually, it works without any problems.
This is a type catalog family, and other catalogs are working fine. I tried rebuilding the family, but the issue persists.
Note: The .txt file contains the "Ø" symbol. I tried removing it, but that didn’t resolve the problem.
Does anyone have any ideas?
Download link:
https://we.tl/t-bmIRcNAejM
Thanks in advance!
Solved:
The problem was the .txt format, some how there was an unknown symbol in the txt.
Bonjour
Je cherche une solution pour importer des tableurs type excel directement sur Revit (sans passer par autocad).
Avez-vous des solutions?
Avant c'était possible avec diroots mais c'est devenu payant depuis quelques mois...
Merci d'avance pour votre aide.