INTELLIGENT WORK FORUMS FOR ENGINEERING PROFESSIONALS
Come Join Us!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- Turn Off Ad Banners
- One-Click Access To Your
Favorite Forums
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site

(Download This Button Today!)
Member Feedback
"...Your site is one of the cleanest and BEST forums that I
have seen. I have sent quite a few people your way. Keep up
the good work!!!"
Geography
Where in the world do Eng-Tips members come from?
|
SolidWorks 3D CAD products FAQ
|
API and Macros
|
Volume in Feet
Posted: 24 Mar 04 (Edited 8 Jun 04)
|
Here is a Macro that lists Volume in feet. See below for details.
We had a customer who wanted a volume on the drawing in feet, but wanted to build his part in inches. You can't find a way to do that in SW.
This macro will insert a macro feature into the feature tree. This macro will then run every rebuild. The macro takes the volume in the natural system units, meters, and converts it into feet. Then it adds a property called volume and adds that value. It updates when the model is changed.
If you add features after the Macro feature they will not be included. You can drag and drop the macro up and down the tree. This does require a ctrl-q rebuild for whatever reason.
It can be found at:
http://www.scottjbaugh.com/Design_Portfolio/Contributed%20SW%20models.htm - Volume in Feet
If you don't feel like Downloading the file You can copy it:
Option Explicit Dim swApp As SldWorks.SldWorks Dim Part As SldWorks.ModelDoc2 Sub main() Dim ThisFile As String Dim Methods(8) As String Dim Names As Variant Dim Types As Variant Dim Values As Variant Dim editBody As body2 Dim swmacrofeaturebydefault As Variant Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set editBody = Nothing 'Define the routines to call ThisFile = swApp.GetCurrentMacroPathName Methods(0) = ThisFile Methods(1) = "MacroFeature_Module1" Methods(2) = "swmRebuild" Methods(3) = ThisFile Methods(4) = "MacroFeature_Module1" Methods(5) = "swmEditDefinition" Methods(6) = "" 'A security routine is optional Methods(7) = "" Methods(8) = ""
Names = Empty Types = Empty Values = Empty 'Insert the macro feature Part.FeatureManager.InsertMacroFeature "Volume in Feet", "", (Methods), Names, Types, Values, editBody, swmacrofeaturebydefault End Sub
Function swmRebuild(app As Variant, Part As Variant, feature As Variant) As Variant Dim Definition As SldWorks.MacroFeatureData Dim Objects As Variant Dim ObjTypes As Variant Dim SelMarks As Variant Dim DrwViews As Variant Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Set Definition = feature.GetDefinition Definition.GetSelections2 Objects, ObjTypes, SelMarks, DrwViews
Dim vol As Variant Dim conv As Variant Dim convRounded As String Dim prop As Boolean Dim mass As SldWorks.MassProperty Set mass = Part.Extension.CreateMassProperty vol = mass.volume conv = vol * 35.31466672 convRounded = Round(conv, 3) prop = Part.DeleteCustomInfo2("", "Volume") prop = Part.AddCustomInfo3("", "Volume", 30, convRounded + " Cubic Feet") Debug.Print " Volume = " & mass.volume End Function
Function swmEditDefinition(app As Variant, Part As Variant, feature As Variant) As Variant End Function |
Back to SolidWorks 3D CAD products FAQ Index
Back to SolidWorks 3D CAD products Forum
My FAQ Archive
Email This FAQ To A Friend |
|
 |
|