Reply

File properties will be locked in the ST7 opened Family of Assembly after reading they with API

Hi,


I wrote an windows form application many years ago to Solid Edge v20 and ST2 to read and write the file properties in opened SE model. This worked well, but now in ST7 the file properties will be locked if I use on an opened Family of Assembly. I can one time read, or read and modify the file properties and save my model, but after that I must close my model and Solid Edge when I want to use my application second time. This happened with Insight and without Insight too.


Here is the part of my Windows Form Application (without most commands of form objects). The names of the file properties are in Hungarian language, those can be translated to try:

 

Imports System.Runtime.InteropServices
Imports SolidEdgeConstants
Imports SolidEdgeFramework.DocumentTypeConstants
Imports SolidEdgeFramework.DocumentStatus
Imports System
Imports System.IO

Public Class Form1
Private objApp As SolidEdgeFramework.Application = Nothing
Dim objDoc As SolidEdgeFramework.SolidEdgeDocument = Nothing
Dim objAsm As SolidEdgeAssembly.AssemblyDocument = Nothing
Dim objAsmMember As SolidEdgeAssembly.AssemblyFamilyMember = Nothing

Dim objPropertySets() As SolidEdgeFramework.PropertySets = Nothing
Dim objProperties As SolidEdgeFramework.Properties = Nothing
Dim objProperty As SolidEdgeFramework.Property = Nothing
Public k As Integer
Public aProp(,) As String
Dim maxProp As Integer = 22
Public sMemberName As String
Public nMember As Integer = 0
Dim sMaterial As String
Dim lAsm As Boolean = False
Dim lParPsm As Boolean = False
Dim lDft As Boolean = False
Dim lFamily As Boolean = False
Public lModified As Boolean = False
Dim lVevoAdd As Boolean = True


Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

If Not (objProperty Is Nothing) Then
Marshal.ReleaseComObject(objProperty)
objProperty = Nothing
End If

If Not (objProperties Is Nothing) Then
Marshal.ReleaseComObject(objProperties)
objProperties = Nothing
End If

For i = 0 To nMember
If Not (objPropertySets(i) Is Nothing) Then
Marshal.ReleaseComObject(objPropertySets(i))
objPropertySets(i) = Nothing
End If
Next

If Not (objAsmMember Is Nothing) Then
Marshal.ReleaseComObject(objAsmMember)
objAsmMember = Nothing
End If

If Not (objAsm Is Nothing) Then
Marshal.ReleaseComObject(objAsm)
objAsm = Nothing
End If

If Not (objDoc Is Nothing) Then
'objDoc.Close()
Marshal.ReleaseComObject(objDoc)
objDoc = Nothing
End If

If Not (objApp Is Nothing) Then
'objApp.Quit()
Marshal.ReleaseComObject(objApp)
objApp = Nothing
End If

Try
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
Catch ex As Exception

End Try
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
Try
' Connect to a running instance of Solid Edge
objApp = Marshal.GetActiveObject("SolidEdge.Application")

' Get a reference to the active document
objDoc = objApp.ActiveDocument

' Using Type property, determine document type
Select Case objDoc.Type
Case igAssemblyDocument
lAsm = True
Console.WriteLine("Assembly Document")
Case igSyncAssemblyDocument
lAsm = True
Console.WriteLine("SyncAssembly Document")
Case igDraftDocument
lDft = True
Console.WriteLine("Draft Document")
Case igPartDocument
lParPsm = True
Console.WriteLine("Part Document")
Case igSyncPartDocument
lParPsm = True
Console.WriteLine("SyncPart Document")
Case igSheetMetalDocument
lParPsm = True
Console.WriteLine("SheetMetal Document")
Case igSyncSheetMetalDocument
lParPsm = True
Console.WriteLine("SyncSheetMetal Document")
Case igUnknownDocument
Console.WriteLine("Unknown Document")
End Select

Catch ex As Exception
' Write any errors to console.
Console.WriteLine(ex.Message)
Me.Close()
Exit Sub
End Try

