how to get a list of dimensions and gtols?

Discussion in 'SolidWorks' started by Howard, Nov 7, 2004.

  1. Howard

    Howard Guest

    Hi,

    I am trying to prepare a list of all the Dimensions
    in a drawing and all the GTols attached to them (if there are any).
    Below you will find a code that does that. It uses the API to get
    the data you see on SolidWorks and copies it into a class private
    members.

    However, I have a few acute problems.
    1. Assuming I have "n" annotations in a drawing
    and each annotation has "k" fields, it means I have to
    perform O(n*k) calls to a COM object. This, on its own has an
    overhead. Since I am using .NET to call the COM object, it means
    I have O(n*k) calls to the RCW (COM wrapper in .NET).

    How do I minimize the overhead and save my users a lot
    of time waiting for the application to run?

    2. There is an API function "GetAttachedEntities2" which works
    when I call and select a GTol, it then tells me which
    dimension it is connected to.
    However, I think there is a bug since this function does not work
    when I select a GTol and look for its Dimensions.

    Is this indeed a bug? how do I connect between a Dimension and
    its GTol? I need a code that works.

    Looking at the attached file: Is there a better way to code
    what I do there?


    Thanks in advance,

    Howard





    ' ------------------------------------------------------------------------


    Private Function SetAnnotation(ByVal swAnnotationToParse As
    SldWorks.Annotation, ByVal IsAnnNumberingOn As Boolean) As Boolean
    Dim swDimension As SldWorks.DisplayDimension
    Dim swAttachedEntitiesArray As Object
    Dim Linear, Angular As Object
    Const PI As Double = 3.14159265359
    Static miDimensionCounter As Integer
    Dim LinearFactorArray As Double() = {1000, 100, 1, 1000 /
    25.4, 1000 / 25.4 / 12, 1000 / 25.4, _
    10000000000.0#, 1000000000,
    1000000, 1000 / 25.4 * 1000, 1 / 25.4 * 1000000000}
    Dim AngularFactorArray As Double() = {180 / PI, 1 / 60, 1 / 60
    / 60, 1}

    ' --------------------------------------------------
    ' on the first part of the function - adding a dimension
    '
    ' --------------------------------------------------

    swDimension = swAnnotationToParse.GetSpecificAnnotation
    ' FindTolOfAnnotationAddToObject(swAnnotationToParse)

    Linear = swDrawingDoc.GetUnits()
    Angular = swDrawingDoc.GetAngularUnits()
    mdDimLinearFactor = LinearFactorArray(Linear(0))
    mdDimAngularFactor = AngularFactorArray(Angular(0))

    ' get the text out of a dimension. Start with "Non Angular"
    dimension
    msPrefixText =
    swDimension.GetText(SwConst.swDimensionTextParts_e.swDimensionTextPrefix)
    msSuffixText =
    swDimension.GetText(SwConst.swDimensionTextParts_e.swDimensionTextSuffix)
    msAboveText =
    swDimension.GetText(SwConst.swDimensionTextParts_e.swDimensionTextCalloutAbove)
    msBelowText =
    swDimension.GetText(SwConst.swDimensionTextParts_e.swDimensionTextCalloutBelow)
    mlngToleranceType = swDimension.GetDimension.GetToleranceType

    If (True = swDimension.GetUseDocPrecision()) Then
    mdPrecision = swDimension.GetPrimaryPrecision2()
    Else
    mdPrecision = swDimension.GetAlternatePrecision2()
    If mdPrecision =
    SwConst.swDimensionPrecisionSettings_e.swTolerancePrecisionFollowsNominal
    Then
    mdPrecision = swDimension.GetPrimaryPrecision2()
    End If
    End If

    If mdPrecision =
    SwConst.swDimensionPrecisionSettings_e.swPrecisionFollowsDocumentSetting
    Then
    mdPrecision =
    swDrawingDoc.GetUserPreferenceIntegerValue(SwConst.swDrawingProjectionType_e.swDrawing1stAngleProjection)
    End If


    mdarrToleranceValues =
    swDimension.GetDimension.GetToleranceValues
    mobjToleranceFitValues =
    swDimension.GetDimension.GetToleranceFitValues()
    If swDimension.GetType <>
    SwConst.swDimensionType_e.swAngularDimension Then
    mdValue =
    swDimension.GetDimension.GetUserValueIn(swDrawingDoc)
    Else ' swAngularDimension
    mdValue = swDimension.GetDimension.value
    End If

    ' exit this function when incurring a bracket annotation
    return FALSE
    If Left(msPrefixText, 1) = "(" And msSuffixText = ")" Then
    Return False
    ' if annotation already numbered don't renumber it, but add to
    counter
    If IsAnnNumberingOn = True Then
    miDimensionCounter = miDimensionCounter + 1
    If Not Regex.IsMatch(msAboveText, "^(.*?)\[(.*?)\](.*?)?")
    Then
    swDimension.SetText(3, msAboveText & " " & "[" &
    miDimensionCounter & "]")
    End If
    End If

    mstr_xPosition =
    swAnnotationToParse.GetDisplayData.GetTextPositionAtIndex(0)(0)
    mstr_yPosition =
    swAnnotationToParse.GetDisplayData.GetTextPositionAtIndex(0)(1)

    ' --------------------------------------------------
    ' the below is a very interesting part of the application
    ' it returns the location/position of the selected annotation
    ' for example "A-5".
    ' --------------------------------------------------

    Dim swDrawingWidth =
    swDrawingDoc.GetCurrentSheet().GetProperties()(5)
    Dim swDrawingHeight =
    swDrawingDoc.GetCurrentSheet().GetProperties()(6)
    Dim iHorizSection, iVertSection As Integer
    Dim dTemp As Double
    Dim dXSectionNum As Double = NumOfHorzSections(swDrawingWidth,
    swDrawingHeight)
    Dim dYSectionNum As Double = NumOfVertSections(swDrawingWidth,
    swDrawingHeight)

    If (dXSectionNum = 21 Or dXSectionNum = 17) Then
    iHorizSection = Math.Round(mstr_xPosition /
    (swDrawingWidth / dXSectionNum)) + 1
    Else
    dTemp = mstr_xPosition / (swDrawingWidth / dXSectionNum)
    iHorizSection = Int(mstr_xPosition / (swDrawingWidth /
    dXSectionNum))
    End If
    iVertSection = NumOfVertSections(swDrawingWidth,
    swDrawingHeight) - Int(mstr_yPosition / (swDrawingHeight /
    NumOfVertSections(swDrawingWidth, swDrawingHeight)))
    mstr_yPosition = (Chr(iVertSection + 64))
    mstr_xPosition = CStr(iHorizSection + 1)

    End Function
    '-----------------------------------------------------------------------------
     
    Howard, Nov 7, 2004
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.