Cancel
Showing results for 
Search instead for 
Did you mean: 

Open a SolidEdge propertyfile by VBA while it's open

Pioneer
Pioneer

Hello all, 

 

I'm french so, sorry for my bad english.

I work on SolidEdge ST6 and i have some problems to open a document property file while it's opened in solidedge. 

 

My aim is to copy the "document number" in the properties, but I can't execute my VBA program because it's opened.

 

I link my VBA program below and the file .bas, if anybody has an idea, i'm beginner in VBA... 

 

Thank you so much

 

---------------------------------------------------

 

Sub MAJ_DESIGNATION()


'Déclaration des variables

Application.ScreenUpdating = False
Dim objPropertySets As SolidEdgeFileProperties.PropertySets
Dim objProperties As SolidEdgeFileProperties.Properties
Dim objProperty As SolidEdgeFileProperties.Property
Dim objValue As Object
Dim I As Integer
Dim strRevision As String
Dim dossier As String
Dim fichier As String
Dim indice As String
Dim fichier2 As String
Dim fichier3 As String
dossier = ThisWorkbook.Path & "\"


For I = 6 To 505


Set objPropertySets = New SolidEdgeFileProperties.PropertySets
indice = Range("G" & I)
FichierIndice = Dir(dossier & Range("F" & I) & "*" & indice & ".dft")
complement = Mid(FichierIndice, 8, 6)

fichier = dossier & Range("F" & I) & complement & indice & ".psm"
fichier2 = dossier & Range("F" & I) & complement & indice & ".asm"
fichier3 = dossier & Range("F" & I) & complement & indice & ".par"


'BOUCLAGE DU CLASSEUR POUR LES NUMEROS QUI N'ONT PAS DE DESIGNATION


'DESIGNATION POUR LES PSM
If (Len(Dir(fichier)) > 0 And Range("B" & I) = "") Then

'DESIGNATION
Call objPropertySets.Open(fichier, False)
Set objProperties = objPropertySets.Item("ProjectInformation")
Set objProperty = objProperties.Item("Document Number")
strRevision = objProperty.Value
objPropertySets.Save
objPropertySets.Close
Range("B" & I) = UCase(strRevision)
Set objProperty = Nothing
Set objProperties = Nothing
Set objPropertySets = Nothing


End If

'DESIGNATION POUR LES ASSEMBLAGES
If (Len(Dir(fichier2)) > 0 And Range("B" & I) = "") Then

Call objPropertySets.Open(fichier2, False)
Set objProperties = objPropertySets.Item("ProjectInformation")
Set objProperty = objProperties.Item("Document Number")
strRevision = objProperty.Value
objPropertySets.Save
objPropertySets.Close
Range("B" & I) = UCase(strRevision)
Set objProperty = Nothing
Set objProperties = Nothing
Set objPropertySets = Nothing

End If


'DESIGNATION POUR LES PAR
If (Len(Dir(fichier3)) > 0 And Range("B" & I) = "") Then

Call objPropertySets.Open(fichier3, False)
Set objProperties = objPropertySets.Item("ProjectInformation")
Set objProperty = objProperties.Item("Document Number")
strRevision = objProperty.Value
objPropertySets.Save
objPropertySets.Close
Range("B" & I) = UCase(strRevision)
Set objProperty = Nothing
Set objProperties = Nothing
Set objPropertySets = Nothing

End If


Next

End Sub

15 REPLIES

Re: Open a SolidEdge propertyfile by VBA while it's open

Valued Contributor
Valued Contributor

Hi,

 

you should use

 

SolidEdgeFrameWork.PropertySets

SolidEdgeFrameWork.Properties

SolidEdgeFrameWork.Property

 

instead of SolidEdgeFileProperties.

Use SolidEdgeFileProperties when the document is closed (not opened in any application, such as DesignManager).

 

PS.: there is an especially API related forum here.

SE2019 MP3

Re: Open a SolidEdge propertyfile by VBA while it's open

