Tick Talk on EsoxRepublic.com


Shapeshifting Through SW Dimension API

Posted in API by Administrator on the October 21st, 2008

One of the sticky things about working with SolidWorks API is the fragmented object structure. Often, it takes more than one object type to deal with a single object. The most common example is the ModelDoc/PartDoc/AssemblyDoc/DrawingDoc objects. All SW files are ModelDocs, but many API functions are only available in the type-specific objects, and accessing those functions may require setting a second PartDoc or AssemblyDoc or DrawingDoc object after the ModelDoc object is already set.

A less common but more convoluted set of objects is the ones that deal with dimensions. There are as many as four different objects that deal with a SolidWorks dimension:

  • Dimension: Properties and methods for the dimension parameter, such as name, value, driven state
  • Tolerance: A sub-object of Dimension, used to access tolerance info
  • Display Dimension: Dimesnions can be displayed in more than one place, DisplayDimension is a single display instance.
  • Annotation: DisplayDimension is a sub-object of the Annotation object. You would need the Annotation object to access layers and leaders.
Dimension object chart
Hierarchy of dimension-related objects.

Selecting Dimensions

When Accessing selected dimensions, the SW SelectionMgr object passes selected dimensions as DisplayDimension object. This means that it is necessary to pass the DisplayDimension object to a Dimension object to change its value. It would be necessary to pass the DisplayDimension to an Annotation object to change its layer. To change a tolerance, one may need to access the Tolerance object (though there are some unlisted Dimension object API’s that access tolerance data).

The example code below shows how to take a DisplayDimension from the SelectionMgr, pass it to a Dimension object, and then change the dimension value.

Set swApp = Application.SldWorks
Dim swApp As SldWorks.SldWorks
Dim ActDoc As SldWorks.ModelDoc2
Dim SelMgr As SldWorks.SelectionMgr
Dim DispDim As SldWorks.DisplayDimension
Dim DimToEdit As SldWorks.Dimension

Set ActDoc = swApp.ActiveDoc
Set SelMgr = ActDoc.SelectionManager

‘get selected DisplayDimension object
Set DispDim = SelMgr.GetSelectedObject6(1)
‘pass selection to a Dimension object
Set DimToEdit = DispDim.GetDimension
change value of Dimension object
DimToEdit.SetUserValueIn2 ActDoc, CDbl(2.78), swSetValue_UseCurrentSetting

OT: Football pool

Once again, I’m in a football pool. Once again, I was off to an abysmal start, 4-5 right per week. Until last week, that is. I changed my pick strategy. For the last two weeks, I have picked the team whose home city has the highest crime rate. Got 10 right last week and 7 this week (our winner only had 9). I’ll go with this strategy for a while longer and see how it pans out.

Leave a Reply

You must be logged in to post a comment.