If Not (lAsm Or lParPsm Or lDft) Then
Me.Close()
Exit Sub
End If

If lAsm Then

objAsm = objDoc
If objAsm.IsFileFamilyByDocument Then

lFamily = True
nMember = objAsm.AssemblyFamilyMembers.Count
ReDim aProp(nMember, maxProp)
ReDim objPropertySets(nMember)

ActiveMemberFind()

For Me.k = 1 To nMember
objAsmMember = objAsm.AssemblyFamilyMembers.Item(k)
If sMemberName = objAsm.AssemblyFamilyMembers.Item(k).MemberName Then
Console.WriteLine("Activ Familymember is " & Me.k & ".." & sMemberName)
End If
Try
objPropertySets(k) = objAsmMember.Properties 'after this line in a family of assembly the file properties are always locked in ST7
Catch ex As Exception When Err.Number = 70
Console.WriteLine("The file properties are locked.")
Me.Close()
Exit Sub
Catch ex As Exception When Err.Number = 53
Console.WriteLine("The Family of Assembly must be saved first.")
Me.Close()
Exit Sub
End Try
PropertyRead(k, aProp)
Next

End If
End If

If (Not (lAsm And lFamily) And Not (lDft)) Or lParPsm Then

k = 0
ReDim aProp(k, maxProp)
ReDim objPropertySets(k)
Try
objPropertySets(k) = objDoc.Properties
Catch ex As Exception When Err.Number = 70
Console.WriteLine("The file properties are locked.")
Me.Close()
Exit Sub
End Try
PropertyRead(k, aProp)

End If
If lDft Then

k = 0
ReDim aProp(k, maxProp)
ReDim objPropertySets(k)
Try
objPropertySets(k) = objDoc.Properties
Catch ex As Exception When Err.Number = 70
Console.WriteLine("The file properties are locked.")
Me.Close()
Exit Sub
End Try
PropertyRead_Dft(k, aProp)

End If

End Sub


Sub TryOnePropRead(ByVal sPropName As String, ByVal aProp(,) As String, ByVal i As Integer)

aProp(k, i) = ""
Try
objProperty = objProperties.Item(sPropName)
aProp(k, i) = objProperty.Value
Catch ex As Exception When Err.Number = 9
Try
objProperty = objProperties.Add(sPropName, "")
Catch ex1 As Exception When Err.Number = 5
Console.WriteLine("The property '" & sPropName & "' is missing in family member '" & objAsm.AssemblyFamilyMembers.Item(k).MemberName & vbCrLf & "'.")
End Try
End Try
Console.WriteLine("Property(" & k & "," & i & ")=" & aProp(k, i))

End Sub

Sub PropertyRead(ByVal k As Integer, ByVal aProp(,) As String)

objProperties = objPropertySets(k).Item("ProjectInformation")
TryOnePropRead("Document Number", aProp, 1)

objProperties = objPropertySets(k).Item("Custom")
TryOnePropRead("Rajzszam aj.", aProp, 2)
TryOnePropRead("Termekszam", aProp, 3)
TryOnePropRead("Megnevezes 2", aProp, 5)
TryOnePropRead("Megnevezes 3", aProp, 6)
TryOnePropRead("Megnevezes 4", aProp, 7)
TryOnePropRead("Megnevezes 2a", aProp, 8)
TryOnePropRead("Megnevezes 4a", aProp, 9)

TryOnePropRead("Anyag 1", aProp, 12)
TryOnePropRead("Anyag 2", aProp, 13)
TryOnePropRead("Anyag 3", aProp, 14)
TryOnePropRead("Anyag 4", aProp, 15)

Try
aProp(k, 11) = ""
objProperty = objProperties.Item("Vevo")
aProp(k, 11) = objProperty.Value
Catch ex As Exception When Err.Number = 9
If lVevoAdd Then
objProperty = objProperties.Add("Vevo", "")
End If
End Try

