Determine if a drawing dimension is an inserted model item

Programming and macros
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 207
Contact:

Determine if a drawing dimension is an inserted model item

Unread post 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
User avatar
mattpeneguy
Posts: 1386
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2489
x 1899

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

Unread post by mattpeneguy »

User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 207
Contact:

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

Unread post 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 1781 times
fraid not
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 207
Contact:

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

Unread post by Rob »

oooh I just found this Get Component via Display Dimension Example

also think IsReference will help
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

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

Unread post 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.
Austin
User avatar
gupta9665
Posts: 393
Joined: Thu Mar 11, 2021 10:20 am
Answers: 21
Location: India
x 410
x 430

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

Unread post by gupta9665 »

Check if View.GetDisplayData3 helps.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 207
Contact:

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

Unread post 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 1704 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!
Attachments
image.png
User avatar
HerrTick
Posts: 207
Joined: Fri Mar 19, 2021 10:41 am
Answers: 1
x 32
x 307

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

Unread post 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.
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 207
Contact:

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

Unread post 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
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

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

Unread post by Austin Schukar »

Thanks for sharing, Rob!
Austin
Post Reply