Visibility of DWG layer

Visibility of DWG layer

Ryan
Enthusiast Enthusiast
2,130 Views
5 Replies
Message 1 of 6

Visibility of DWG layer

Ryan
Enthusiast
Enthusiast

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

0 Likes
Accepted solutions (1)
2,131 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 6

Ryan
Enthusiast
Enthusiast
Accepted solution

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.

 

 

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

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

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 6

Ryan
Enthusiast
Enthusiast

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

0 Likes
Message 6 of 6

jeremy_tammik
Alumni
Alumni

Thank you very much for putting together the nice sample.

 

I published it now on The Building Coder:

 

http://thebuildingcoder.typepad.com/blog/2018/05/retrieve-visible-dwg-geometry-and-foreground-image-...

 

Cheers,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open