objProperties = objPropertySets(k).Item("SummaryInformation")
TryOnePropRead("Megnevezés", aProp, 4)
TryOnePropRead("Tervező", aProp, 10)

If lParPsm Then
objProperties = objPropertySets(k).Item("MechanicalModeling")
objProperty = objProperties.Item("Material")
sMaterial = objProperty.Value
If sMaterial <> aProp(k, 12) _
And objDoc.Status <> igStatusReleased And objDoc.Status <> igStatusObsolete Then
aProp(k, 12) = sMaterial
objProperties = objPropertySets(k).Item("Custom")
objProperty = objProperties.Item("Anyag 1")
objProperty.Value = aProp(k, 12)
End If
End If

End Sub

Sub PropertyRead_Dft(ByVal k As Integer, ByVal aProp(,) As String)

objProperties = objPropertySets(k).Item("ProjectInformation")
TryOnePropRead("Document Number", aProp, 1)

objProperties = objPropertySets(k).Item("Custom")
TryOnePropRead("Termekszam", aProp, 3)

TryOnePropRead("Info 1.", aProp, 16)
TryOnePropRead("Info 2.", aProp, 17)
TryOnePropRead("Info 3.", aProp, 18)
TryOnePropRead("Info 4.", aProp, 19)

TryOnePropRead("Meretarany", aProp, 20)
TryOnePropRead("Helyettesito rajz", aProp, 21)
TryOnePropRead("Helyettesitett rajz", aProp, 22)

Try
objProperty = objProperties.Item("Vevo")
Catch ex As Exception When Err.Number = 9
If lVevoAdd Then
objProperty = objProperties.Add("Vevo", "")
End If
End Try
aProp(k, 11) = objProperty.Value

objProperties = objPropertySets(k).Item("SummaryInformation")
TryOnePropRead("Megnevezés", aProp, 4)
TryOnePropRead("Tervező", aProp, 10)

End Sub

Sub PropertyWrite(ByVal k As Integer, ByVal aProp(,) As String)

objProperties = objPropertySets(k).Item("ProjectInformation")
objProperty = objProperties.Item("Document Number")
objProperty.Value = aProp(k, 1)

objProperties = objPropertySets(k).Item("Custom")
objProperty = objProperties.Item("Rajzszam aj.")
objProperty.Value = aProp(k, 2)
objProperty = objProperties.Item("Termekszam")
objProperty.Value = aProp(k, 3)
objProperty = objProperties.Item("Megnevezes 2")
objProperty.Value = aProp(k, 5)
objProperty = objProperties.Item("Megnevezes 3")
objProperty.Value = aProp(k, 6)
objProperty = objProperties.Item("Megnevezes 4")
objProperty.Value = aProp(k, 7)
objProperty = objProperties.Item("Megnevezes 2a")
objProperty.Value = aProp(k, 8)
objProperty = objProperties.Item("Megnevezes 4a")
objProperty.Value = aProp(k, 9)

If lAsm Then
objProperty = objProperties.Item("Anyag 1")
objProperty.Value = aProp(k, 12)
End If
objProperty = objProperties.Item("Anyag 2")
objProperty.Value = aProp(k, 13)
objProperty = objProperties.Item("Anyag 3")
objProperty.Value = aProp(k, 14)
objProperty = objProperties.Item("Anyag 4")
objProperty.Value = aProp(k, 15)

If lVevoAdd Then
objProperty = objProperties.Item("Vevo")
objProperty.Value = aProp(k, 11)
End If

objProperties = objPropertySets(k).Item("SummaryInformation")
Try
objProperty = objProperties.Item("Megnevezés")
objProperty.Value = aProp(k, 4)
Catch ex As Exception
End Try
Try
objProperty = objProperties.Item("Tervező")
objProperty.Value = aProp(k, 10)
Catch ex As Exception
End Try

End Sub

Sub PropertyWrite_Dft(ByVal k As Integer, ByVal aProp(,) As String)

objProperties = objPropertySets(k).Item("ProjectInformation")
objProperty = objProperties.Item("Document Number")
objProperty.Value = aProp(k, 1)

