Cancel
Showing results for 
Search instead for 
Did you mean: 

SE2019 Properties via VB.net in WIN10

Creator
Creator

 

Hello everyone,

 

I'm not a high level programmer. I've tried to make sense of all the various posting on the subject of changes made in SEvST10 in accessing SE Properties.  I've tried all of the suggestions with no success. My current macro allows the user to fill in several text boxes on a windows form and populate them as custom properties in the active SE document.

Works perfectly with SEvST8.

 

partial code snippet:

Public objApp As SolidEdgeFramework.Application = Nothing

Public objSEPart As SolidEdgePart.PartDocument = Nothing

Public objSESheetMetal As SolidEdgePart.SheetMetalDocument = Nothing

Public objSEAssy As SolidEdgeAssembly.AssemblyDocument = Nothing

Public objSelectSet As SolidEdgeFramework.SelectSet = Nothing

Public objPropertySets As SolidEdgeFramework.PropertySets = Nothing

Public objProperties As SolidEdgeFramework.Properties = Nothing

Public objProperty As SolidEdgeFramework.Property = Nothing

 

Public Sub PHDModelProperties_Load(sender As Object, e As EventArgs) Handles MyBase.Load

 

objApp = GetObject(, "SolidEdge.Application")

objSEPart = objApp.ActiveDocument

objPropertySets = objSEPart.Properties

strFilename.Text = objSEPart.Name

 

'**** CUSTOM TAB

objProperties = objPropertySets.Item("Custom")

objProperty = objProperties.Item("SimilarTo")

txtSimTo.Text = objProperty.Value

 

Code fails when setting objPropertySets = objSEPart.Properties...  It equals "Nothing"

I know Revision Manager has changed to Design Manager and PropAuto.dll has changed.

Everything I find on-line is set to writing properties to a new PropertySet.

Any help would be greatly appreciated.

 

Mark

15 REPLIES 15

Re: SE2019 Properties via VB.net in WIN10

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

@mspencer,

 

you should avoid working with Option Strict Off  and stop counting on implicit type conversions and late binding.

Let all of your VB-Code files start with the line Option Strict On

 

To get your code compiled, you have then to cast your returned object types on your own where necessary.

 

I.e. change your code from:

 

objApp = GetObject(, "SolidEdge.Application")
objSEPart = objApp.ActiveDocument
objPropertySets = objSEPart.Properties
...

to:

objApp = CType(GetObject(, "SolidEdge.Application"), SolidEdgeFramework.Application)
objSEPart = CType(objApp.ActiveDocument, SolidEdgePart.PartDocument)
objPropertySets = CType(objSEPart.Properties, SolidEdgeFramework.PropertySets)
...

Of course also ensure the active document to be really a part document.

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de

Re: SE2019 Properties via VB.net in WIN10

Gears Phenom Gears Phenom
Gears Phenom

Wolfgang,  @wku    Can you add a bit more detail to this, please.    I see what you have done in the example above and understand at a basic level type conversions...  but I have always only set my objects as shown here. 

objApp = GetObject(, "SolidEdge.Application")
objSEPart = objApp.ActiveDocument
objPropertySets = objSEPart.Properties
...

What are the issues, complications, pros/cons?

TIA!

Matt Johnson
Solid Edge Certified Professional
Solid Edge 2019 (SEEC) - Production
NX12 (Tc Integration)
Teamcenter 10.1.7
Highlighted

Re: SE2019 Properties via VB.net in WIN10

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Hi Matt (@Johnson_BigMatt),

 

the pros are

  • type safe programming (which is also good coding practice)
  • intelligence in Visual Studio in the program editor providing a list of available properties/methods when entering the dot char after an object variable to choose from.
  • early binding which gives compared to late binding the pros of enabling the compiler to detect formal errors at compile time versus at runtime.

The cons are

  • Some rare cases might be more comfortably to solve when using late binding

I'm convinced that the problems of the original poster get solved by using strict typing set on.

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de

Re: SE2019 Properties via VB.net in WIN10

Creator
Creator

VB Code Ref.png

 

Hi Wolfgang, 

I followed your suggestion.  This code is an older existing code that was working so I didn't spend a lot of time cleaning it up.  Stripped out a lot of excess for sharing with the forum.  I've also included a screenshot of the references and I'm still getting a failure setting the PropertySets.  I read that Seimens changed the SolidEdgeProperties in SEvST10 or SE2019.  Could that be what is causing the inability to get them? 

 

Option Strict On  
Option Explicit On
Imports Microsoft.VisualBasic.FileIO
Imports System.IO
Imports System.Runtime.InteropServices

