×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Editing a diameter dimension

Editing a diameter dimension

Editing a diameter dimension

(OP)
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


RE: Editing a diameter dimension

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.

RE: Editing a diameter dimension

(OP)
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

RE: Editing a diameter dimension

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.

RE: Editing a diameter dimension

(OP)
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

RE: Editing a diameter dimension

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.

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 "You need to preselect a dimension"
    Else
        'If you want to keep the dimension change the 0 to 1
        'after the "SUFFIX TEXT" 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, "DIMENSION", 0, 0, 0
        Part.EditDimensionProperties2 0, 0, 0, "", "", 1, 9, 2, 1, 11, 11, "PREFIX TEXT", "SUFFIX TEXT", 0, "TEXT ABOVE DIM", "TEXT BELOW DIM", 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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources