Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Editing a diameter dimension 1

Status
Not open for further replies.

dogarila

Mechanical
Oct 28, 2001
594
Here's what I want to do:

1) Dimension a tapped hole as a regular hole: DIA8.00
(I don't know how to use phi in this text so I'll use DIA)
2) Select the dimension.
3) Click a button (run a macro) that will open a dialog box.
4) Select from the dialog box the pitch (based on the DIA value), the depth and the number of holes, then click OK.
5) The text of the dimension will change to: TAP M8x1.25 and on the second line 16.0 DEEP, 4X.

Does anybody has a routine that does that or something similar, or suggestions of how to do it in VB or any help ay all?

Thanx,
Andrew (Netshop21)
andrew@netshop21.com


 
Replies continue below

Recommended for you

Do you have any experience with VB? For example, do you know how to setup and populate forms? I can help you out but need to know the degree of depth that I need to go into. DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Hi dsi,

I have used VB before, I know how to create and use forms and do simple things. I know VB at theoretical level, I didn't have the opportunity to use it much so far.

It would be great if you could help me. Thank you.

Andrew
 
I started looking at the process. I have a couple more questions.

1. The diameter has two decimal places and you want the final text to remove them, correct? Would this be as simple as adding prefix and suffix text to the dimension, or does the system value get replaced as well?

2. If the dimension must be read, converted and replaced, I will need to know the units you are using. All lengths are returned to VB in meters.

3. If I can get you the code to select and modify the dimension, could you handle the creation of the desired strings? If not, I will need a short sample list of the items you are going to present to the user. DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
1. Correct, remove the decimals. It's just adding prefix and suffix, some of the last on the next line.

2. The units I'm using are mm.

3. I'll try. I think I can.

Andrew
 
Excellent! I just had another project dropped on my desk, so I was about to bail on your project. I should have enough here to get you started. I indicated where you need to call your form. Post more to this thread if you have any more questions.

You should just put this into a SolidWorks macro file if you are using SW2001. The latest release has the ability to add forms. This will save you from having to compile the project.
Code:
Option Explicit

Public Const swSelDIMENSION = 14

Public swApp As Object
Public Part As Object
Public SelMgr As Object
Public SelObj As Object

Public sDimName As String

Sub Main()
    Set swApp = CreateObject("SldWorks.Application")
    Set Part = swApp.ActiveDoc
    
    sDimName = ""
    ' Get the selected item from the SW selection mgr
    Set SelMgr = Part.SelectionManager()
    If SelMgr.GetSelectedObjectCount > 0 Then
        ' Ensure the 1st selected item is a dimension
        If SelMgr.GetSelectedObjectType(1) = swSelDIMENSION Then
            ' The user has a dimension selected
            Set SelObj = SelMgr.GetSelectedObject2(1)
            sDimName = SelObj.FullName
        End If
    End If
    If Len(sDimName) < 2 Then
        swApp.SendMsgToUser &quot;You need to preselect a dimension&quot;
    Else
        'If you want to keep the dimension change the 0 to 1
        'after the &quot;SUFFIX TEXT&quot; string. This will maintain the
        'system dimension
        
        'Here is where you would call your form to get the remaining text
        'Compile you strings and come back to this point.
        
        'If you need to get the value of the dimension to remove the
        'trailing zeroes, use the SystemValue property and convert the
        'units from meters to your desired units. Then, use the CInt() method
        'to convert the value to an integer. Then you can bury it in your string.
        
        Part.EditSketch
        Part.SelectByID sDimName, &quot;DIMENSION&quot;, 0, 0, 0
        Part.EditDimensionProperties2 0, 0, 0, &quot;&quot;, &quot;&quot;, 1, 9, 2, 1, 11, 11, &quot;PREFIX TEXT&quot;, &quot;SUFFIX TEXT&quot;, 0, &quot;TEXT ABOVE DIM&quot;, &quot;TEXT BELOW DIM&quot;, 0
        Part.ClearSelection
    End If

    Set SelObj = Nothing
    Set SelMgr = Nothing
    Set Part = Nothing
    Set swApp = Nothing
End Sub
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