Get AssemblyDetailViewOrientation from existing view

Get AssemblyDetailViewOrientation from existing view

Anonymous
Not applicable
2,876 Views
17 Replies
Message 1 of 18

Get AssemblyDetailViewOrientation from existing view

Anonymous
Not applicable

Hello,

 

I was curious if it's possible to access the AssemblyDetailViewOrientation property within a view that exists in the project?

 

when creating a view via AssemblyViewUtils theres a method: 

 

AssemblyViewUtils.CreateDetailSection(doc, i.Id, AssemblyDetailViewOrientation.ElevationFront)

 

In this method AssemblyDetailViewOrientation is set to a view type, but I have not managed to find a way to pull this data. Revit of course automatically names the view based on it's orientation, but if a user changes the name of the view, how could you determine the orientation of the view?

 

I'm trying to pull this data from an existing view to basically create new views for a new assembly that 'duplicate' an existing sheet with views placed on it. But if I can't pull this data from each view then I'll likely have to rely on the view name and account for duplicates which would make it more difficult to accommodate every scenario.

 

At the moment I am using:

 

if viewTemplate.Name == "Elevation Front":
    view = AssemblyViewUtils.CreateDetailSection(doc, i.Id, AssemblyDetailViewOrientation.ElevationFront)
elif viewTemplate.Name == "Elevation Top":
    view = AssemblyViewUtils.CreateDetailSection(doc, i.Id, AssemblyDetailViewOrientation.ElevationTop)
elif viewTemplate.Name == "Plan Detail":
    view = AssemblyViewUtils.CreateDetailSection(doc, i.Id, AssemblyDetailViewOrientation.HorizontalDetail)
elif viewTemplate.Name == "Detail Section A":
    view = AssemblyViewUtils.CreateDetailSection(doc, i.Id, AssemblyDetailViewOrientation.DetailSectionB)
elif viewTemplate.Name == "3D Ortho":
    view = AssemblyViewUtils.Create3DOrthographic(doc, i.Id)

But ultimately I'd like to use:

 

assemblyViewOrient = templateView.MethodForGetting(AssemblyDetailViewOrientation)


view = AssemblyViewUtils.CreateDetailSection(doc, assembly.Id, AssemblyViewOrient)

where templateView is the pre-existing view

 

Thanks!

 

 

0 Likes
2,877 Views
17 Replies
Replies (17)
Message 2 of 18

Anonymous
Not applicable

Still looking for any information on this.

 

One work around is to use view direction and compare it to the orientation of the assembly origin but it would be great to just query the view being used as a template rather than jumping into it and using directional comparisons.

 

Thanks!

0 Likes
Message 3 of 18

Anonymous
Not applicable

Would this be my only option then? Does the api not give access to this information after it has been set?

0 Likes
Message 4 of 18

Anonymous
Not applicable

Hello,

 

Still looking for a solution to this!

Thanks!

0 Likes
Message 5 of 18

Anonymous
Not applicable

Any thoughts on this?

0 Likes
Message 6 of 18

RPTHOMAS108
Mentor
Mentor

Assembly views exist in database in their own right so you have to filter for them and check AssociatedAssemblyInstanceID matches your target instance rather than null. View class also has a property View.IsAssemblyView to help with such filtering.

 

Assembly instance has no orientation so view orientations created are based on project north I believe. i.e. even if you create them on a rotated scope boxed view it sets the views up to project north. If you rotate them only the items within the container rotate, similar to group behaviour.

0 Likes
Message 7 of 18

Anonymous
Not applicable
I appreciate your response, but I don’t think that’s correct.

The view is based upon the assembly instance orientation I am referring to is the assembly origin which is verifiable if you create an assembly instance and rotate it, front view would remain the same regardless of how you rotate it in model space(when creating new voting views).

