AnsweredAssumed Answered

Modification brought by script not saved

Question asked by m_ba on May 15, 2014
Latest reply on Jun 2, 2014 by m_ba

Hi,

 

I wrote a litte function to swap value of two attributes.

VBA code is running fine. All sheets are opened and modified (modifications brought can be seen during code execution). Unfortunately only a part of these are saved. Such as a ‘save’ operation is missing.

DxDesigner needs no ‘save’ due to the fact it’s working on a database (see p697 of DxDesigner Automation Reference Manual, EE 7.9.5 DocumentSave method).

Could someone explain me what I’m doing wrong?

Thanks

 

 

Private Sub Swap_Properties()
    Dim My_Dx_App As Object
    Dim My_Dx_Prj As String
    Dim My_Block As Variant

    Dim My_Block_Sheets As Variant
    Dim My_Block_Sheet As Variant
    Dim My_WorkSheet As Object
   
    Dim My_Components As Object
    Dim My_Component As ViewDraw.Component
    Dim My_Component_Attribute As ViewDraw.Attribute

    Dim My_Comp_PartNumber_Value As String
    Dim My_Comp_PartNumber_Visible As Integer
    Dim My_Comp_PartLabel_Value As String
    Dim My_Comp_PartLabel_Visible As Integer

    Dim i As Integer

 

    i = 0

    My_Comp_PartNumber_Value = ""
    My_Comp_PartNumber_Visible = 0
    My_Comp_PartLabel_Value = ""
    My_Comp_PartLabel_Visible = 0


    Set My_Dx_App = GetObject(, "ViewDraw.Application") 'DxDesigner need to be open!
    If My_Dx_App Is Nothing Then
        MsgBox "Could not connect to DxDesigner Apllication!", vbCritical
    Else
        My_Dx_Prj = My_Dx_App.GetActiveDesign 'Check if there's an open project
        If My_Dx_Prj = "" Then
            MsgBox "No open project found!", vbExclamation
        Else
            For Each My_Block In My_Dx_App.SchematicSheetDocuments.GetAvailableSchematics
                
                Set My_Block_Sheets = My_Dx_App.SchematicSheetDocuments.GetAvailableSheets(My_Block)
               
                For Each My_Block_Sheet In My_Block_Sheets
                    Set My_WorkSheet = My_Dx_App.SchematicSheetDocuments.Open(My_Block, My_Block_Sheet)

                    My_WorkSheet.Activate
                    Set My_Components = My_Dx_App.Query(VDM_COMP, VD_ALL)
                    If My_Components.Count > 0 Then
                        For Each My_Component In My_Components
       
                            Set My_Component_Attribute = My_Component.FindAttribute("Part Number")
                            If Not My_Component_Attribute Is Nothing Then
                                My_Comp_PartNumber_Value = My_Component_Attribute.Value
                                My_Comp_PartNumber_Visible = My_Component_Attribute.Visible
                            End If
       
                            Set My_Component_Attribute = My_Component.FindAttribute("Part Label")
                            If Not My_Component_Attribute Is Nothing Then
                                My_Comp_PartLabel_Value = My_Component_Attribute.Value
                                My_Comp_PartLabel_Visible = My_Component_Attribute.Visible
                            End If


                            If Not (My_Comp_PartNumber_Value = "" Or My_Comp_PartLabel_Value = "") Then
                           
                            '*** Swap the two attributes ***

                                Set My_Component_Attribute = My_Component.FindAttribute("Part Number")
                                If Not My_Component_Attribute Is Nothing Then
                                    My_Component_Attribute.Value = My_Comp_PartLabel_Value
                                    My_Component_Attribute.Visible = My_Comp_PartLabel_Visible
                                End If
       
                                Set My_Component_Attribute = My_Component.FindAttribute("Part Label")
                                If Not My_Component_Attribute Is Nothing Then
                                    My_Component_Attribute.Value = My_Comp_PartNumber_Value
                                    My_Component_Attribute.Visible = My_Comp_PartNumber_Visible
                                End If
       
                            '*** End Swap the two attributes ***
                            End If
       
                            i = i + 1
                            My_Comp_PartNumber_Value = ""
                            My_Comp_PartNumber_Visible = 0
                            My_Comp_PartLabel_Value = ""
                            My_Comp_PartLabel_Visible = 0
       
                        Next
                    End If
                    My_WorkSheet.Close True, My_Block_Sheet
                    'My_Dx_App.SchematicSheetDocuments.Close 'close all schematic and not only the selected one!!
                Next
            Next
        End If
    End If


MyEndSub:
    Set My_Component_Attribute = Nothing
    Set My_Component = Nothing
    Set My_Components = Nothing
    Set My_WorkSheet = Nothing
    Set My_Block_Sheet = Nothing
    Set My_Block_Sheets = Nothing
    Set My_Block = Nothing
    'Set My_Dx_Prj = Nothing
    Set My_Dx_App = Nothing
    Debug.Print "Finished " & Now()
End Sub

Outcomes