Public Class PHDModelProperties
    Public objApp As SolidEdgeFramework.Application = Nothing
    Public objSEPart As SolidEdgePart.PartDocument = Nothing
    Public objSESheetMetal As SolidEdgePart.SheetMetalDocument = Nothing
    Public objSEAssy As SolidEdgeAssembly.AssemblyDocument = Nothing
    Public objSelectSet As SolidEdgeFramework.SelectSet = Nothing
    Public objPropertySets As SolidEdgeFramework.PropertySets = Nothing
    Public objProperties As SolidEdgeFramework.Properties = Nothing
    Public objProperty As SolidEdgeFramework.Property = Nothing
    Public SqlConn As New SqlConnection
    Public strPropVal As String = ""
    Public OleMessageFilter As Object
    Dim strPartNo As String = ""
    Dim strPartName As String = ""
    Dim strPartFileName As String = ""
    Dim strPartTitle As String = ""
    Dim strPartSubject As String = ""
    Dim strPartAuthor As String = ""
    Dim strPartManager As String = ""
    Dim strPartCompany As String = ""
    Dim strPartHeatTreat As String = ""
    Dim strPartFinish As String = ""
    Dim strPathName As String = ""  
    Dim strMessage As String = ""   
    Dim bClearedFields As Boolean = False
    Dim q As Integer
    Dim r As Integer
    Dim s As Integer
    Dim I As Integer
    Dim J As Integer
    Dim K As Integer
    Dim nChars As Integer
    Dim Strlen As Long
    Dim CharPos As Long
    Dim NewLen As Long
    Dim blnRetry As Boolean
    Dim blnPart As Boolean   
    Dim blnChecked As Boolean
    Dim strFilename As String = ""


    Public Sub PHDModelProperties_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        LblVersion.Text = "Ver: 19.165"

        ''Connect to running instance of Solid Edge.
        Try
            objApp = CType(GetObject(, "SolidEdge.Application"), SolidEdgeFramework.Application)
            blnRetry = False
        Catch ex As Exception
            blnRetry = True
            MsgBox("Solid Edge must be open to run this macro.", CType(MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, MsgBoxStyle), "Populate Properties")
            End
        End Try


        Try
            'Check to see if part file
            Try
                objSEPart = CType(objApp.ActiveDocument, SolidEdgePart.PartDocument)

                objPropertySets = CType(objSEPart.Properties, SolidEdgeFramework.PropertySets)  ****'FAILS
                blnRetry = False
                blnPart = True
                strFilename = objSEPart.Name
                lblSEFileName.Text = strFilename
            Catch ex As Exception
                blnRetry = True
            End Try

          

        Catch
            blnRetry = True
        End Try


        If blnRetry = True Then
            MsgBox("Solid Edge active window must be in Part, Assembly or Sheet Metal environment to run this macro.", CType(MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, MsgBoxStyle), "Populate Properties")
            End
        End If

        PopulateGenericTitles()
        PopulateFinishESM()
        PopulateHTesm()


        '**** PROJECT TAB
        'Get "DocumentNumber" property from currently open Solid Edge Part file
        objProperties = objPropertySets.Item("ProjectInformation")
        objProperty = objProperties.Item("Document Number")
        'If objProperty.Value = "" Then
        q = Len(strFilename) - 4
        strDocNo = Microsoft.VisualBasic.Left(strFilename, q)
        lblDocNo.Text = strDocNo
        s = Len(lblDocNo.Text)
        r = Microsoft.VisualBasic.InStr(lblDocNo.Text, "-")
        If r > 0 Then
            txtBaseNo.Text = Microsoft.VisualBasic.Left(lblDocNo.Text, r - 1)
            txtDashNo.Text = Microsoft.VisualBasic.Right(lblDocNo.Text, s - (r - 1))
        ElseIf r = 0 Then
            txtBaseNo.Text = lblDocNo.Text
            txtDashNo.Text = ""
        End If
        'End If

        'Get "Revision" property from currently open Solid Edge Part file
        objProperty = objProperties.Item("Revision")
        TxtRev.Text = CType(objProperty.Value, String)     


        '**** CUSTOM TAB
        objProperties = objPropertySets.Item("Custom")      

        'Get "Finish" property from currently open Solid Edge Part file
        If blnAssy = False Then
            Try
                objProperty = objProperties.Item("Finish/Plating")
                'CboFinish.Text = objProperty.Value
                Label7.Text = CType(objProperty.Value, String)
            Catch ex As Exception
                CboFinish.Text = ""
            End Try
        End If

End Sub

End Class

 

 

 

Re: SE2019 Properties via VB.net in WIN10

Siemens Phenom Siemens Phenom
Siemens Phenom

From the ST10 readme file:

 

<--

32-bit versions of SEInstallData.dll and PropAuto.dll no longer installed with Solid Edge

