Page 1 of 1

Determine if a drawing dimension is an inserted model item

Posted: Fri Dec 17, 2021 8:53 am
by Rob
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

Code: Select all

D1@Boss-Extrude1@Part1.Part
whilst other dimension names look like

Code: Select all

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

Re: Determine if a drawing dimension is an inserted model item

Posted: Fri Dec 17, 2021 9:08 am
by mattpeneguy

Re: Determine if a drawing dimension is an inserted model item

Posted: Fri Dec 17, 2021 10:08 am
by Rob
mattpeneguy wrote: Fri Dec 17, 2021 9:08 am Is this what you are looking for?
http://help.solidworks.com/2018/english ... state.html
image.png
image.png (13.11 KiB) Viewed 1780 times
fraid not

Re: Determine if a drawing dimension is an inserted model item

Posted: Fri Dec 17, 2021 11:16 am
by Rob
oooh I just found this Get Component via Display Dimension Example

also think IsReference will help

Re: Determine if a drawing dimension is an inserted model item

Posted: Fri Dec 17, 2021 12:59 pm
by Austin Schukar
Maybe check http://help.solidworks.com/2015/english ... awing.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.

Re: Determine if a drawing dimension is an inserted model item

Posted: Fri Dec 17, 2021 11:45 pm
by gupta9665
Check if View.GetDisplayData3 helps.

Re: Determine if a drawing dimension is an inserted model item

Posted: Sun Dec 19, 2021 2:51 am
by Rob
Austin Schukar wrote: Fri Dec 17, 2021 12:59 pm Maybe check http://help.solidworks.com/2015/english ... awing.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.
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
image.png (2.58 KiB) Viewed 1703 times
[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!

Re: Determine if a drawing dimension is an inserted model item

Posted: Tue Dec 21, 2021 9:16 am
by HerrTick
The object chain for dimensions is long and convoluted. It could be any one of a number of objects. Keep sifting and probing.

Re: Determine if a drawing dimension is an inserted model item

Posted: Tue Dec 21, 2021 9:59 am
by Rob
HerrTick wrote: Tue Dec 21, 2021 9:16 am 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.

Code: Select all

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

Code: Select all

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

Re: Determine if a drawing dimension is an inserted model item

Posted: Tue Dec 21, 2021 10:32 am
by Austin Schukar
Thanks for sharing, Rob!