Use Document's Units Code
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Use Document's Units Code

 
Post new topic   Reply to topic    CADForums.net Forum Index -> SolidWorks
Author Message
inthepickle
Guest





Posted: Wed Nov 09, 2005 1:10 pm    Post subject: Use Document's Units Code Reply with quote

I have a part fully defined and modeled in SolidWorks Office 2005. The
Document Properties -> Units is set for a 3 place decimal. There are 3
reference dimensions that have been put on the part manually.

RD1@Annotations
RD2@Annotations
RD3@Annotations

I am trying to write a macro that will select these dimension, go into
more properties, and then say "do not use document units", and set it
to fraction rounded to the 16th.

I tried to use SolidWorks and record the macro myself, but it will not
record correctly. It only records the code used to select these
dimension. It will not show how to only change these dimensions to a
fraction.

I have went through SolidWorks API helo, and came up empty handed. I
am sure this something really simple, but I can't find it. Could
someone please give me the lines of code that will change these
dimensions that way I need them, or at least point me in the right
direction.

Thanks

Back to top
Tin Man
Guest





Posted: Wed Nov 09, 2005 5:10 pm    Post subject: Re: Use Document's Units Code Reply with quote

The below macro will change all the *preselected* dimensions to 1/16th
fractional.

Ken



'******************************************************************************
' Fractional.swb
'******************************************************************************
Dim swApp As Object
Dim swModel As Object
Dim swSelMgr As Object
Dim selCount As Integer
Dim selType As Integer
Dim retval As Variant
Dim CurrentSelDimension As Object
Dim boolstatus As Boolean
Dim useDoc, roundToFraction As String
Dim uType, fractBase, fractDenom As Long
Dim i As Integer

Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

If swModel.GetUserPreferenceIntegerValue(swUnitsLinear) <> swINCHES
Then
boolstatus = MsgBox("Program only works for files with INCH
Primary" & Chr(13) & _
"Units in the Doument Settings." & Chr(13) & _
"Ending routine.", vbExclamation)
End
End If

useDoc = False 'TRUE=Use the document settings for units
uType = swINCHES 'Set to Inches
fractBase = swFRACTION 'Set to Fractions
fractDenom = 16 'Denominator Base unit
roundToFraction = True 'TRUE rounds values to the nearest fraction,
FALSE displays fractions only if the values are exact

Set swSelMgr = swModel.SelectionManager()
selCount = swSelMgr.GetSelectedObjectCount()

If (selCount > 0) Then
For i = 1 To selCount
selType = swSelMgr.GetSelectedObjectType2(i)
If (selType = swSelDIMENSIONS) Then
Set CurrentSelDimension = swSelMgr.GetSelectedObject3(i)
CurrentSelDimension.SetDual True
CurrentSelDimension.SetUnits useDoc, uType, fractBase,
fractDenom, roundToFraction
End If
Next
End If

swModel.ClearSelection2 True
swModel.GraphicsRedraw2
End Sub
Back to top
inthepickle
Guest





Posted: Wed Nov 09, 2005 9:10 pm    Post subject: Re: Use Document's Units Code Reply with quote

thanks ken - the code you gave me worked like a charm

Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> SolidWorks All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Contact Us
Powered by phpBB