Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

DisplayDimension::SetPrecision

Status
Not open for further replies.

LeBlanc

Mechanical
Nov 16, 2001
4
I am currently using SW2001. I am a new user to VB and API programming.
Would someone be able to supply me with an example macro that uses retval=DisplayDimension.SetPrecision(useDoc,primary,alternate,primaryTol,alternateTol) successfully. I keep getting the message runtime error 438, Object doesnt support this property or method.

Thanks
Andre
 
Replies continue below

Recommended for you

Could you post some more of your code? How are you obtaining the DisplayDimension object?

There is a FAQ for removing dangling entities that illustrates how to obtain the object by traversing through all of the display dimensions in the drawing.

Can you also explain more of what you are doing? For example, are you traversing through all of the display dimensions or is the user selecting a single dimension for updating? DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
The user must select a single dimension for updating. This part works fine.
The problem is that I can not set the tolerance precision. The dimension precision is set by EditDimensionProperties2, but this does not set the tolerance precision.

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long
Dim Annotation As Object
Dim Gtol As Object
Dim DatumTag As Object
Dim FeatureData As Object
Dim Feature As Object
Dim theDimen As Object

Dim Component As Object


Sub main()

Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set model = Part


Set SelMgr = model.SelectionManager() ' Get the selection manager class
If (SelMgr.GetSelectedObjectCount <> 0) Then ' If user has selected something
Set selObj = SelMgr.GetSelectedObject2(1) ' Get the first item in the selection list
selObjName = selObj.FullName ' Get the name of the selected component
messageString = &quot;Member name is &quot; + selObjName
swApp.SendMsgToUser messageString ' Display to the user
Part.SelectByID selObjName, &quot;DIMENSION&quot;, 0, 0, 0
HoleUpperLimit = 2.5
HoleLowerLimit = 1.5
MaxTolerance = HoleUpperLimit * 0.0000254
MinTolerance = HoleLowerLimit * 0.0000254
Part.EditDimensionProperties2 2, MaxTolerance, MinTolerance, &quot;&quot;, &quot;&quot;, 0, 4, 1, 1, 11, 11, &quot;&quot;, &quot;&quot;, 1, &quot;&quot;, &quot;&quot;, 0
model.GraphicsRedraw2
Set theDimen = Part.Parameter(selObjName)
theValue = theDimen.Value
End If

retval = theDimen.setPrecision(0, 4, 2, 4, 2) ' It doesn't seem to recognize SetPrecision

End Sub
 
LeBlanc:

A few things to note.

There is a difference between a dimension and a display dimension. Note that the FullName property is not available to display dimensions. This should indicate that the GetSelectedObject2 returned a dimension rather than a display dimension.

You should also use the GetSelectedObject3() method in 2001 since GetSelectedObject2() has been marked obsolete.

All that said, here is some code that should do what you want.
Code:
Option Explicit

Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim dwgDim As Object
Dim dispDim As Object
Dim sDimName As String

Sub Main()
    Dim HoleUpperLimit As Single, HoleLowerLimit As Single
    Dim MaxTolerance As Single, MinTolerance As Single
    Dim retval
    
    Set swApp = CreateObject(&quot;SldWorks.Application&quot;)
    Set Part = swApp.ActiveDoc
    Set SelMgr = Part.SelectionManager()
    
    If (SelMgr.GetSelectedObjectCount <> 0) Then
        'Get the display dimension
        Set dispDim = SelMgr.GetSelectedObject3(1)
        retval = dispDim.SetPrecision(False, 4, 2, 4, 2)
        'Get the dimension
        Set dwgDim = dispDim.GetDimension
        'Modify the dimension
        sDimName = dwgDim.FullName
        Part.SelectByID sDimName, &quot;DIMENSION&quot;, 0, 0, 0
        HoleUpperLimit = 2.5
        HoleLowerLimit = 1.5
        MaxTolerance = HoleUpperLimit * 0.0000254
        MinTolerance = HoleLowerLimit * 0.0000254
        Part.EditDimensionProperties2 2, MaxTolerance, MinTolerance, &quot;&quot;, &quot;&quot;, 0, 4, 1, 1, 11, 11, &quot;&quot;, &quot;&quot;, 1, &quot;&quot;, &quot;&quot;, 0
        Part.GraphicsRedraw2
    End If
    
    Set dwgDim = Nothing
    Set dispDim = Nothing
    Set SelMgr = Nothing
    Set Part = Nothing
    Set swApp = Nothing
End Sub
Hope this helps! DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Many thanks, this is exactly what I require.
I used GetSelectedObject2 knowing it was obsolete only because my code would not run using the new GetSelectedObject3. Any ideas why this might be so.

 
You're welcome.

The GetSelectedObject2 method returns a Dimension object and GetSelectedObject3 returns a DisplayDimension object.

When you access the FullName property using GSO3, you will get an error because the FullName property is not available in the DisplayDimension object.

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor