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
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
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
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
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
2. The units I'm using are mm.
3. I'll try. I think I can.
Andrew
RE: Editing a diameter dimension
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.