Reply

Virtual basics and properties

Hi dears,

 

I'm french so I apologize for my written english ..

I have a problem with my vba program. I found parts on the web and tried to do something with it.

My aim is to get the properties of each draft (Project name principally) and write it in my excel. Because for now we have to write it twice.

I succeed because it works, my vba open each plan and get the name of the draft but then i have a problem.

When I open a draft which has already been opened by my program, i have some save problems. When i close a draft SolidEdge dont answer me to save. And sometimes even I save, there is nothing happening. I write you a little part of my code, I hope you could help.

Thank you in advance Smiley Happy !

 

Sub MAJ_DESIGNATION()


    'Déclaration des variables
   
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect
    Dim objApplication As SolidEdgeFramework.Application
    Dim objPSMDocument As SolidEdgePart.SheetMetalDocument
    Dim objASMDocument As SolidEdgeAssembly.AssemblyDocument
    Dim objPARDocument As SolidEdgePart.PartDocument
    Dim objPropertySets As SolidEdgeFramework.PropertySets
    Dim objProperties As SolidEdgeFramework.Properties
    Dim objProperty As SolidEdgeFramework.Property
    Dim objModelLinks As SolidEdgeDraft.ModelLinks
    Dim objModelLink As SolidEdgeDraft.ModelLink
    Dim objApp As Object
    Dim objDocs As Object
    Dim objDoc 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
    Set objApp = GetObject(, "SolidEdge.Application")
    Set objDocs = objApp.Documents
   
       
    For i = 6 To 505
   
        indice = "A"
        indice = Range("G" & i)
        fichier = dossier & "\" & Range("F" & i) & "-0001-" & indice & ".psm"
        fichier2 = dossier & "\" & Range("F" & i) & "-0001-" & indice & ".asm"
        fichier3 = dossier & "\" & Range("F" & i) & "-0001-" & indice & ".par"
        fichier4 = dossier & "\" & Range("F" & i) & "-0000-" & indice & ".par"
        fichier5 = dossier & "\" & Range("F" & i) & "-0000-" & indice & ".asm"
   
   
       
        'BOUCLAGE DU CLASSEUR POUR LES NUMEROS QUI N'ONT PAS DE DESIGNATION
        If Range("B" & i) = "" Then
       
            'DESIGNATION POUR LES SHEETMETAL
            If Len(Dir(fichier)) > 0 Then
               
                Set objDoc = objDocs.Open(fichier)
                objApp.DisplayAlerts = False
                Set objApplication = GetObject(, "SolidEdge.Application")
                Set objPSMDocument = objApplication.ActiveDocument
                Set objPropertySets = objPSMDocument.Properties
                Set objProperties = objPropertySets.Item("ProjectInformation")
                Set objProperty = objProperties.Item("Document number")
                strRevision = objProperty.Value
               
               
                Range("B" & i) = UCase(strRevision)
                Call objDoc.Close(savechanges:=True)
               
               
              End If
             
            'DESIGNATION POUR LES PAR
            If Len(Dir(fichier3)) > 0 Then
               
                Set objDoc = objDocs.Open(fichier3)
                objApp.DisplayAlerts = False
                Set objApplication = GetObject(, "SolidEdge.Application")
                Set objPARDocument = objApplication.ActiveDocument
                Set objPropertySets = objPARDocument.Properties
                Set objProperties = objPropertySets.Item("ProjectInformation")
                Set objProperty = objProperties.Item("Document number")
                strRevision = objProperty.Value
               
                Range("B" & i) = UCase(strRevision)
                Call objDoc.Close(savechanges:=True)
               
              End If
             
              'DESIGNATION POUR LES ASSEMBLAGES
              If Len(Dir(fichier2)) > 0 Then
               
                Set objDoc = objDocs.Open(fichier2)
                objApp.DisplayAlerts = False
                Set objApplication = GetObject(, "SolidEdge.Application")
                Set objASMDocument = objApplication.ActiveDocument
                Set objPropertySets = objASMDocument.Properties
                Set objProperties = objPropertySets.Item("ProjectInformation")
                Set objProperty = objProperties.Item("Document number")
                strRevision = objProperty.Value
               
                Range("B" & i) = UCase(strRevision)
                Call objDoc.Close(savechanges:=True)
               
              End If
             
              'DESIGNATION POUR LES PAR EN 0000
              If Len(Dir(fichier4)) > 0 Then
               
                Set objDoc = objDocs.Open(fichier4)
                objApp.DisplayAlerts = False
                Set objApplication = GetObject(, "SolidEdge.Application")
                Set objPARDocument = objApplication.ActiveDocument
                Set objPropertySets = objPARDocument.Properties
                Set objProperties = objPropertySets.Item("ProjectInformation")
                Set objProperty = objProperties.Item("Document number")
                strRevision = objProperty.Value
               
                Range("B" & i) = UCase(strRevision)
                Call objDoc.Close(savechanges:=True)
               
              End If
             
              'DESIGNATION POUR LES ASSEMBLAGES EN 0000
              If Len(Dir(fichier5)) > 0 Then
               
                Set objDoc = objDocs.Open(fichier5)
                objApp.DisplayAlerts = False
                Set objApplication = GetObject(, "SolidEdge.Application")
                Set objASMDocument = objApplication.ActiveDocument
                Set objPropertySets = objASMDocument.Properties
                Set objProperties = objPropertySets.Item("ProjectInformation")
                Set objProperty = objProperties.Item("Document number")
                strRevision = objProperty.Value
               
                Range("B" & i) = UCase(strRevision)
               
                Call objDoc.Close(savechanges:=True)
               
                End If
               
            End If
           
           
    Next
   
    ActiveSheet.Protect