But ultimately this isn’t what I’m looking for. My intention is to find a method or call that would tell me what the view orientation is. When a view is created in revit it is given a default name which is equivalent to the orientation - so there is at least a short period of time in which that property is readable, I’d like to access that property (and not through the temporary naming revit gives the view by default).
0 Likes
Message 8 of 18

RPTHOMAS108
Mentor
Mentor

Left/Right/Bottom/Top are based on project co-ordinates (the viewcube). So for views orthogonal to project co-ordinates this can be easily re-established by looking at view direction. Since we've now established that assembly views created are orthogonal to project co-ordinates I don't really understand the issue?

 

0 Likes
Message 9 of 18

RPTHOMAS108
Mentor
Mentor

Below are some view extension methods that may help but in general such view names are not that important. To duplicate a view direction is more straightforward.

 

Works for my limited VB example, not checked C#

 

VB

Public Module RvtExtMethodsModule
   <Extension()> _
    Public Function ViewOrphoName(ByVal View As Autodesk.Revit.DB.View) As String

        Dim D As Document = View.Document
        Dim Loc As ProjectLocation = D.ActiveProjectLocation
        Dim Vec As XYZ = Loc.GetTransform.Inverse.OfVector(View.ViewDirection)

        Dim X As Integer = Vec.X
        Dim Y As Integer = Vec.Y
        Dim Z As Integer = Vec.Z

        If Z = -1 Then
            Return "Bottom"
        ElseIf Z = 1 Then
            Return "Top"
        ElseIf Z = 0 Then
            If X = -1 Then
                Return "Left"
            ElseIf X = 1 Then
                Return "Right"
            ElseIf Y = -1 Then
                Return "Front"
            ElseIf Y = 1 Then
                Return "Back"
            Else
                Return "N/K"
            End If
        Else
            Return "N/K"
        End If
    End Function
End Module

 

C#

 

public static class RvtExtMethodsModule
{
    [Extension()]
    public static string ViewOrphoName(Autodesk.Revit.DB.View View)
    {

        Document D = View.Document;
        ProjectLocation Loc = D.ActiveProjectLocation;
        XYZ Vec = Loc.GetTransform().Inverse.OfVector(View.ViewDirection);

        int X = Convert.ToInt16(Vec.X);
        int Y = Convert.ToInt16(Vec.Y);
        int Z = Convert.ToInt16(Vec.Z);

        if (Z == -1)
        {
            return "Bottom";
        }
        else if (Z == 1)
        {
            return "Top";
        }
        else if (Z == 0)
        {
            if (X == -1)
            {
                return "Left";
            }
            else if (X == 1)
            {
                return "Right";
            }
            else if (Y == -1)
            {
                return "Front";
            }
            else if (Y == 1)
            {
                return "Back";
            }
            else
            {
                return "N/K";
            }
        }
        else
        {
            return "N/K";
        }
    }
}

 

 

 

0 Likes
Message 10 of 18

Anonymous
Not applicable

This isn't accurate. The views are solely based on assembly origins. When an assembly is created it is based upon the viewcube, project orientation, thus creating a relationship between project orientation and assembly orientation and assembly views, but assembly orientation can be modified to accommodate say an assembly that is not orthogonal to the project, perhaps a diagonal wall or something of the sort. Thus project orientation and assembly orientation, and therefore assembly view directions, are not dependent upon one another. 

 

This means checking the view orientation gives non-relevant information, an assembly view with orientation (1, 1, 0) and a second assembly with view orientation of (.75, -.5, 0) could both be Front Views in their own right.

 

As I mentioned before, when you create an assembly view you give it an orientation which is based upon the assembly, to be able to retrieve that orientation property would allow you to copy the exact layout and type of views from one assembly to another, but without being able to retrieve this property you'd simply be crossing your fingers that the user hasn't modified the view name which initially contains view information such as "Elevation Front", "Elevation Top", etc.

 

I appreciate your continued efforts in trying to find a solution to this.

 

Please feel free to test out what I am saying:

1) Create a wall in model space, any orientation, and size.

