Unable to lock detail view with API

Hello everyone and thank you in advance for the help :slight_smile:

I am currently trying to duplicate layout pages and copying all objects.
I am having a slight issue when duplicating the detail views. It seems that I managed to reproduce the same detail view but the locking is not passing.

I am starting from a layout page with a locked detail view (debugging with Visual Studio it shows as locked) but when setting the IsProjectionLocked in the new detailView it does not work.

Here is my code that copy the properties from the old detail view to the new one.

//Setting the new layout active     
layoutCopy.SetPageAsActive();
//Setting the new detail view active
layoutCopy.SetActiveDetail(objectGuid);
//Get the right projection view and set it
if (Enum.TryParse(detailView.Viewport.Name, true, out DefinedViewportProjection viewportProjection)) {
    detailViewCopy.Viewport.SetProjection(viewportProjection, string.Empty, false);
    detailViewCopy.CommitViewportChanges();
}
//Set the same display mode
detailViewCopy.Viewport.DisplayMode = detailView.Viewport.DisplayMode;
//Set the same scale
detailViewCopy.DetailGeometry.SetScale(1, rhDoc.ModelUnitSystem, detailView.DetailGeometry.PageToModelRatio, rhDoc.ModelUnitSystem);
//Set the same Camera target
detailViewCopy.Viewport.SetCameraTarget(detailView.Viewport.CameraTarget, true);

//Set the lock (NOT WORKING)
detailViewCopy.DetailGeometry.IsProjectionLocked = detailView.DetailGeometry.IsProjectionLocked;

//Commiting changes
detailViewCopy.CommitChanges();
detailViewCopy.CommitViewportChanges();
layoutCopy.SetPageAsActive();

Hi @brice.canteneur1,

The attached code works for setting a detail locked or unlocked:

TestToggleDetailLock.cs (1.2 KB)

After doing this:

if (Enum.TryParse(detailView.Viewport.Name, true, out DefinedViewportProjection viewportProjection))
{
  detailViewCopy.Viewport.SetProjection(viewportProjection, string.Empty, false);
  detailViewCopy.CommitViewportChanges();
}

your reference to detailViewCopy is most likely out-of date. Try reacquiring the detail and then setting its properties before committing again.

– Dale

Hi @dale !
Thanks a lot for the help.

I retrieved the detailViewCopy after commiting changes like you said and now it works :slight_smile: :+1:

detailViewCopy = Array.Find(copy.GetDetailViews(), dv => dv.Id == detailViewCopy.Id);
if (detailViewCopy != null) {
    detailViewCopy.DetailGeometry.IsProjectionLocked = detailView.DetailGeometry.IsProjectionLocked;
}
detailViewCopy.CommitChanges();