×
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

API help - DimensionTolerance.SetFont

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 :

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

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

Two immediate problems:

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.

batI could be the world's greatest underachiever, if I could just learn to apply myself.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: API help - DimensionTolerance.SetFont

Is what you've posted the entire macro you're trying to run?  If so, you've not told SW which dimension you want it to go to work on.  You have to get a handle on the specific dimension you're interested in.  Assuming you want to operate on the selected dimension, it'll be something like this, which will do what you want to do to every selected dimension that has a tolerance shown:

CODE

Dim swApp As SldWorks.SldWorks
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

(OP)
Thanks for the answers, guys.


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

The variables you define in the code are only pointers or containers for the actual SW objects you wish to edit.  When they are first defined, they are empty.  It is not until you assign an actual object (i.e. using "Set") that the variable has something to edit.  Then the variables become the gateway through which the VB code can interact with the objects.

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.

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

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