AssemblyViewUtils.CreateDetailSection - isAssigned param disorganize the viewport layout

AssemblyViewUtils.CreateDetailSection - isAssigned param disorganize the viewport layout

mgutierrezBM9E9
Contributor Contributor
439 Views
4 Replies
Message 1 of 5

AssemblyViewUtils.CreateDetailSection - isAssigned param disorganize the viewport layout

mgutierrezBM9E9
Contributor
Contributor

I plan to place 2 assembly viewports at the top left corner of a titleblock.

 

When using the following code to create 1 viewport, everything works fine:

 

var sectionView = AssemblyViewUtils.CreateDetailSection(TicketPopulatorCommand.doc, assemblyId, anchorView.SectionOrientation
?? AssemblyDetailViewOrientation.ElevationTop, anchorViewTemplate.Id, true);


FamilyInstance titleBlock = new FilteredElementCollector(TicketPopulatorCommand.doc)
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_TitleBlocks)
.WhereElementIsNotElementType()
.Where(x => x.OwnerViewId == viewSheet.Id)
.Cast<FamilyInstance>()
.FirstOrDefault();
if (titleBlock == null) throw new Exception("No title block found on the sheet.");
BoundingBoxXYZ titleBlockBox = titleBlock.get_BoundingBox(viewSheet);
XYZ titleBlockMin = titleBlockBox.Min; // Bottom-left of title block
XYZ titleBlockMax = titleBlockBox.Max; // Top-right of title block
XYZ location = new XYZ(titleBlockMin.X, titleBlockMax.Y,0);
Viewport viewport = Viewport.Create(TicketPopulatorCommand.doc, viewSheet.Id, sectionView .Id, location);

 

mgutierrezBM9E9_1-1743039168868.png

 

However, when looping on multiple views there is an offset that gets added to the next view port (in the sample below the viewport from above was passed in the second loop, therefore an offset has been added to that viewport).

mgutierrezBM9E9_0-1743039125609.png

 

By the way, on every loop the min and max value of the title block is the same:
{(-3.328760717, -4.658490202, 0.000000000)}
{(-1.754686650, -3.639971685, 0.000000000)}

I have no clue where the offset is coming from.

 

 

Another examples when placing 3 viewports!

mgutierrezBM9E9_0-1743039510369.png

 

0 Likes
440 Views
4 Replies
Replies (4)
Message 2 of 5

mgutierrezBM9E9
Contributor
Contributor

Can someone from the autodesk dev team take a look into this. Apparently the api does not allow to palce multiple viewports at the same location. Can you confirm this please?

0 Likes
Message 3 of 5

Moustafa_K
Advisor
Advisor

can you show us how are you looping?

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 4 of 5

mgutierrezBM9E9
Contributor
Contributor

I'm not even looping, I'm just creating the assembly sheet:

FamilySymbol titleBlock = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol))
    .OfCategory(BuiltInCategory.OST_TitleBlocks).Cast<FamilySymbol>()
    .FirstOrDefault(tb => tb.Name.Equals(ticketTemplate.Titleblockname, StringComparison.OrdinalIgnoreCase));
if (titleBlock == null) return MolinErrors.Shared.ThrowError($"Titleblock not found: {ticketTemplate.Titleblockname}",
    tg: tg, tr: tr);
ViewSheet viewsheet = AssemblyViewUtils.CreateSheet(doc, assembly.Id, titleBlock.Id);

 

Then, I'm querying the titleblock placed on that sheet:

FamilyInstance titleBlockInstance = new FilteredElementCollector(TicketPopulatorCommand.doc)
    .OfClass(typeof(FamilyInstance))
    .OfCategory(BuiltInCategory.OST_TitleBlocks)
    .WhereElementIsNotElementType()
    .Where(x => x.OwnerViewId == viewsheet.Id)
    .Cast<FamilyInstance>()
    .FirstOrDefault();
if (titleBlockInstance == null) throw new Exception("No title block found on the sheet.");

 

 

then I'm picking the top left corner of the titleblock:

                                BoundingBoxXYZ titleBlockBox = titleBlock.get_BoundingBox(viewsheet);
                                XYZ titleBlockMin = titleBlockBox.Min; // Bottom-left of title block
                                XYZ titleBlockMax = titleBlockBox.Max; // Top-right of title block
                                XYZ location = new XYZ(titleBlockMin.X, titleBlockMax.Y, titleBlockMax.Z);

Finally I'm creating views and placing them onto the sheet:

ElementId mainViewId = TicketPopulatorApp.Shared.CreateView(ticketTemplate.AnchorViews.MainView, assembly.Id);
Viewport viewport = Viewport.Create(TicketPopulatorCommand.doc, viewsheet.Id, mainViewId, location);


ElementId bottomViewId = TicketPopulatorApp.Shared.CreateView(ticketTemplate.AnchorViews.BottomView, assembly.Id);
Viewport bottomVP = Viewport.Create(TicketPopulatorCommand.doc, viewsheet.Id, bottomViewId, location);



This is my CreateView method:

public ElementId CreateView(AnchorView anchorView, ElementId assemblyId) {
    if (TicketPopulatorCommand.doc == null) throw new Exception("Document can not be null");

    View anchorViewTemplate = new FilteredElementCollector(TicketPopulatorCommand.doc)
        .OfClass(typeof(View)).Cast<View>().FirstOrDefault(v =>
        v.IsTemplate && v.Name == anchorView.ViewTemplateName);
    if (anchorViewTemplate == null) throw new Exception($"Template not found: {anchorView.ViewTemplateName}");
    ElementId anchorViewId = ElementId.InvalidElementId;

    switch (anchorView.IsSection)
    {
        case true:
            var sectionView = AssemblyViewUtils.CreateDetailSection(TicketPopulatorCommand.doc, assemblyId, anchorView.SectionOrientation
                ?? AssemblyDetailViewOrientation.ElevationTop, anchorViewTemplate.Id, true);
            anchorViewId = sectionView.Id;
            break;
        case false:
            var view3d = AssemblyViewUtils.Create3DOrthographic(TicketPopulatorCommand.doc, assemblyId, anchorViewTemplate.Id, true);
            anchorViewId = view3d.Id;
            break;
    }
    return anchorViewId;
}

 

0 Likes
Message 5 of 5

mgutierrezBM9E9
Contributor
Contributor

it's crazy, but changing the last parameter from true to false fixed the issue!

var sectionView = AssemblyViewUtils.CreateDetailSection(TicketPopulatorCommand.doc, assemblyId, anchorView.SectionOrientation
?? AssemblyDetailViewOrientation.ElevationTop, anchorViewTemplate.Id, false);

The documentation says the following description:

isAssigned Type: SystemBoolean
If true, the template will be assigned; if false, the template will be applied.

Does someone mind elaborating more on that? I'm still confused how the true value affect the layout of the views.

0 Likes