Use weight in an equation?
Use weight in an equation?
(OP)
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
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






RE: Use weight in an equation?
Remember...
"If you don't use your head,
your going to have to use your feet."
RE: Use weight in an equation?
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
RE: Use weight in an equation?
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
RE: Use weight in an equation?
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
RE: Use weight in an equation?
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
RE: Use weight in an equation?
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.
RE: Use weight in an equation?
The problem is this. You can do calculations with the design table yes but only on (for lack of a better term) "visible" 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
RE: Use weight in an equation?
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
RE: Use weight in an equation?
John Richards Sr. Mech. Engr.
Rockwell Collins Flight Dynamics
Forget rich and famous - I want to be rich and unknown.
RE: Use weight in an equation?
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.
RE: Use weight in an equation?
Regards,
Jon
jgbena@yahoo.com