Search code examples
c#autocadautocad-plugin

How do we set the AutoCAD layer viewport override values


We have a requirement to add multiple viewports in a single layout and each should have a different layer theme.

Am aware of the viewport overrides- VP Color, VP Linetype, VP Lineweight. I was able to set this directly in autocad as well.

I need to do this programatically and I am not able to find the properties to be set.

The way we generally set the layer properties

LayerTableRecord ltr = (LayerTableRecord)trans.GetObject(layerId, OpenMode.ForWrite, false); 
ltr.Color = lColour;
ltr.LinetypeObjectId = linetype;
ltr.LineWeight = lineWeight;

There are no properties to set viewport overrides.

Doing the above when adding the viewport changes the model layer properties.


Solution

  • This should be enough to get you going on the right path:

    Note: oVpId is the Viewport's ObjectId, oId is the Layout's ObjectId

    Dim oLay As LayerTableRecord = TryCast(oTr.GetObject(oId, OpenMode.ForWrite), LayerTableRecord)
    
    oLay.GetViewportOverrides(oVpId).Color or .Linetype