Pioneer
Pioneer
Hi CsokaZ, thank you for your answer

Oh I didn't know, and how do I have to declare those variables?

Do you have an example using them?

Re: Open a SolidEdge propertyfile by VBA while it's open

Valued Contributor
Valued Contributor

SolidEdgeFileProperties and SolidEdgeFrameWork has same syntax, so you just have to change namespace.
Do you know this samples? They are good starting points.

SE2019 MP3

Re: Open a SolidEdge propertyfile by VBA while it's open

Pioneer
Pioneer

CsokaZ , 

 

I watched this samples already, but i'm not able to do the link with my project. 

 

I'm sorry for my incompétence... 

 

i changed by SolidEdgeFrameWork but nothing is happening

 

 


Application.ScreenUpdating = False
Dim objPropertySets As SolidEdgeFrameWork.propertySets
Dim objProperties As SolidEdgeFrameWork.Properties
Dim objProperty As SolidEdgeFrameWork.Property

Dim objValue As Object
Dim I As Integer
Dim strRevision As String
Dim dossier As String
Dim fichier As String
Dim indice As String
Dim fichier2 As String
Dim fichier3 As String
dossier = ThisWorkbook.Path & "\"


For I = 6 To 505

Set objPropertySets = New SolidEdgeFrameWork.propertySets
indice = Range("G" & I)
FichierIndice = Dir(dossier & Range("F" & I) & "*" & indice & ".dft")
complement = Mid(FichierIndice, 8, 6)

fichier = dossier & Range("F" & I) & complement & indice & ".psm"
fichier2 = dossier & Range("F" & I) & complement & indice & ".asm"
fichier3 = dossier & Range("F" & I) & complement & indice & ".par"


'BOUCLAGE DU CLASSEUR POUR LES NUMEROS QUI N'ONT PAS DE DESIGNATION


'DESIGNATION POUR LES PSM
If (Len(Dir(fichier)) > 0 And Range("B" & I) = "") Then

'DESIGNATION
Call objPropertySets.Open(fichier, False)
Set objProperties = objPropertySets.Item("ProjectInformation")
Set objProperty = objProperties.Item("Document Number")
strRevision = objProperty.Value
objPropertySets.Save
objPropertySets.Close
Range("B" & I) = UCase(strRevision)
Set objProperty = Nothing
Set objProperties = Nothing
Set objPropertySets = Nothing


End If

Re: Open a SolidEdge propertyfile by VBA while it's open

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

Hello @mc-laren

 

If the document is already open in Solid Edge, no need to create a reference to the SolidEdgeFileProperties

Dim objPropertySets As SolidEdgeFileProperties.PropertySets

   

You can access properties from the document directly.

See the case 1 (a) in this blog article which shows the subtle differences between the two.

The Solid Edge API is very inconsistent.

   

Regards,

Tushar

 

Re: Open a SolidEdge propertyfile by VBA while it's open

Valued Contributor
Valued Contributor

Hmm, so just almost the same...

@mc-laren sorry for misguidance.

SE2019 MP3

Re: Open a SolidEdge propertyfile by VBA while it's open

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

You were right @CsokaZ

Since the OP wanted an example, I pointed to the page.

Re: Open a SolidEdge propertyfile by VBA while it's open

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Your code looks good to me, you can use the SolidEdgeFileProperties API to access the file properties.

The only thing you should change is the way you open it.

As you only access some property to read it, without changing properties in the document, you should open the properties READ_ONLY:

Call objPropertySets.Open(fichier, True)

And then, of course, do not call "objPropertySets.Save", but simply close it.

 

This way, there should be no problem to access a document, which is already open.

 

EDIT: You should ask this type of question in the Solid Edge Developer Forum!

Re: Open a SolidEdge propertyfile by VBA while it's open

Pioneer
Pioneer

Hi sorry for my late reply, 

 

I can only answer when i'm at work ... 

 

I tried it but it doesn't there isn't any error, the program can be executed but nothing is happen.. 

 

Regards, 

 

Mac-Laren