Reply
Solved! Go to solution

Saving assembly components after modifying properties (ST5)

Hello guys, this is driving me mad, and I'm sure it can be interesting!

 

I have designed an app which (among other things) modifies a lot of internal properties of all components of an assembly. In order to do it, with the assembly opened, I get access to the components through their occurences, so I get the document object and finally the propertysets and properties, without opening every part in its own window. More or less like this:

 

Dim objDocument As SolidEdgeFramaWork.SolidEdgeDocument

'Get document from occurrences and other stuff which works fine
...

'Access to the different properties and modify them OK
Dim objDocPropertySets As SolidEdgeFramework.PropertySets
objPropertySets = objDocument.Properties()
objDocPropertySets.Item(strPropSetName).Item(strPropName).Value = strPropValue

Tis is supossed to be the "logical" path for doing it, since there's access to the documents! 

 

All works fine, and in fact, once the program finishes, I see the properties modified in SE Property Manager.

 

However, as far as I close the assembly (no matter if I save it), when I open it again, all properties have their old value, as if it had never changed. As far as I guess, the fact is that individual component files are never saved.

 

If I simply make a manual change on the Property Manager for all of them after my program runs, I force the saving of all components, so my edited properties also remain. However, is tedius having to enter property Manager and "change anything" just to force a full-saving!

 

I have tried saving each document object after editing their properties, with something like this:

 

objDocument.Save()

However, this generates a share error, I think that due to the nightmare-I-have-never-fully-understand of COM stuff and Marshal demons.

 

Can't I simply force SE to save the open assembly along all its sons, or at least change something in them so they will be saved on the next Save, as Property Manager seems to do? (You must simply modify some property for ALL components and see how log the next assembly saving will take!)

 

I have find an ugly workaround, which is accessing the properties from component's path. Something like this:

 

objPropertySets = New SolidEdgeFileProperties.PropertySets()
objPropertySets .Open(strPath)
...
'Property editing here!
... objPropertySets.Save() objPropertySets.Close()

 

This forces me to close the assembly first to avoid problems, and is a lot slower. Also, my app needs to keep the assembly opened for more operations, I have to reload the whole info again, and I become more and more sad....

 

Any clues of how to save ALL components from an assembly once their properties have been edited?

 

Much thanks in advance!

 

p.s. I'm using ST5 on Windows 7

9 REPLIES

Re: Saving assembly components after modifying properties (ST5)

Hello javigoca,

 

Part of your listed code

objPropertySets .Open(strPath)

has a second optional argument as OpenReadOnly which does not appear to be specified.

I am not sure what the default value for this optional parameter is, but you can try setting it to False explicitly.

 

Regards,

Re: Saving assembly components after modifying properties (ST5)

[ Edited ]

Hi javigoca

 

Last mounth I had a similar issue.

 

What i had to do was to save the propertiset for each occurrence and finally save the assembly.

 

'ocu is the occurrence you're writing properties
'With the Add method you can add new properties or change properties that already exists

