Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Macro Syntax for Setting Shaded Image Quality 1

Status
Not open for further replies.

Tobin1

Petroleum
Nov 9, 2007
176
0
0
US
Howdy All!

I've recorded a SW Macro with the intent of setting the Shaded Image Quality property.
I'm using SW 2007.

The property I'm trying to set is found in Tools > Options > Document Properties > Image Quality - Inside the Frame labeled "Shaded and draft quality HLR/HLV resolution" there is a Slider Bar with some sort of digital readout labeled "Deviation:" that changes as you slide the bar.

I can set/change the other properties on this page, but, I don't seem to be able to set/change this paticular property.

Is there some Syntax for this?
Can anyone help?

Recorded Macro Included:

Tobin Sparks
 
Replies continue below

Recommended for you

Code:
Const SF As Double = 1000

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim CurVal As Double
Dim MaxVal As Double
Dim MinVal As Double
Dim NewVal As Double
Dim myString As String

Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
swDoc.Extension.GetUserPreferenceDoubleValueRange _
    swImageQualityShadedDeviation, CurVal, MinVal, MaxVal
myString = "Enter a value between " & MinVal * 1000 & " and " & MaxVal * 1000 & _
    vbCrLf & vbCrLf & "     (Current value is " & CurVal * 1000 & ")"
NewVal = Val(InputBox(myString, "Shaded Deviation", CurVal * 1000)) / 1000
swDoc.SetUserPreferenceDoubleValue swImageQualityShadedDeviation, NewVal

End Sub

-handleman, CSWP (The new, easy test)
 
handlsman
WOW - thanks very much!

I'm having a little trouble understanding just what's going on here though. Is there some sort of reference I could get to find this kind of information? I've been trying F1 while standing on different code (as was suggested in some vb instructions) but don't seem to be getting any of this kind of information.

I was actulally just looking for a sort of dumbed down version of this. We're thinking of making a Macro that someone can run just before pushing Save and it would be hard coded with a setting that would reduce the deviation to a reasonable amount. I've been trying to alter what you gave me but I don't seem to understnad enough yet to get what I want.

Can you help with where I might be able to learn more about this?

Thanks again

Tobin Sparks
 
The SolidWorks API help can't be accessed from the VBA code window. You have to pick Help->Solidworks and Addins API Help Topics from the main SolidWorks window.

Recorded macros in SolidWorks are not nearly as helpful as those in Excel. They rarely even give a good starting point for a useful macro.

As far as what is going on here, it's fairly simple. I'll add some comments for each line:

Code:
Const SF As Double = 1000
'This SF is not really necessary.  It just avoids having 
'to deal with numbers like 5E-4

Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim CurVal As Double
Dim MaxVal As Double
Dim MinVal As Double
Dim NewVal As Double
Dim myString As String
'variable declarations

Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
'These two are sort of standard lines to get 
'references to SolidWorks and the current document.

swDoc.Extension.GetUserPreferenceDoubleValueRange _
    swImageQualityShadedDeviation, CurVal, MinVal, MaxVal
'This line gets the current value along with the maximum and
'minimum allowed values for the shaded deviation.  It loads
'these values into the variables CurVal, MinVal, and MaxVal.
'You need to know what the max and min acceptable values
'are before you can input one.

myString = "Enter a value between " & MinVal * SF & " and " & MaxVal * SF & _
    vbCrLf & vbCrLf & "     (Current value is " & CurVal * SF & ")"
'All this line does is build up the message for the InputBox.  It multiplies
'all the values by SF to make them easier for the user to read and input.


NewVal = Val(InputBox(myString, "Shaded Deviation", CurVal * SF)) / SF
'This line is what actually displays the box asking the user for a new
'value.  The input box comes up with the current value (multiplied by
'the scale factor) for convenience.  Whatever the user enters is 
'divided by the scale factor to get it back to the right value.
'This value is loaded into the variable NewVal

swDoc.SetUserPreferenceDoubleValue swImageQualityShadedDeviation, NewVal
'This line actually sets the new value.  If you knew from the start what
'that new value was, all you would need is this line and the two lines 
'starting with "Set...".  All the stuff in the middle is just for the 
'user interface.  However, I'm not sure how much the acceptable
'values for the deviation vary from file to file, so if you hard-code
'a particular value for the new deviation then your macro may not always work.

End Sub

-handleman, CSWP (The new, easy test)
 
handleman

Thank you very much.
This is very helpful to me.
I really appreciate the part about the Scale being involved with the Deviation Value.
I'll let this sink in a little, I'm sure this is very useful information. I'm thinking of using the retrieved Min and Max values divided by three to create a reasonable setting. I’ll post what I come up with.

Thanks Again


Tobin Sparks
 
handleman

Attached is our result of the Macro that you helped me start.

I have a question about one of your comments.

You wrote <Recorded macros in SolidWorks are not nearly as helpful as those in Excel. They rarely even give a good starting point for a useful macro.>

Does this mean you use Excel somehow to get SW program information or just that the VB in Excel is better than the VB in SW?

I'm still curious as to how I could go about digging out useful information similar to <swDoc.Extension.GetUserPreferenceDoubleValueRange _
swImageQualityShadedDeviation, CurVal, MinVal, MaxVal> especially with the syntax information (not much good without it).

Is this just a matter of digging around in the Object Browser or is there a better way?
Even if I use this parameter and search in the Object Browser I can’t seem to get to the syntax information you were able to give to me. I seem to be missing something and it feels like it’s real big. :)

Thanks Again


Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=918e9a48-4257-4392-9535-d1eebeeca2b4&file=SetImageQuality.swp
No, you can't use Excel to find out information about SolidWorks programming. What I meant to say was that recording Excel macros in Excel give you a better starting point on an Excel macro than recording SolidWorks macros in SolidWorks gives for writing a SolidWorks macro.

Did you try looking in the API help? Open SolidWorks. Just SolidWorks, not the VBA editor. Click "Help", then click "SolidWorks and Add-Ins API Help Topics." In that area you can find syntax help, examples, etc. for all the SolidWorks API functions.

-handleman, CSWP (The new, easy test)
 
handleman,

I have been rummaging thru the “SolidWorks and Add-Ins API Help Topics”.
I've found it to be helpful except when I’m not sure what I’m looking at. :)
The information that you gave me is very helpful though.

Thanks Again


Tobin Sparks
 
Status
Not open for further replies.
Back
Top