API help - DimensionTolerance.SetFont
API help - DimensionTolerance.SetFont
(OP)
Can someone please help me with this? I am going out of my mind trying to get this to work, but all of my tests and guesses have failed.
I've already got a larger macro to put this code into, so all I want is to be able to run a simple macro and change the selected dimension tolerance font scale to 0.75. I will integrate it into my other code once I get it working.
After snagging some other code I found on here and messing with it appropriately, I've had no luck. Here is what I've got it trimmed down to :
This keeps throwing a "Compile Error / Expected: =". When I try to throw an = in there, it has me set the values again, which I still just can't make happy. What exactly is this looking for, and am I calling it properly?
FYI, I'm on SW2006 SP3.1.
I've already got a larger macro to put this code into, so all I want is to be able to run a simple macro and change the selected dimension tolerance font scale to 0.75. I will integrate it into my other code once I get it working.
After snagging some other code I found on here and messing with it appropriately, I've had no luck. Here is what I've got it trimmed down to :
CODE
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDim As SldWorks.Dimension
Dim swTol As SldWorks.DimensionTolerance
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swTol = swDim.Tolerance
swTol.SetFont(False, True, "0.75")
End Sub
Dim swDoc As SldWorks.ModelDoc2
Dim swDim As SldWorks.Dimension
Dim swTol As SldWorks.DimensionTolerance
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swTol = swDim.Tolerance
swTol.SetFont(False, True, "0.75")
End Sub
This keeps throwing a "Compile Error / Expected: =". When I try to throw an = in there, it has me set the values again, which I still just can't make happy. What exactly is this looking for, and am I calling it properly?
FYI, I'm on SW2006 SP3.1.






RE: API help - DimensionTolerance.SetFont
1. You are not actually selecting a dimension object for "swDim" to perform this action on.
2. Your syntax is wrong on the "swTol.SetFont" command. You are using function syntax while calling the API as a sub. Get rid of the parentheses.
http://www.EsoxRepublic.com-SolidWorks API VB programming help
RE: API help - DimensionTolerance.SetFont
CODE
Dim swDoc As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension
Dim swDimTol As SldWorks.DimensionTolerance
Dim boolstatus As Boolean
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set SelMgr = swDoc.SelectionManager
For i = 1 To SelMgr.GetSelectedObjectCount2(-1)
If SelMgr.GetSelectedObjectType3(i, -1) = swSelDIMENSIONS Then
Set swDispDim = SelMgr.GetSelectedObject6(i, -1)
Set swDim = swDispDim.GetDimension
Set swDimTol = swDim.Tolerance
If swDimTol.Type <> swTolNONE Then
swDimTol.SetFont False, True, 0.75
End If
End If
Next i
swDoc.GraphicsRedraw2
End Sub
Note that you had "0.75" instead of just 0.75. SetFont expects a double, not a string.
RE: API help - DimensionTolerance.SetFont
I think I understand now, I was misunderstanding how the targetting of an object works. I was thinking that if it was selected, it was automatically the object that the macro works on. I see now in the macro above that you actually have to set an object variable to the selected dimension, then perform the SetFont command upon it.
One question, though... if you're defining the objects in the code (set swDispDim, set swDim, set swDimTol) then why bother setting them in the overall variables prior to executing? Also, what does the boolstatus line do? It seems unnecessary to me, and the macro appears to work without it.
RE: API help - DimensionTolerance.SetFont
You are correct about "boolstatus". In many cases it can be ignored, provided you use "Sub" syntax and not "Function" syntax. In this case. "boolstatus" is just a return or "flag" variable to record whether a function performed successfully.
http://www.EsoxRepublic.com-SolidWorks API VB programming help