Dim oProps As SolidEdgeFramework.PropertySets = ocu.OccurrenceDocument.Properties
            With oProps.Item("Custom")
                .Add("Name", "Value)
                .Add("Name2", "Value2")
            End With
            oProps.Save()

'Finally save the asm.
objASM.Save()

 

Best regards

Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET

Re: Saving assembly components after modifying properties (ST5)

Thanks for the fast answers.

 

Yes, I also save the property sets after the editing.

 

I have not tried to save the main assembly from the API, but I do that manually in SE, with no success. Properties seem to retain their value until you close the assembly, but that value is lost when you open it again.

 

Tomorrow I will try that functionality directly from the API, but I guess it will work the same way...

 

Thanks again

 

Re: Saving assembly components after modifying properties (ST5)

The code you are talking about is that of the "ugly workaround" for the main problem, which consists in loading the properties externally, from their component path. This workaround works fine, but it's a mess inside my program, so I would prefer to avoid it!

Re: Saving assembly components after modifying properties (ST5)

[ Edited ]

Hector wrote:

Hi javigoca

 

Last mounth I had a similar issue.

 

What i had to do was to save the propertiset for each occurrence and finally save the assembly.

 

'ocu is the occurrence you're writing properties
'With the Add method you can add new properties or change properties that already exists

Dim oProps As SolidEdgeFramework.PropertySets = ocu.OccurrenceDocument.Properties
            With oProps.Item("Custom")
                .Add("Name", "Value)
                .Add("Name2", "Value2")
            End With
            oProps.Save()

'Finally save the asm.
objASM.Save()

 

Best regards


I have tried it and it didn't work, I just saved properties and property sets before, adding the assembly saving did not anything.

 

As always, properties get correctly modified or added, and you can check that in the property manager after my profram ends, but nothing is saved. In fact, assembly saving takes no time, whereas, when you edit properties in Property Manager for a big number of components, the next assembly saving can take minutes!

 

With all when you close and open again, the values are lost: If I had added a property, it doesn't exist anymore. If I changed its value, the old value is restored.

 

I just need to force SE to save all files after my program runs in order to preserve the edition, as it happens when you manually edit properties in the Property Manager, which makes SE save all files with changes. As I told before, if I enter in the Prop Manager, make a simple change in a property for all parts and then save the assembly, all components get saved, including the modifications done by my app. However, this is ugly and a real timewaste.

 

Would be great to be able to mark every component with edited properties as modified, so automatically SE saves it in the next assembly saving!

 

As a note: my program reads all SE document in the assembly, building a quite complex internal nodal structure for different purposes (currently more than 10000 lines of SE mess!) which keeps those SolidEdgeFrameWork.SolidEdgeDocument instances among other objects referenced inside the structure, for later access. Then, when I need to edit the properties, I simply travel along my previous loaded structure and modify those documents. Maybe this generates sharing conflicts or COM/Marshal problems. Until now, I have just "read" information, with no issues, but "writing" seems more headache-prone Most examples I have seen about this have a direct approach: get occurrence->get document->modify->save. I guess that SE API should allow what I'm doing and even more, but maybe...

 

Thanks for your interest guys, this is driving me mad!

 

Re: Saving assembly components after modifying properties (ST5)

Have you tried to set Dirty property in Occurrence.partDocument as true and then save the asm?

 

When you edit an occurrence this property changes to true.

Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET

Re: Saving assembly components after modifying properties (ST5)

Sure, but again, no success.

 

Just the main assembly with its properties is saved, since is the document really opened by SE.

 

Changing Dirty flag to all documents of its occurrences makes nothing, the children component are not saved when saving the father assembly.

 

Maybe I need to open in SE each component before modyfing properties and save, but this would be awesome slow.

 

I think that one common objective when programming the API is doing automated stuff on big assemblies, with all the parts or subassemblies involved, along all their properties, which are a main tool when organizative stuff is involved, so I'm sure there must be a quite logical and simple workaround for this! Property Manager saves all in front of my eyes every day!

 

Thanks anyway,I will keep you updated with my guessings (or lack of them!) 

Re: Saving assembly components after modifying properties (ST5)


Hector wrote:

Have you tried to set Dirty property in Occurrence.partDocument as true and then save the asm?

 

When you edit an occurrence this property changes to true.


I think that it's solved!

 

What I have done, is previous to change the Dirty flag, change the ReadOnly flag too, which I saw it was to true. So, more or less:

 

objDocument.ReadOnly = False
...
'Modify the properties here
...
objDocument.Dirty = True
...
objMainAssemblyDocument.Save()

With this, when I save the assembly, all the components under it are saved too. So I'm a bit happier now :-P

 

Overall, this looks a bit "unnecessarily-tricky"!

Solution
Solution
Accepted by topic author javigoca
‎08-26-2015 04:32 AM

Re: Saving assembly components after modifying properties (ST5)

Congrats.

 

I'm writing you at this moment.

 

I forgot to tell you to use the command MakeWritable in each occurrence. Sorry

Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
Development: VB.NET