objProperties = objPropertySets(k).Item("Custom")
objProperty = objProperties.Item("Termekszam")
objProperty.Value = aProp(k, 3)

objProperty = objProperties.Item("Info 1.")
objProperty.Value = aProp(k, 16)
objProperty = objProperties.Item("Info 2.")
objProperty.Value = aProp(k, 17)
objProperty = objProperties.Item("Info 3.")
objProperty.Value = aProp(k, 18)
objProperty = objProperties.Item("Info 4.")
objProperty.Value = aProp(k, 19)

objProperty = objProperties.Item("Meretarany")
objProperty.Value = aProp(k, 20)
objProperty = objProperties.Item("Helyettesito rajz")
objProperty.Value = aProp(k, 21)
objProperty = objProperties.Item("Helyettesitett rajz")
objProperty.Value = aProp(k, 22)

objProperty = objProperties.Item("Vevo")
objProperty.Value = aProp(k, 11)

objProperties = objPropertySets(k).Item("SummaryInformation")
Try
objProperty = objProperties.Item("Megnevezés")
objProperty.Value = aProp(k, 4)
Catch ex As Exception
End Try
Try
objProperty = objProperties.Item("Tervező")
objProperty.Value = aProp(k, 10)
Catch ex As Exception
End Try

End Sub


Sub ActiveMemberFind()
Dim sFilename As String
Dim i As Integer
sFilename = Trim(objApp.ActiveWindow.Caption)
sMemberName = vbNullString
i = InStrRev(sFilename, "!", -1, vbTextCompare)
sMemberName = Mid(sFilename, i + 1) ' isolate member

'Csak olvasható = Read only. Next two line must be modified to current language.
'This text is in the name of the Solid Edge windows, see Console.WriteLine(objApp.ActiveWindow.Caption)
If Strings.Right(sMemberName, 16) = "][Csak olvasható" Then
sMemberName = Strings.Left(sMemberName, Len(sMemberName) - 16)
End If
'Console.WriteLine("ActiveMember: " + sMemberName)
'Console.WriteLine()

End Sub

Sub PropertySave()
'Console.WriteLine(objAsm.Status.ToString)
If objDoc.Status = igStatusReleased Or objDoc.Status = igStatusObsolete Then
Exit Sub
End If
If lAsm Then
If lFamily Then
For Me.k = 1 To nMember
objAsmMember = objAsm.AssemblyFamilyMembers.Item(k)
PropertyWrite(k, aProp)
objPropertySets(k).Save() 'Not needed in SE v20 and ST2
Next
Else
PropertyWrite(k, aProp)
objPropertySets(k).Save() 'Not needed in SE v20 and ST2
End If
End If
If lParPsm Then
PropertyWrite(k, aProp)
objPropertySets(k).Save() 'Not needed in SE v20 and ST2
End If
If lDft Then
PropertyWrite_Dft(k, aProp)
objPropertySets(k).Save() 'Not needed in SE v20 and ST2
End If

End Sub

Private Sub Button_Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button_Cancel.Click
Me.Close()
End Sub

Private Sub Button_OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_OK.Click
PropertySave()
Me.Close()
End Sub

End Class

 

After "objPropertySets(k) = objAsmMember.Properties" line the file properties (without the active family member) will be locked (0x80030005 (STG_E_ACCESSDENIED)) even if I close the application with releasing object variables.


Can someone help me, how can I solve the problem? This happened in ST8 too?


Best regards,


Peter Kaderasz

1 REPLY

Re: File properties will be locked in the ST7 opened Family of Assembly after reading they with API

Hi,

 

here is some more info.

 

When I want to delete all files from my local cache after reading file properties with my application from a family of assembly, Solid Edge send an error message that this asm file can't be deleted, because it's still open in Solid Edge (but I closed it previously). After closing and newly opening Solid Edge this asm file can be deleted too.

 

Best regards,

 

Peter Kaderasz