2) Create assembly from the wall.

3) Create an Elevation Front view for the assembly.

4) Edit the assembly and rotate the assembly orientation, perhaps by 90 degrees for the most visible change.

5) Create another Elevation Front view for the assembly and compare the two.

 

You should notice these two elevation front views are completely different, supporting my claim that the view is based upon assembly orientation and not project orientation, though initially project orientation and assembly orientation are the same.

0 Likes
Message 11 of 18

RPTHOMAS108
Mentor
Mentor

Going back to the original task there is the need to create a view in assembly B which is a copy of assembly A and the new view is to have the same properties as those taken from the equivalent view direction in assembly A?

 

We should agree the named orientations are placeholder names and meaningless beyond when they are created? They only exist to stop user from creating non-orthogonal views to assembly bounding box. Assembly has a transform that relates it to internal co-ordinates (has a rotation because it's basis x and y changed as I rotated it). View has a view direction that relates it's orientation to internal co-ordinates. Therefore there is a relationship between the view and it's assembly to identify two views from different assemblies as equivalent in direction (regardless of when they were back/front/left/right).

 

Beyond a user renaming a view you also can't control at what point a user may create a view, so the placeholder names are meaningless for subsequent identification. I believe my mistake above is using transform from project (thinking you care about project relationship) when in reality you want to use the one from the assembly.

 

I don't think there'll ever be a method for identifying existing view direction via it's original enum value due to the reasons you outlined.

0 Likes
Message 12 of 18

BardiaJahan
Advocate
Advocate

Could you clarify what you are trying to do? Maybe by providing a file or something. Why couldn't you use ViewDirection property? Get the view direction from assembly A, create a detail section (doesn't really matter - Front) and then rotate the view cropbox to make it aligned with the template view. Why wouldn't this work?

0 Likes
Message 13 of 18

Anonymous
Not applicable

I'm having trouble simplifying this down, but here's another shot.

 

Let's say you have 2 wall assemblies with 2 different orientations, assembly 1 is facing east and assembly 2 is facing north and the assembly origin has been oriented for each assembly (thus the front elevation view shows the front face of the wall).Now make a Front Elevation view for assembly 1.

 

So, in this instance, how would you be able to determine the view type (as it is called when creating assembly views) of the first Front Elevation View so that you would know to create a Front Elevation View for the second assembly?

 

I don't understand why a stipulated input, AssemblyDetailViewOrientation (CreateDetailSection(Document, ElementId, AssemblyDetailViewOrientation), is not retrievable.

 

if you wanted to duplicate the view locations and types from a sheet (used as a template) for multiple assemblies, how would you know what to input for AssemblyDetailViewOrientation?

 

0 Likes
Message 14 of 18

Anonymous
Not applicable

RPTHOMAS, I think you've got a handle on what I'm trying to do now. I suppose this means there isn't a built-in way to determine the view's orientation in relation to the assembly it is a view of.

0 Likes
Message 15 of 18

BardiaJahan
Advocate
Advocate

And how would you do the same thing in the UI?

0 Likes
Message 16 of 18

Anonymous
Not applicable

Outside of the default view name and a visual check (which would be the same operation as view orientation vs assembly orientation), I can't think of any way to determine the 'view type'. 

 

I guess now my question is why wouldn't this be revealed or saved in revit?

0 Likes
Message 17 of 18

BardiaJahan
Advocate
Advocate

Well, you are performing a visual check and this is what you would need to implement through API. FYI, you could create a Front view and rotate it however you want. 

And about your other question, since there is not such a command in Revit UI, I am not surprised that it is not included in its API either.

0 Likes
Message 18 of 18

Anonymous
Not applicable

My current implementation uses the view names because our standards accomodate that, I was just hoping to find a more 'secure' method to determine the view type.

 

Using viewDirection and comparing that to the assembly orientation could be implemented, certainly, it just isn't as tidy..

 

Thank you so much for your responses.

0 Likes