Determine if a drawing dimension is an inserted model item

Hi guys

I’d like to work with the drawing dimensions that have been inserted as Model Items.

I’ve looked through the IAnnotaion, IDisplayDimension & IView interfaces and couldn’t see anything that looked right.

It looks like I could do this by looking at the Dimension FullName which for inserted items looks something like

D1@Boss-Extrude1@Part1.Part

whilst other dimension names look like

RD1@Drawing View1@Part1.Drawing

All good I suppose, but it seems a bit hacky!

Anyone know if there’s a property or alternate way of working with inserted model items?

Nice1, cheers

Is this what you are looking for?
http://help.solidworks.com/2018/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.idimension~drivenstate.html

image.png
fraid not

oooh I just found this Get Component via Display Dimension Example

also think IsReference will help

Maybe check http://help.solidworks.com/2015/english/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IDisplayDimension~MarkedForDrawing.html as well?

Edit: How do I edit the hyperlink display text?

Edit2: I just tried, and it doesn’t show the inserted dimension as “Marked for Drawing” since it now resides in a drawing…what the heck. Also tried OwnerType Property (IAnnotation) with no luck. It determined the owner was a drawing view.

Check if View.GetDisplayData3 helps.

Nice1 Austin, Thanks


[re:Edit2]
Yep . those were my initial thoughts too but it’s not as easy as I though it could be.
My end goal for this is to delete an inserted model item in the drawing and also go to the model and unmark for drawing.

[re:Edit1]
likethis
image.png
[Waffle}
I have been able to write code to get at the inserted items but Im having problems down the rabbit hole.
the forum is blocking me from posting it so here’s my snips.. Sorry if it looks a bit weird - I’m just experimenting with style.
I’m using some of my own extension methods which are mostly just casting the parameters and returns of the SWAPI calls
Very Foolishley I’m using c#8, there’s an incompatibility warning but I’m just having fun with the language features that are new to me, like nullable types and switch expressions
image.png
I too discovered OwnerType Property, it is useful to check we have a view
image.png
when you get t’view you can get t’referenced doc. You can grab the dimension full name, config status and model path.
image.png
But after that Im in the weeds. Im not sure how to use the GetCorresponding Methods and which one to use to get to the actual display dimension in the part or assembly or component.. TBC no doubt!

The object chain for dimensions is long and convoluted. It could be any one of a number of objects. Keep sifting and probing.

Cheers

I ended up just brute forcing it, grabbing the referenced document pathname, along with the referenced configuration, feature name and dimension name and put them in a nested dictionary.

var jobsFerDo = new Dictionary<string, IDictionary<string, IDictionary<string, IList<string>>>>();

foreach (var (pathName, isOpenedViewOnly, configName, configID, isConfigured, configNames, dimensionName, featureName) in usefulShiz)
{
    if (!jobsFerDo.ContainsKey(pathName))
            jobsFerDo.Add(pathName, new Dictionary<string, IDictionary<string, IList<string>>>());

    if (!jobsFerDo[pathName].ContainsKey(configName))
            jobsFerDo[pathName].Add(configName, new Dictionary<string, IList<string>>());

    if (!jobsFerDo[pathName][configName].ContainsKey(featureName))
            jobsFerDo[pathName][configName].Add(featureName, new List<string>());

    jobsFerDo[pathName][configName][featureName].Add(dimensionName);

    if (isConfigured)
    {
        foreach (string otherConfigName in configNames)
        {
        if (!jobsFerDo[pathName].ContainsKey(otherConfigName))
                jobsFerDo[pathName].Add(otherConfigName, new Dictionary<string, IList<string>>());

        if (!jobsFerDo[pathName][otherConfigName].ContainsKey(featureName))
                jobsFerDo[pathName][otherConfigName].Add(featureName, new List<string>());

        jobsFerDo[pathName][otherConfigName][featureName].Add(dimensionName);
        }
    }
}

Then I went through the Dictionary and did all the adjustments

foreach (string? path in jobsFerDo.Keys)
{
    IModelDoc2 model = SWAp.ActivateDocumentEx(path, out swActivateDocError_e error) !;

    model.SetSaveFlag();

    string initialConfig = model.ConfigurationManager.ActiveConfiguration.Name;

    foreach (string configName in jobsFerDo[path].Keys)
    {
        model.ShowConfigurationEx(configName);

        foreach (string featureName in jobsFerDo[path][configName].Keys)
        {
            IFeature feature = model switch
            {
                IAssemblyDoc assm => assm.IFeatureByName(featureName),
                    IPartDoc part => part.IFeatureByName(featureName),
                                _ => throw new InvalidOperationException(),
            }

            ?? throw new Exception($"{featureName}");

            foreach (string dimName in jobsFerDo[path][configName][featureName])
            {
                if (feature.GetDisplayDimensionsEx()
                    .Where(dd => dd.IGetDimension().Name.Equals(dimName))
                    .FirstOrDefault() is IDisplayDimension dispDim)
                {
                    dispDim.MarkedForDrawing = false;
                }
            }
        }

        Log($"{configName} {model.EditRebuild3()}");
    }

    model.ShowConfigurationEx(initialConfig);
    model.GraphicsRedraw2();
}

Not very elegant, but it working so far

Thanks for sharing, Rob!