Custom Property from lightweight component vb.net

Hi,

I have an application, what traverse through an assembly's all subassemblies and parts, and I'd like to get custom info all of parts and assemblies.

My problem is, I can not get/set custom properties if a component is lightweight.

I've tried that to set lightweit components to resolve before I'd like to handle property, but in case of a huge assembly that takes very long time to finish the whole traverse.

I have a traverse function with a variable what contains a current component:

Comp As SldWorks.Component2

If I'm right, Ican only get/set custom properties in ModelDoc objects, so I get the Modeldoc the way below.

(confStr is a String what is declared previously)

Dim CompModel As SldWorks.ModelDoc2 = Comp.GetModelDoc2

If CompModel IsNot Nothing Then

   Dim PartNo As String = CompModel.GetCustomInfoValue(confStr, "PartNo")

End If

...

The problem is, if component is lightweight, CompModel will be Nothing.

Is there any other way to get/set component custom propertiesif it is in lightweight?

thank you

SolidworksApi macros
Answers 8
PM
PM 2017-04-14 Best Answer

Hi Norbert,

you can use IComponent2::SetSuppression2 method to set resolved state of component.

NG
NG 2017-04-14

Thank you the answer, but this is not what I'm looking for.

As I wroted I tried to set the lightweight components to resolved (with this function), but it takes lot of time.

Example with an assembly what contains about 2000 components, the whole traverse process takes more than five minutes if I resolved the lightweight componenets one by one. And sometimes I could not resolve the whole assembly (example huge assemblies) because of memory.

That is the reason why I would like to find other solution what I can use with lightweight mode.

DM
DM 2017-04-14

Hi Norbert, if you check the suppression state of the selected component and it is lightweight, you can then use Document Manager to either read or write properties to the selected part file. If a part is loaded lightweight then it isn't made read only to the file system, therefore Document Manager can write to the file on disk. I remember testing this several years ago for the exact same reason as you mention, large assemblies or files can take a long time to resolve.

Best Regards,

Declan.

AJ
AJ 2017-04-14

I have to concour with ​

Use the DocumentManager instead. This is basically the same as using GetModelDoc2 when the component is not suppressed/lightweight (unless the part open - which I'm assuming is not since it's suppressed/lightweight so that's good a sign). GetModelDoc2 would return the ModelDoc2 from the model file in its last saved state.

2012 SOLIDWORKS API Help - Configurations Property (IPDMWDocument)

There is also another approach to do this (answer by @Jana_Fischer from another question):

My colleague gave me a solution that finishes what I started: The trick is to change some SolidWorks settings before opening the component model document file.

IDocumentSpecification copmDocSpec = _swApp.GetOpenDocSpec(comp.GetPathName());

compDocSpec.ReadOnly = true;

compDocSpec.Silent = true;

_swApp.DocumentVisible(false, compDocSpec.DocumentType); // allows opening the file without opening another window

_swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swLockRecentDocumentsList, true); // prevents the opened file to appear in the recent document list

compDoc = _swApp.OpenDoc7(compDocSpec); // open file - user won't notice

_swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swLockRecentDocumentsList, false); // change back

_swApp.DocumentVisible(true, compDocSpec.DocumentType); // change back

// Do what you want here

//  get custom property for compDoc

Best,
Amen
CADHero.com ​

PM
PM 2017-04-15

Norbert,

you might try another option. This could be also reasonable because as you said you do not have so much memory.

- check state of component (resolve if it is lightweight)

- read property

- save property (external file or memory)

- set component back to lightweight

I did not try it, btw.

When your application is standalone app. or vba macro, the issue of operation speed might be there. Add-in is faster.

Nevertheless how much time does it take?

NG
NG 2017-04-18

Thank you Patric I tried this method before, but I'd like to find what I can use without resolving a component.

NG
NG 2017-04-18

Thank you Amen I tried also this method before, but I'd like to find what I can use without resolving a component

NG
NG 2017-04-18

Thank you, it seems a bit complicated, but I gues there is the only way Thank you