End Sub

 

8 REPLIES

Betreff: Virtual basics and properties

Hi @mc-laren

 

 

 

first of all I think Your question will be better positioned at the Programmers forum rather than here in a overall section.

 

And regarding Your programmers question I think there should be a way to only use the properties than opening the part/draft itself.

I believbe that there is a "Solid Edge File Properties Object Library" to involve here.

 

This will allow You to get directly to the properties of the file

 

 



regards
Wolfgang

Betreff: Virtual basics and properties

Hi @mc-laren

 

 

 

 

I just found an older code where I also used this:

 

 

Dim objSEProps As SolidEdgeFileProperties.PropertySets ' for FileProperties ONLY

 

Set objSEProps = CreateObject("SolidEdge.FileProperties")
If Err.Number <> 0 Then
MsgBox "Unable to start the 'Solid Edge File Properties': " & Err.Description
Exit Sub
End If

 

...

 

This gives You the access to the file properties

 

 



regards
Wolfgang

Betreff: Virtual basics and properties

Hi @hawcad,

 

Yeah sorry for the my post position ..

 

If it's real, it could be perfect so. Could you tell me how i can do it  ?

Maybe a link ?

Because in france, I didn't find anybody speaking about that..

 

Thank you !


Regards,

Vincent

Betreff: Virtual basics and properties

Do you know how can I reach my document number ?

Regards,

Betreff: Virtual basics and properties

Hi @mc-laren

 

 

 

Document Number is property:

 

objProps.Group(5).Item(1) or  Group("ProjectInformation").Item("Document Number").Value

 

 

 



regards
Wolfgang

Betreff: Virtual basics and properties

Hi @mc-laren

 

 

 

best source for such info always is 

  1. Programmers Manual/Tutorial from Solid Edge Help PathFinder
  2. if oOu have opened the VB coe with the Solid Edge API calls I normally use the F2 the Object Catalog to see what is possibel
  3. The links from the Solid Edge Programming Forum
  4. Jason Newell homepage
  5. Tushars Programmers Pages

 

I think the links are to be found in the Programmers Forum

 

 



regards
Wolfgang

Re: Virtual basics and properties

Hi @mc-laren

 

@hawcad has already provided you a direct answer.

 

For general information, File Properties can be accessed in many ways:

1. When the document IS open in Solid Edge.

2. When both the document and Solid Edge are NOT open.

 

Accordingly, below are the code snippets:

  

1. When the document is open in Solid Edge:

 

Dim objApp As SolidEdgeFramework.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("SolidEdge.Application")
Dim objPropSets As SolidEdgeFramework.PropertySets = Nothing
Dim objProp As SolidEdgeFramework.Property = Nothing
Dim objProps As SolidEdgeFramework.Properties = Nothing
Dim objDocument As SolidEdgeFramework.SolidEdgeDocument = Nothing

objDocument = objApp.ActiveDocument

objPropSets = objDocument.Properties

For Each objProps In objPropSets
    If objProps.Name = "ProjectInformation" Then
        For Each objProp In objProps
            If objProp.Name = "Document Number" Then
                objProp.Value = "Document"
            End If
        Next
    End If
Next

 

Alternatively, if you want to use the SolidEdgeFileProperties reference, then a document need not be open in Solid Edge, nor Solid Edge be running.

Change the file properties directly like this:

 

Dim objPropSets As SolidEdgeFileProperties.PropertySets = New SolidEdgeFileProperties.PropertySets
Dim objProp As SolidEdgeFileProperties.Property = Nothing
Dim objProps As SolidEdgeFileProperties.Properties = Nothing

Dim sDocument As String = "C:\Temp\Testfile.par"

objPropSets.Open(sDocument, False)

For Each objProps In objPropSets
    If objProps.Name = "ProjectInformation" Then
        For Each objProp In objProps
            If objProp.Name = "Document Number" Then
                objProp.Value = "Document"
            End If
        Next
    End If
Next
objPropSets.Save() objPropSets.Close()

 

Hope you find this useful.

 

~Tushar Suradkar

Solid Edge Users Facebook Group

[ Everything under the sun about - Solid Edge ]

Re: Virtual basics and properties

This will also be very useful -

 

SOLID EDGE VB.NET PROGRAMMERS GUIDE

HP Z420 16GB RAM
Quadro K4000
ST7 MP10 on Windows 7 Pro 64.