AnsweredAssumed Answered

Differences between write code in VBA editor and in the properties

Question asked by Danilo Martins on Sep 26, 2014
Latest reply on May 30, 2016 by Danilo Martins

Hello there,

 

 

I'm trying to get a simple macro to run under the properties of the file. As example i'll use a macro to calculate the volume of a part in dm³. As i'm using SolidWorks 2012, I don't have the unit cubic decimeters.

 

 

That's the simpler code that works for me:

 

 

------------------------------------------------------------------------------

 

 

Dim Part As Object

Dim boolstatus As Boolean

Dim swApp As SldWorks.SldWorks

Dim swPart As SldWorks.PartDoc

Dim swSelMgr As SldWorks.SelectionMgr

Dim mass As SldWorks.MassProperty

Dim retval As String

Dim Volume As String

 

 

Sub main()

 

 

        Set swApp = CreateObject("SldWorks.Application")

        Set Part = swApp.ActiveDoc

        Set mass = Part.Extension.CreateMassProperty

        boolstatus = mass.AddBodies((compbody))

        mass.UseSystemUnits = False

        Volume = mass.Volume / 1000000

        Part.DeleteCustomInfo ("VOLUME dm3")

        Part.AddCustomInfo3 "", "VOLUME dm3", swCustomInfoText, FormatNumber(Volume, 3, vbUseDefault, vbUseDefault, vbUseDefault)

 

 

End Sub

 

 

------------------------------------------------------------------------------

 

 

All I want is to put the code under the properties of a part, and call it using Equations. I know that I can't do some things calling the macro under properties, but what is wrong? Can anyone explain more about this differences?

 

 

Thanks a lot! I hope this informations opens my world!

Outcomes