I am trying to extract Geometry from import instance who's layers are currently visible in the current view.
I pass the view into the Geometry options, but it still returns all geometry in the instance.
I can get the name of the DWG layer from:
(curDoc.GetElement(curObj.GraphicsStyleId) as GraphicsStyle).Name;
But cannot seem to find anywhere in the View Class to check if this layer is on or off. Which is achievable with the UI visibility dialog.
What would be the best way to approach this?
Thanks
Ryan
Solved! Go to Solution.
Solved by Ryan. Go to Solution.
Dear Ryan,
Thank you for your query.
Are you referring to the following functionality to Hide Layers in CAD Files?
It refers to 'imported categories'.
Therefore, you may be able to affect the visibility in the Revit view by controlling the category visibility.
The following two methods control that:
To test, you might call GetCategoryHidden, make a note of what it returns, modify the setting for a specific layer manually, and check the return value again to see whether it changed.
If so, it may be possible to use SetCategoryHidden to control the layer visibility.
I hope this helps.
Best regards,
Jeremy
Thanks Jeremy,
As usual, i didn't go deep enough in my testing. The layer categories that i was after to pass into GetCategoryHidden() are one step more in GraphicsStyle.GraphicsStyleCategory.Id .
In my testing, i was thinking that the API wanted a BuiltInCategory. And for that, all i could find was BuiltInCategory.OST_ImportObjectStyles.
The following code works as expected, only adding the DWG geometry that is currently visible in view to the list.
foreach (GeometryObject gObject in gElement) { gInstance = (GeometryInstance)gObject; gElement2 = gInstance.GetInstanceGeometry(); foreach (GeometryObject obj in gElement2) { var gStyle = curDoc.GetElement(obj.GraphicsStyleId) as GraphicsStyle;
//Try Catch because i was getting some Object Instance errors with the graphics style object. try { //add object to list if (!view.GetCategoryHidden(gStyle.GraphicsStyleCategory.Id)) list.Add(obj); } catch { continue; } } }
One question is left though, shouldn't passing the view into the GeometryOptions only allow the visible cad layers to come back in the GeometryObject?
Thanks again.
Dear Ryan,
Thank you for your update.
Congratulations on solving it.
Could you possibly provide a full reproducible case to demonstrate this in action, with a minimal DWG, a minimal RVT, and a minimal add-in or macro ready to run?
http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b
This looks useful enough to be worth sharing on the blog, if you are OK with that.
Thank you!
Some aspects that I note:
First, how can you call gInstance.GetInstanceGeometry() without first checking whether gInstance is null?
Second, you should never, ever catch all exceptions:
http://thebuildingcoder.typepad.com/blog/2017/05/prompt-cancel-throws-exception-in-revit-2018.html#5
Narrow it down to the one that you really observe and expect.
I hope this helps.
Best regards,
Jeremy
Hi Jeremy,
Finally had time to put this into a simple project. Project has a basic macro that will draw a detailed region around the visible layer in the linked cad.
Thanks again.
Ryan
Thank you very much for putting together the nice sample.
I published it now on The Building Coder:
Cheers,
Jeremy