ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
MSMike Spens12/03/2010

Hi all,

  Can anyone help with the following VBA macro code?  I need to get the center of area of some sketch geometry in a sketch.  GetSectionProperties2 method of ModelDocExtension looks to be the call I'm after, but I'm sure I'm not building the "section" input correctly and there isn't much info in the API help.  When I run the macro, the returned value of the first array element is 1 = "invalid input" according to the API help. All other values in the returned array are zero. 

  FYI, I was hoping to select a single boundary of lines, arcs, etc. from a more complicated sketch and get just the center of area of the selected boundary.

Dim swApp As SldWorks.SldWorks
Sub main()
Dim model As ModelDoc2
Set swApp = Application.SldWorks
Set model = swApp.ActiveDoc

Dim selmgr As SelectionMgr
Set selmgr = model.SelectionManager

Dim sections As Variant
Dim tmp() As Object
ReDim tmp(selmgr.GetSelectedObjectCount - 1)
For i = 1 To selmgr.GetSelectedObjectCount
   Set tmp(i - 1) = selmgr.GetSelectedObject(i)
Next i
Dim values As Variant

values = model.Extension.GetSectionProperties2(tmp)

End Sub