update drawing after changing file properties

 

I have a macro that updates the file properties in both the part and drawing.  It changes the properties fine.  However, the drawing view update sporadically.  The first time I run it, the properties update, but the titleblock does not update on the screen.  I can go back into the macro and hit the save again.  The title block then updates.

Code:

                objPropSets.Save()

                objDocument.Save()

                With DirectCast(objDocument, DraftDocument)

                    .UpdatePropertyTextDisplay()

                    .UpdatePropertyTextCacheAndDisplay()

                End With

                objApplication.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailViewRefreshWindow)

                objApplication.StartCommand(SolidEdgeConstants.DetailCommandConstants.DetailViewRefreshWindow)

 

Posted by: Kenneth McIntyre
Post date: 6/30/2009 9:35:13 AM

13 REPLIES

RE: update drawing after changing file properties

 

Hi Ken,

use SolidEdgeConstants.DetailCommandConstants.DetailDimensionUpdatePropertyText to get your property texts updated.

Best regards,

Wolfgang

 

Posted by: Wolfgang Kunert
Post date: 7/1/2009 10:57:42 PM

Re: RE: update drawing after changing file properties

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

I did something different to update the property in the referenced file but that's not the problem here. I noticed that I need to save the referenced document in order to see the property updated in the title block (while doing this manually in SE).

 

In my macro I can update the property in the 3D file but I can't save the document. To say it shortly I have one object for the linked 3D :

objParDoc = objDocAct.ModelLinks.Item(1).ModelDocument

 

Then after updating the property (I use the solidedgeframework.property objects) I want to save the linked model but I can't.


I just use objParDoc.Save() but I have an error. Solid Edge says that I don't have the rights to write in the folder or on the file (which is obviously false since I can open the file and do what I want in a regular way through Solid Edge). Any clue on why the Save method doesn't work and how I can overwrite this limitation ?

 

Files are local for testing (but will be on a server in production version) and I'm administrator of my station and I created those files. The files are at the root of a local hard drive (I first thought it could be a problem with the length of the path).

Re: RE: update drawing after changing file properties

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

You should not save the document itself as it may have been opened automatically by SE when opening the draft.

I recommend to access it through the SolidEdgeFileProperties API and then just save the property sets and close it.

Another pitfall is the internal property text cache, which Solid Edge uses to the display them. In order to force SE to refetch them from the document, you should call the UpdatePropertyTextCacheAndDisplay() method on the draft document.

The following example demonstrates this usage:

    Dim objDoc As DraftDocument = objApp.ActiveDocument
    Dim mdlLink As ModelLink = objDoc.ModelLinks.Item(1)

    ' Open the file properties
    Dim props As New SolidEdgeFileProperties.PropertySets
    props.Open(mdlLink.FileName, False)
    Dim custProps As SolidEdgeFileProperties.Properties = props.Item("Custom")

    ' Change the value of a custom property
    Dim prop As SolidEdgeFileProperties.Property = custProps.Item("CAD Identifier")
    prop.Value = Date.Now.ToLongTimeString() ' Just to have a new string during each run

    ' Save the properties
    props.Save()
    props.Close()

    ' Update all property texts
    objDoc.UpdatePropertyTextCacheAndDisplay()

During my tests, I was using a callout with the following property text: "%{CAD Identifier/CP|GP}". If you are not changing that custom property, you will have to change the code above.

Re: RE: update drawing after changing file properties

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

The custom property is "Indice" and I changed the code according to that (the goal is to put that string in lower case).

 

However I have a problem with the FileProperties API. When I reach this line :

Dim props As New SolidEdgeFileProperties.PropertySets

 

I have an error which says that the COM class for the CLSID {XXXXX....} component could not be retrieved and the class is not registered. Sorry the message is in french.

 

System.Runtime.InteropServices.COMException : 'La récupération de la fabrique de classes COM pour le composant avec le CLSID {AED8FE60-3129-11D1-BC83-0800360E1E02} a échoué en raison de l'erreur suivante : 80040154 Classe non enregistrée (Exception de HRESULT : 0x80040154 (REGDB_E_CLASSNOTREG)).'

 

I'm using Visual Studio Community 2017.

