Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use weight in an equation? 1

Status
Not open for further replies.

SAWH

Mechanical
Jan 28, 2004
15
SE
We would like to calculate a value using weight and volume from a part and use this value on our drawings.

Because there is no equations in Drawing mode we hoped to be able to use equations in the part calcuate the value and for example give that value to the length of a dummy sketch. Then take that value in to a file property and get that property in to the drawing.

The equation is Weight-Volume*1.4 (The weight in water)

Is there a way to do this???

/Sam White
 
Replies continue below

Recommended for you

You can use a design table to do the calculation and have it propagate a custom property for the value which can then be use to fill the note on the drawing.



Remember...
"If you don't use your head,
your going to have to use your feet."
 
Sam

I am pretty sure that you can accomplish this with a "Macro Feature" create your dummy sketch, and place the macro feature in the tree underneath it so it executes each time the part rebuilds... basically you can tap into those values via the API and have that macro do the calcualtion for you but you will have to keep in mind the units that you are working in via th api

I dont have time to mess with it right now but I can try to work out somethimg for you later today perhaps... unless you feel comfortable with the API...

let me know



Regards,
Jon
jgbena@yahoo.com
 
Heres a snippet of the code that you could use.

Sub main()
Dim swApp, Model As Object
Dim retval As Long
Dim massprops As Variant
Dim mass As Double
Dim Density As Double
Dim volume As Double
Dim A as Double

Set swApp = CreateObject("SldWorks.Application")
Set Model = swApp.ActiveDoc

massprops = Model.GetMassProperties

'Density = massprops(10)

volume = massprops(3)

'SurfaceArea = massprops(4)

mass = massprops(5)

A = (mass - volume) * 1.4

boolstatus = Part.Extension.SelectByID("D1@Sketch1@Part1.SLDPRT", "DIMENSION", 0, 0, 0, False, 0, Nothing)

Part.Parameter("D1@Sketch1").SystemValue = A / 1000
End Sub

Then all you need to do is create a parametric note in the drawing and you should be good to go..

oh yea there is an API function to insert that as a macro feature but I cant remember the syntax at the moment and I dont have time to fiddle with it.. perhaps you can look at the API help and figure it out... if not i will try again later on or maybe tonight



Regards,
Jon
jgbena@yahoo.com
 
Ooops

One thing I forgot to say is also that I did this code in VB 6.0 When you are in solidworks recording a macro instead of the "createobject" you would use:

Set swApp = Application.SldWorks

instead

hope that helps



Regards,
Jon
jgbena@yahoo.com
 
Okay my head is not in a very good place today.. im sorry for so many posts on this subject...

I redid this macro in the VBA editor in Solidworks so you could use it easier... but Im afraid I cant seem to remember how to insert the macro feature.. the last time i did this was like a year ago. As soon as I figure it out Ill give you the rest.

But for now heres what you can do.

Create your dummy sketch and name it DMSKETCH
dimension the line in the DMSKETCH and rename that dim "TEMP"

make sure that the DMSKETCH is the very last feature in the part always.

Run this macro


create your drawing and insert the model items dimensions

In your drawing create a parametric note and select the "TEMP" dimension from DMSKETCH

that will update each time and stay current.

Here is the code that will work in VBA in Solidoworks

Sorry for any confusion
------------------------------------------------------------
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Dim A As Long
Dim massprops As Variant
Dim mass As Double
Dim Density As Double
Dim volume As Double

Sub main()

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

massprops = Part.GetMassProperties

'Density = massprops(10)

volume = massprops(3)

'SurfaceArea = massprops(4)

mass = massprops(5)

A = (mass - volume) * 1.4

boolstatus = Part.Extension.SelectByID("TEMP@DMSKETCH", "DIMENSION", 0, 0, 0, False, 0, Nothing)

Part.Parameter("TEMP@DMSKETCH").SystemValue = A / 1000


End Sub
-----------------------------------------------------------



Regards,
Jon
jgbena@yahoo.com
 
I have not done this!!! But I believe this might be the way to go.

Use Custom properties in the following way. (Actually a system generated custom property.)

First set Tools - Options - System Options - Performance - Update Mass Properties While Saving Document.

This will keep your mass props up to date automatically.

Next use File - Properties and the Custom @ Congiguration Specific Properties in the Summary Information Dialogue Box.

The property will be in the form:

SW<mass property>@ @configuration @model

Sounds like a Design Table would allow you to tweak this to get the format you want on your drawing - or some custom code.

John Richards Sr. Mech. Engr.
Rockwell Collins Flight Dynamics

Forget rich and famous - I want to be rich and unknown.
 
John,

The problem is this. You can do calculations with the design table yes but only on (for lack of a better term) &quot;visible&quot; dimensions and paramaters.. you cannot use the mass properties and volume variables in the design table. I tried it a few different ways and it will not recognize the values. Thats why I developed the code above... now if i could only remember how to insert a macro feature! ;)

Regards,
Jon
jgbena@yahoo.com
 
Thanks everybody for trying to help me

I been away for a while and was supprised of all the effort you guys put in.

I just tested doing this with a design table but couldnt get it to work because I dont get the value just the link in to my desig table.

Im going to check my API fundamentals and try geting Jon´s macro feature solution to work.

/Sam White
 
It has been a while since I did any Design Tables, but I thought you could get custom properties in to them?

John Richards Sr. Mech. Engr.
Rockwell Collins Flight Dynamics

Forget rich and famous - I want to be rich and unknown.
 
I just looked in Help and you can use custom properties of this type. You would need to get it over from the part to the drawing, but that should not be too hard with external DT's. Worth a look?

John Richards Sr. Mech. Engr.
Rockwell Collins Flight Dynamics

There are only 10 types of people in the world - those who understand binary and those who don't.
 
Sam If you give me an email address I can send you the sample part and the macro



Regards,
Jon
jgbena@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top