SolidDNA get view of a drawing

You called? :slight_smile:

The Views method is a bit strange and not user-friendly for beginners. I’m not really a fan of the methods that take an Action parameter, that’s all built by Luke before me.

To do something useful with the views, you can do something like this:

public static void Test()
{
    SolidWorksEnvironment.Application.ActiveModel.Drawing.Views(PerformActionOnViews);
}

private static void PerformActionOnViews(List<DrawingView> views)
{
    foreach (var drawingView in views)
    {
        var referenceModel = drawingView.UnsafeObject.ReferencedDocument;
    }
}

I don’t understand why @BigCrazyAl is using the CustomPropertyView, maybe he’s checking if the first is the sheet? If so, I’d use IView.GetType for that.

Be careful that the ReferencedDocument can be null if the underlying part or assembly is not loaded, so you may have to check that value before you create a Model from it.

In general, you don’t have to call Dispose on an UnsafeObject if you are not storing a reference to this object for a long time. Like storing the active model in a static variable that you keep in place for hours, even when the user changes the active model. Don’t do that if you don’t really need to.

I don’t think I use Dispose in any of my products. If you have a method where you get an UnsafeObject, use a property or call a method on it and don’t store the object for later use, you’ll be fine. As soon as the brackets of the method of if-statement close, the variable goes out of scope and the rest is taken care of by .NET.

2 Likes