Shape's "Name" Field not passed when exporting drwaing to (MSAccess) database ?

Started by jd2009, October 18, 2009, 08:56:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jd2009

Hello Experts,

I have this Visio 2003 problem which is "tearing me apart" for the last few days....

I am trying to draw an electronic system drawing (with multiple connections per system block to other system blocks). well  I succeeded in doing this of course by creating my own shapes with multiple connections points.

What I want to do is to export this drawing to a database, to analyze the system architecture within this database and eventually get the system blocks and connections between these blocks in a database format.

My problems is as follows : The shape's "Name" field is not exported to the database. (nor it is found in the shapesheet)
I have been using the "Export to database" tool. when exporting the drawing to an Access database, I get the shapes and connection lines between them with information about the connection points (Begin,Y;Y ; End,X;Y) to other shapes. When trying you associate between the connection lines drawn and the shapes I am seeing a mismatch.

For example:
in the exported database I can find the connection line properties that contain the contention information (This comes is form the connection lines shapesheet)...
"BeginX ; Y" of a connection line are : "PAR(PNT(SubSystem.9!Connections.X2,Subsystem.9!Connections.Y2))"
and
"PAR(PNT(SubSystem.9!Connections.X2,SubSystem.9!Connections.Y2))"  respectively.
meaning it is coming started at a shape named as "SubSystem.9!"

When looking for this "SubSystem.9" shape in the exported  database i can't find it... , the only reference I have for the exported shapes is the "ShapeKey" field. and in the index of "SubSystem.9" shape in the exported database  is not "9"..... . I can't find the "Name" in the exported database.

When marking each and every shape in the drawing and clicking on menu "Format->Special" I can see the information that I would like to get like "ID","Master","Type" and "Name" . but these are not exported to the database. If I would have the "Name" exported then I could associate between the a "ShapeKey" and "Name" and thus associate between the a connection line and the relevant shape.

Tried a workaround : I have tried to find a way to create a custom property like "Shape_Name" and using the "ShapeSheet", create a function that will assign the shape's "Name" to the "Shapes_Name" custom property, and this can be easily exported to the database..... but I could not find the function to do it.

It looks quite odd to me that you can access all of of the shapesheet information and properties but cannot get a shape's "Name".

I am puzzled... am I missing anything here ? how to do it ? how can I get the shape's "Name" being exported using the database export tool ?

I would appreciate if someone can help me.

Thanks,

Joseph D.


aledlund


Unless you specifically name a shape via code, visio will assign one (that is unique only to the page it is on). In actuality it will assign two of them, Name and NameU. I haven't checked the export properties, but I suspect the NameU is in there.

You might check this out

http://msdn.microsoft.com/en-us/library/bb435962(office.11).aspx

you might check this out also

http://blogs.msdn.com/visio/archive/2006/07/27/679625.aspx

hth,
al

jd2009

Hello al,

Thanks for your answer... but it does not help yet. please see below.

#1 - "Name" is no longer part of the shapesheet (as seen in this ref: http://books.google.co.uk/books?id=zZq_lBKcei0C&pg=PA126&lpg=PA126&dq=visio+shapesheet+name&source=bl&ots=z0molVHceq&sig=QnwNgRxnB17zZUv5I2MIj1bHn5M&hl=en&ei=4XXbSpWKGZHWmgOHqbXZDA&sa=X&oi=book_result&ct=result&resnum=9&ved=0CCAQ6AEwCA#v=onepage&q=name&f=false)

#2 - The above link says that "nameU" is part of the shapesheet on V2003. but ... I can't find "Nameu" in the shapesheet (visio 2003). where is it ? which section ?

#3 - tried to assign "=shape.nameu" and  "=shape.name" and "=shape.NameID" to a custom propoerty but i get "error in formula".

#4 -page 88 of the above book suggets to use NameID.. OK.... so how do  i get it as well ?

Thanks in advance.

JD





Thanks,

JD


aledlund

I'm not sure how you are moving your 'names' to your custom properties. I tested the process with this macro code.
al




Public Sub myMacro()

    Dim visApp As Visio.Application
    Dim visPage As Visio.Page
    Dim visShapes As Visio.Shapes
    Dim visShape As Visio.Shape
    Dim visShapeName As String
    Dim visShapeNameU As String
    Dim visShapeNameId As String
   
    Set visApp = Application
    Set visPage = visApp.ActivePage
    Set visShapes = visPage.Shapes
   
    '
    'cycle through the shapes on the page
    '
    For Each visShape In visShapes
   
        visShapeName = visShape.Name
        visShapeNameU = visShape.NameU
        visShapeNameId = visShape.NameID
   
        ForceShapeProperty visShape, "myName", visShapeName
        ForceShapeProperty visShape, "myNameU", visShapeNameU
        ForceShapeProperty visShape, "myNameId", visShapeNameId
       
    Next visShape

End Sub


'
' update custom property, if the property does not exist create it
'
Public Sub ForceShapeProperty(visShape As Visio.Shape, _
                                strProperty As String, _
                                strValue As String, _
                                Optional strAttrSet As String = "")

        Dim visCell As Visio.Cell
        Set visCell = Nothing
        Dim strPropertyName As String
        strPropertyName = "prop." & strProperty
        Dim blnReturn As Boolean

            If visShape.CellExists(strPropertyName, False) = False Then
                blnReturn = AddCustomProperty( _
                        visShape, _
                        strProperty, _
                        strProperty, _
                        strProperty, _
                        , , , , , _
                        strAttrSet)
            End If
           
            Set visCell = visShape.Cells(strPropertyName)
            SetCellValueToString visCell, strValue

    End Sub


'***********************************************************************
'
' visio sdk code
'
'***********************************************************************



