Author Topic: active document not active?  (Read 179 times)

0 Members and 1 Guest are viewing this topic.

perry59

  • Full Member
  • ***
  • Posts: 225
active document not active?
« on: December 14, 2020, 07:05:43 PM »
I have a section of code (below) which is to open a specific document and make a simple change to a shape. Sounds easy enough the code executes but there is no change to the shape. When the drawing is opened it appears to be active (there is a "junk" variable for debugging that DOES have the proper name for the document).
However even though document2 is supposedly active I believe it is working on document1. A good clue is that I see the code work on "page-2" which does NOT exist in document 2 but DOES exist in document1.
Can anyone tell me what is going on? how can my code be working on document1 while my debugger is saying document2 is active???
Thanks!

result = DatabaseOps.executeNonQuery(sql)
                If result = True Then
                    refsDrawing = DatabaseOps.GetDrawingRefs(_designatorPrefix, _designator)
                    refsSheet = DatabaseOps.GetSheetRefsDict(_designatorPrefix, _designator)
                    'for each drawing containing a reference to this connector...
                    For Each row As DataRow In refsDrawing.Rows
                        dwgName = row.Item("DocumentName")
                        fullPath = VE_docPath & dwgName
                        If System.IO.File.Exists(fullPath) Then
                            If Globals.ThisAddIn.Application.ActiveDocument.FullName <> fullPath Then
                                Globals.ThisAddIn.Application.Documents.Open(fullPath)
                                'the above statement opens the document and appears to make it active,
                                'as the "junk" variable below has the correct document name
                                Dim junk As String = Globals.ThisAddIn.Application.ActiveDocument.FullName
                                'for each sheet in this drawing containing a reference to this connector...
                                For Each vsoPage In vsoPages
                                    'if the page is listed in our table of refernces...
                                    'this can iterate sheets more than desired, the current sheet may not have a connector
                                    'but the list of sheets may have this sheet name from other drawings.
                                    'still better than going through EVERY sheet no matter what though
                                    If refsSheet.ContainsValue(vsoPage.Name) Then
                                        For ShpNo = 1 To vsoPage.Shapes.Count
                                            vsoShape = vsoPage.Shapes(ShpNo)
                                            If (Microsoft.VisualBasic.Left(UCase(vsoShape.Name), 9) = "BACKSHELL") Then
                                                'have to get designatorprefix, designator and effectivity ID and see if they match current connector
                                                If vsoShape.CellExists("Prop.VEDesignatorPrefix", False) = True Then
                                                    If vsoShape.Cells("Prop.VEDesignatorPrefix").ResultStr(Visio.VisUnitCodes.visNoCast) = _designatorPrefix Then
                                                        If vsoShape.CellExists("Prop.VEDesignator", False) = True Then
                                                            If vsoShape.Cells("Prop.VEDesignator").ResultStr(Visio.VisUnitCodes.visNoCast) = _designator Then
                                                                If vsoShape.CellExists("Prop.VEExisting", False) = True Then
                                                                    If vsoShape.CellsU("Prop.VEExisting").Formula <> _isExisting Then
                                                                        vsoShape.CellsU("Prop.VEExisting").FormulaForceU = _isExisting
                                                                    End If
                                                                End If
                                                            End If
                                                        End If
                                                    End If
                                                End If
                                            End If
                                        Next ShpNo
                                    End If
                                Next
                                'save and close document
                                Globals.ThisAddIn.Application.ActiveDocument.Save()
                                Globals.ThisAddIn.Application.ActiveDocument.Close()

perry59

  • Full Member
  • ***
  • Posts: 225
Re: active document not active?
« Reply #1 on: December 14, 2020, 07:25:01 PM »
Never mind, I'm an idiot!
a couple of key lines, namely:

vsoDoc = Globals.ThisAddIn.Application.ActiveDocument
vsoPages = vsoDoc.Pages

were not where they should have been, all is well now!