The SEInstallData.dll and PropAuto.dll libraries provide functions programmers can use to evaluate the current Solid Edge installation on a computer and properties of Solid Edge files. In previous versions of Solid Edge, 64-bit versions of these libraries were delivered in the Program folder and registered and 32-bit versions of these libraries were installed in the Solid Edge Program\Win32 folder, where users could register them to make the functions within them accessible to external programs. The 32-bit versions of these libraries are no longer installed with Solid Edge. The 64-bit versions of the libraries continues to be installed and registered in the Solid Edge 2019\Program folder. Existing programs, compiled for 32-bit processors, can be recompiled with the Target CPU set to x64 or Any CPU in order to access the 64-bit versions of the libraries.

-->

 

You will either need to update your code to run 64-bit or install the 32-bit ST10 View & Markup software package.

Re: SE2019 Properties via VB.net in WIN10

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Hi Mark (@mspencer),

 

in your code above I'm missing the reference to Solid Edge Part Type Library!? It's just referencing the Solid Edge Assembly Type Library. This can't be correct, if you want explicitely access SolidEdgePart.Partdocument. Can you check this? (But if the reference is really missing then you shouldn't be able to get the code compiled).

 

From what I see it might also be better to work with the more generic SolidEdgeDocument object, when accessing the ActiceDocument and allowing it to be of type AssemblyDocument, PartDocument or SheetMetalDocument.

 

I assume your code fails, because objSEPart is Nothing!

 

Former answer before EDIT:

 

Can you try the example below taken from the Solid Edge 2019 API help for PartDocument.Properties:

 

Option Infer On

Imports System
Imports System.Runtime.InteropServices

Namespace Examples
    Friend Class Program
        <STAThread>
        Shared Sub Main(ByVal args() As String)
            Dim application As SolidEdgeFramework.Application = Nothing
            Dim partDocument As SolidEdgePart.PartDocument = Nothing

            Try
                ' See "Handling 'Application is Busy' and 'Call was Rejected By Callee' errors" topic.
                OleMessageFilter.Register()

                ' Attempt to connect to a running instance of Solid Edge.
                application = DirectCast(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)
                partDocument = CType(application.ActiveDocument, SolidEdgePart.PartDocument)

                If partDocument IsNot Nothing Then
                    Dim properties = CType(partDocument.Properties, SolidEdgeFramework.PropertySets)
                End If
            Catch ex As System.Exception
                Console.WriteLine(ex)
            Finally
                OleMessageFilter.Unregister()
            End Try
        End Sub
    End Class
End Namespace

This code is very similar to your's, except:

  •  it's a console program taking usage of the <STAThread> main method decoration to ensure STA
  •  it's using the OleMessageFilter

Set your project configuration to x64 platform (not x86 and not AnyCPU).

 

The changes of ST10 or higher with missing 32 bit DLL for SolidEdgeFileProperties doesn't apply to your case, since you're using the Solid Edge API to access the file properties and not the (external) SolidEdgeFileProperties object.

 

If you get the above sample program to run, you also should be able to fix your WinForm code to get it work.

 

Kind regards,
Wolfgang Kunert - www.wksyspro.de

Re: SE2019 Properties via VB.net in WIN10

Siemens Phenom Siemens Phenom
Siemens Phenom

Firstly, I do not think we need to be so quick to discount the transition away from 32-bit code.  99% of all calls to GTAC for "my code works pre-ST10 but no longer works with ST10" are resolved by simply installing View & Markup or recompiling the code for 64-bit.  Regardless of how badly or how inefficiently you thing the code may be written, code that works pre-ST10 but then does not work with ST10 should not and does not require complete rewrites of entire blocks of code to then work with ST10.  Installing View & Markup is a simple test to verify if the pre-ST10 code will still work with ST10.

 

Secondly, as part of this transition away from 32-bit code, some of the functionality with 64-bit did not initially work as expected with ST10 so there were several fixes made for the 64-bit to then correctly work.  Therefore it is important that you also have installed the latest ST10 maintenance pack.

Re: SE2019 Properties via VB.net in WIN10

Creator
Creator

I've changed the compile to x64... I've installed the downloaded SEvST10 View & Markup...

and I'm testing this macro on SE2019 but nothing is working as original in ST8.

I did step thru properties section of the included Open&Save program where they find the file status property and that works fine.  The problem appears to be in not letting me set the active document to be able to access the properties?

 

If I OPEN the file from a specific path location I am able to read properties.

But if the file is already open and I want to interrogate to edit or add by calling the active document I'm at a standstill.

 

I thought for certain someone would have a snippet of code out there to access an active document and add a property.

 

 

Re: SE2019 Properties via VB.net in WIN10

Creator
Creator

Hello Wolfgang,

You're right, I'm not sure why the screen shot didn't show Solid Edge Part Type Library, but it is indeed referenced.

As for your assumption, yes it does appear the objSEPart is not being set.  I tried the Seimen's recommendation of installing SEvST10 View & Markup (against my better judgement because to to me that isn't a fix, just a work around).

 

So I'm not sure why it won't let me set the active doc. 

 

I'll work later on skipping setting it to a "Part Document" as you suggest and see if that fixes it.

 

Thanks for all your help.

Mark