Somtimes no Mass from ISwDMConfiguration14.GetMassProperties

Hello,

I use DocumentManager to the mass from all configurations:

2017 SOLIDWORKS API Help - GetMassProperties Method (ISwDMConfiguration)

Sometimes I get a swDmMassPropErrorNoData-error for a configuration. When I open the file in SWX, change to this configuration and use swModel.Extension.GetMassProperties, I get the mass.

Does anyone can guess a reason, why DM is sometimes not working?

Thanks,

Samuel

SolidworksApi macros
Answers 8
AJ
AJ 2017-11-16 Best Answer
swDmMassPropErrorNoData2 = Reason for error could be that mass properties were not calculated before the part was saved

Apparently GetMassProperties only retrieves a cached result created by the mass calculation that happens inside SOLIDWORKS so that sholud explain why it is. You need to open the part, calculate the mass, save it and then use the DM again. Mass calculation involves reading the part's bodies. I'm not sure the document manager is designed to do that.

Let me know if this helps.

Cheers,

Amen

CADHERO consulting SUARL – SOLIDWORKS API/PDM Design Automation & Training – SOLIDWORKS VBA MACROS, SOLIDWORKS Addins an…

SP
SP 2017-11-19

I can not understand, why the cache is not always up to date. If a part isn't been saved, the file does not exists, right? :-)

Or do you mean, that SWX do not always calc the mass before saving?

AJ
AJ 2017-11-19

I do not have access to the SOLIDWORKS source code to tell you exactly what's happening under the hood. I don't understand what you mean by this,

<span style="color: #333333; font-family: Verdana, 'Verdana Ref', Geneva, Tahoma, sans-serif; font-size: 14px;"> If a part isn't been saved, the file does not exists, right? :-)</span>

If a part has not been saved, the file does not exist: This is only true for when you start a new part. It's not true once the part has been saved for the first time, ie IModelDoc2::GetPathName is returning a non empty string.

I think SOLIDWORKS will not calculate the mass before saving, which makes sense, according to the principle of seperation of concern. The save function should do save the file and the mass calcuation should only calculate the mass. The only way to have an updated mass value to invoke the mass calculation function then save the document. Thus, the DM will get the latest value.

Cheers,
Amen

CADHERO consulting SUARL – SOLIDWORKS API/PDM Design Automation & Training – SOLIDWORKS VBA MACROS, SOLIDWORKS Addins an…

JB
JB 2017-11-20

If the configuration has not been built/rebuilt in SW since the last model change that SW thinks might affect that configuration, the mass is marked as "dirty" and not reported in order to avoid reporting bad data.  For example, if I have a part with configs "A" and "B".  Config A is active.  I change some dimension values and rebuild Config A.  Config B will not be rebuilt until necessary, either being activated in its window or being referenced in an open assembly.  Therefore, its previously calculated mass is probably wrong, but SW doesn't spend the resources to calculate it yet.  This is to avoid massive rebuild times and file sizes.  I have a capscrew file that contains all sizes possible, but it's a very small file because only one of the configurations has ever been active/built.  All other configs were created by a design table.  If I activated and built every config, the file would be huge.  If you want to avoid missing mass values, you must rebuild each configuration in SW, save, and then the DM will report mass for each configuration.  There are macros available to rebuild each configuration before saving.

AJ
AJ 2017-11-20

So the rebuild functions invoke the mass calculation? Can you paste where that is said in the docs because I can't find it :s. Thanks for sharing.

JB
JB 2017-11-20

I don't think there's a need to consult documentation in this case... It follows from logic.  It is patently obvious that SW cannot calculate mass for something it hasn't rebuilt.  SW has internal ways of knowing if things have changed enough to require a rebuild.  The IConfiguration object has an IsDirty method.  ISwDMConfiguration10 has this method as well. I can't say for sure, but I would wager a pretty considerable amount that if IsDirty returns true, you get no mass and if IsDirty is false, you get a mass.

CZ
CZ 2019-01-17

X:\ProgramData\SOLIDWORKS\SOLIDWORKS 2018\design library\routing\electrical\pabst 512f - with 310 mm lead.sldprt

Return Dirty==False, but get a swDmMassPropErrorNoData.

How to update its through the "Document Manager API"?

JB
JB 2019-01-17

You can't.  Document Manager cannot rebuild things.  Only SolidWorks can.