I just tried in my VS 2010 Pro license and it can't find the interop.solidedgefileproperties.dll in the COM references. I wonder why but it could be related. I imported it manually from one of the Custom examples but the problem is the same.

Maybe I have to register the dll manually with regsvr32 command line ?

Re: RE: update drawing after changing file properties

Solution Partner Creator Solution Partner Creator
Solution Partner Creator
Tried regsvr32, gave an error Smiley Sad

Re: RE: update drawing after changing file properties

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Which version of Solid Edge are you using?

I did my tests with ST9 and am actually installing ST10.

Re: RE: update drawing after changing file properties

Solution Partner Creator Solution Partner Creator
Solution Partner Creator
I'm testing in ST10.

Re: RE: update drawing after changing file properties

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Make sure that you add a reference to the "Solid Edge File Properties Object Library" in you project.

References.png

If you still have problems to create an instance of this class, register the propauto.dll in a Command Prompt with Administrator privileges. You need to run cmd.exe as administrator! If you run a "normal" command prompt, even as a user with admin rights, the "regsvr32 propauto.dll" command will fail.

Re: RE: update drawing after changing file properties

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

I already had the referenced dll. I tried to register propauto.dll and it worked (the registration I mean) but I still can't create a new instance of this class.
I can find the designated CLSID in my registry in the Classes Root and in Local Machine\software\classes.

Here's the full code :

Imports SolidEdgeFileProperties
Imports SolidEdgeFramework
Imports SolidEdgeFrameworkSupport
Imports SolidEdgeConstants
Imports SolidEdgeDraft
Imports SolidEdgePart
Imports System.IO
Imports System.Runtime.InteropServices

Module Module1

#Region "Déclarations"
    Private objApp As SolidEdgeFramework.Application        'Application Solid Edge ouverte
    Private objDoc As DraftDocument
    Private mdlLink As ModelLink
#End Region


    Sub Main()

        ConnectToSE(objApp)

        'vérifier qu'il y a un document actif
        Try
            ' Get a reference to the active document. Détecte si c'est une mise en plan et ferme sinon
            If objApp.ActiveDocument.Type <> SolidEdgeFramework.DocumentTypeConstants.igDraftDocument Then
                MsgBox("Mettez vous dans un fichier plan et relancez la macro.", vbInformation)
                Exit Sub
            End If

            objDoc = objApp.ActiveDocument
        Catch ex As Exception
            MsgBox("Impossible de trouver le document actif. Solid Edge doit être lancé avec un fichier ouvert.", vbCritical)
        End Try

        mdlLink = objDoc.ModelLinks.Item(1)

        ' Open the file properties
        Dim props As New SolidEdgeFileProperties.PropertySets
        props.Open(mdlLink.FileName, False)
        Dim custProps As SolidEdgeFileProperties.Properties = props.Item("Custom")

        ' Change the value of a custom property
        Dim prop As SolidEdgeFileProperties.Property = custProps.Item("Indice")
        Dim PropVal As String = prop.Value
        PropVal = PropVal.ToLower

        prop.Value = PropVal

        ' Save the properties
        props.Save()
        props.Close()

        ' Update all property texts
        objDoc.UpdatePropertyTextCacheAndDisplay()

        objDoc.Save()

    End Sub

#Region "Solid Edge Connect"
    ''' <summary>
    ''' Procedure permettant de se connecter a SolidEdge 
    ''' </summary>
    ''' <param name="objApp">application SolidEdge ouverte</param>
    ''' <remarks>/!\ SolideEdge doit etre ouvert avec un fichier ouvert</remarks>
    Public Sub ConnectToSE(ByRef objApp As SolidEdgeFramework.Application)

        'Se connecter à Solid Edge
        Try
            ' Connect to a running instance of Solid Edge
            objApp = Marshal.GetActiveObject("SolidEdge.Application")
        Catch ex As Exception
            Debug.Print(ex.Message)
            'Si pas Solid Edge, msgbox
            MsgBox("Impossible de se connecter à Solid Edge. Solid Edge doit être lancé avec un fichier ouvert.", vbCritical)
            End
        End Try
    End Sub

#End Region