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: 

toggle ref plane visibility

4 REPLIES 4
Reply
Message 1 of 5
paul
1008 Views, 4 Replies

toggle ref plane visibility

I'm attempting to create an external command to toggle the visibility of reference planes on and off, but can't seem to get it right.

If noticed there is no built-in category for reference planes. So I used the following code instead:

Autodesk.Revit.Elements.ReferencePlane rp = new Autodesk.Revit.Elements.ReferencePlane();
Category cat = rp.Category;

However on the last I line I get an error like this:

System.AccessViolationException: Attempted to read or write protected memory.

I'm guessing it's because the 'Category' property is part of the derived Element class and not part of the ReferencePlane class itself, but I can't seem to find a way to specify the reference plane category.

Any ideas?
4 REPLIES 4
Message 2 of 5
michaelhodges
in reply to: paul

did you figure it out?

 

I'd love a toggle keyboard shortcut to view and hide ref planes.

Message 3 of 5
krispy
in reply to: michaelhodges

BuiltInCategory is OST_CLines

Message 4 of 5
mertens3d
in reply to: krispy

I was able to get this in some code I wrote. If i reme....ah heck...let me go find it and cut and past...hang on.

 

 

 

 

 

 Public Sub toggleOneCategory(ByVal catName As String)

        Dim oneCat As Autodesk.Revit.DB.Category


        Dim aView As Autodesk.Revit.DB.View

        Dim docTransaction As New Autodesk.Revit.DB.Transaction(ptrToDoc)

        aView = ptrToDoc.ActiveView


        For Each oneCat In ptrToDoc.Settings.Categories

            If oneCat.Name = catName Then

                'Dim dog As String = ""
                Try
                    docTransaction.SetName("stg - quickToggle")


                    docTransaction.Start()
                    Dim oldVis As Boolean
                    oldVis = aView.getVisibility(oneCat)

                    aView.setVisibility(oneCat, Not oldVis)

                    docTransaction.Commit()



                Catch ex As Exception
                    MsgBox(ex.ToString)

                End Try

            End If

        Next
    End Sub

 

Using a built in category is probably better, but similar idea.

 

Message 5 of 5
mertens3d
in reply to: mertens3d

lol...oh...and i've since learned from Jeremy that wrapping this sub/function in a try/catch is not good coding.

 

Additionally, if i should probably have exited the for loop, once found.

 

i'm learning. 🙂

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community