'
' from v2007 sdk, modified
'
Public Function AddCustomProperty(visShape As Visio.Shape, _
    strLocalRowName As String, _
    strRowNameU As String, _
    strLabelName As String, _
    Optional vsoPropType As VisCellVals, _
    Optional strFormat As String, _
    Optional strPrompt As String, _
    Optional blnAskOnDrop As Boolean, _
    Optional blnHidden As Boolean, _
    Optional strSortKey As String) As Boolean

   
    Dim vsoCell     As Visio.Cell
    Dim intRowIndex As Integer
    Dim strValue    As String
   
    On Error GoTo AddCustomProperty_Err
   
   
        Dim blnReturn As Boolean
        blnReturn = False
        Dim strCell As String
        strCell = "prop." & strLocalRowName
        Dim exists As Boolean
        exists = visShape.CellExists(strCell, visExistsAnywhere)
        If exists = True Then
             blnReturn = True
             GoTo HandleReturn
        End If

        If visShape.SectionExists(visSectionProp, False) = False Then
            visShape.AddSection (visSectionProp)
        End If
   
    ' Add a named Custom Property row. In addition to
    ' adding a row with the local name (strLocalRowNname),
    ' this call will usually set the universal name of
    ' the new row to strLocalRowName as well.
    ' However, the universal row name will not be set
    ' if this shape already has a custom property row
    ' with the universal name (NameU) equal to strLocalRowName.
    intRowIndex = visShape.AddNamedRow(visSectionProp, _
         strLocalRowName, VisRowIndices.visRowProp)
     
    ' The columns of the properties that this functions
    ' sets are fixed, and can be accessed directly using
    ' the CellsSRC method and column index.
   
    ' Column 1: Prompt
    ' Get the Cell object.
    Set vsoCell = visShape.CellsSRC(visSectionProp, _
        visRowProp + intRowIndex, visCustPropsPrompt)
    SetCellValueToString vsoCell, strPrompt
   
    ' Any cell in the row can be used to set the
    ' universal row name. Only set the name if
    ' strRowNameU differs from the local name and
    ' is not blank.
    If (strLocalRowName <> strRowNameU And _
        Len(strRowNameU) > 0) Then
        vsoCell.RowNameU = strRowNameU
    End If
       
    ' Column 2: Label
    Set vsoCell = visShape.CellsSRC(visSectionProp, _
        visRowProp + intRowIndex, visCustPropsLabel)
    SetCellValueToString vsoCell, strLabelName

    ' Column 3: Format
    Set vsoCell = visShape.CellsSRC(visSectionProp, _
        visRowProp + intRowIndex, visCustPropsFormat)
    SetCellValueToString vsoCell, strFormat
   
    ' Column 4: Sort Key
    Set vsoCell = visShape.CellsSRC(visSectionProp, _
        visRowProp + intRowIndex, visCustPropsSortKey)
    SetCellValueToString vsoCell, strSortKey
   
    ' Column 5: Type
    Set vsoCell = visShape.CellsSRC(visSectionProp, _
        visRowProp + intRowIndex, visCustPropsType)
    strValue = CStr(vsoPropType)
    SetCellValueToString vsoCell, strValue
   
    ' Column 6: Hidden
    Set vsoCell = visShape.CellsSRC(visSectionProp, _
        visRowProp + intRowIndex, visCustPropsInvis)
    strValue = CStr(blnHidden)
    SetCellValueToString vsoCell, strValue
   
    ' Column 7: Ask to drop
    Set vsoCell = visShape.CellsSRC(visSectionProp, _
        visRowProp + intRowIndex, visCustPropsAsk)
    strValue = CStr(blnAskOnDrop)
    SetCellValueToString vsoCell, strValue
   
HandleReturn:

    AddCustomProperty = blnReturn
   
    Exit Function
   
AddCustomProperty_Err:
    Debug.Print Err.Description
                     
End Function


'
' from v2007 sdk
'
Public Sub SetCellValueToString(vsoCell As Visio.Cell, _
    strNewValue As String)

    On Error GoTo SetCellValueToString_Err
   
    ' Set the value for the cell.
    vsoCell.FormulaU = StringToFormulaForString(strNewValue)
   
    Exit Sub
   
SetCellValueToString_Err:

    If Not (vsoCell Is Nothing) Then
        If (vsoCell.Application.AlertResponse = 0) Then
            ' needs a little more information when if fails
            MsgBox Err.Description & " " & vsoCell.Shape.Name & " " & vsoCell.Name
        Else
            Debug.Print Err.Description
        End If
    Else
        Debug.Print Err.Description
    End If
                         
End Sub

'
' from v2007 sdk
'
Public Function StringToFormulaForString(strIn As String) As String
   

    Dim strResult As String
   
    On Error GoTo StringToFormulaForString_Err
   
    strResult = strIn
   
    ' Replace all (") with ("").
    strResult = Replace(strResult, Chr(34), _
        Chr(34) & Chr(34))
   
    ' Add ("") around the whole string.
    strResult = Chr(34) & strResult & Chr(34)
   
    StringToFormulaForString = strResult

    Exit Function
   
StringToFormulaForString_Err:
    Debug.Print Err.Description
   
End Function



jd2009

Wow ! . thank you!

For moving the value to the custom properties I suppose that I need to try the following things:

#1 - Run the macro or function through the Shapesheet "action" properties and then add in the code for the assignment of custom properties fields for the relevant values.

or....

#2 - Develop a function from the code that you have added and allocate the function in the relevant custom properties fields. the function would need to return the Name and NameU values.

Thanks a lot for your help !

JD



aledlund

Experience has shown that many users that work with the DataWizard want to automate the refresh/save process of their documents. Usually this ends up as another macro that calls the add-in. The offered code would probably fit very nicely into that type of workflow.
have a great one,
al