Error while running Visual Studio Script

Experimenter
Experimenter

I am trying to create a scpript that will change the document number in Solid Edge documents.  I am using Visual Studio 2015.  The code I am using is shown below:

 

Dim objApp As SolidEdgeFramework.Application = Nothing
Dim objPropSets As SolidEdgeFileProperties.PropertySets = Nothing
Dim objProp As SolidEdgeFileProperties.Property = Nothing
Dim objProps As SolidEdgeFileProperties.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

 The error i get is:

 

Exception thrown: 'System.Runtime.InteropServices.COMException' in WindowsApplication1.exe

The procedure number is out of range. (Exception from HRESULT: 0x800706D1)

The program '[8300] WindowsApplication1.vshost.exe' has exited with code -1 (0xffffffff).

 

My script chokes after it passes the first "For Each" statement.  I have tried googling for a solution to this error message but I have not found anything that pertains to Solid Edge.  Has anybody ever come across this error and if so how did you fix it?  I will gladly provide more info if need be.  Any help, suggestions or tips would be greatly appreciated, thanks.

 

Kevin

2 REPLIES

Re: Error while running Visual Studio Script

Phenom
Phenom

Your objApp is still Nothing, need to assign it to a running instance of SE

Also I changed the references for PropertySets, Properties and Property to SolidEdgeFramework (instead of your SolidEdgeFileProperties)

The following should work:

 

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

fb.pngSolid Edge Users Facebook Group

[ Everything under the sun about - Solid Edge ]

Re: Error while running Visual Studio Script

Genius
Genius

Maybe this post helps you:

 

https://community.plm.automation.siemens.com/t5/Solid-Edge-Developer-Forum/Document-properties-unava...



==========================
Kabir Costa
Industrial Designer
kabircosta@gmail.com