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: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
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!
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();
}