|
rounding in custom property "sw-mass"
hi all, thanks for taking the time to help.
i am using a macro to save custom properties into my part files (drawing number, material of construction, finish, etc) which is then transferred to the title block in the component's drawing document. one of the custom properties is "sw-mass", which always seems to evaluate to 3 decimal places (conincidentally or otherwise this is what i have my dimension rounding set to).
is there a way i can round this number to a specified number of decimal places (usually none) before it is written to the drawing title block?
if i invoke the custom property userform with a part document open, any previously saved custom properties are pre-filled in on the form, apart from the weight of the component. i have just tried using the following code in userform_initialize() to get the weight to be filled into a text box...
txtweight = modeldoc2.custominfo("weight")
... but it simpy displays "sw-mass" in the textbox as opposed to the evaluated value. how can i get the evaluated value to display in the textbox?
many thanks,
chris
christopher thorn | cswp
mechanical design engineer
atritor limited, coventry, england
hey christopher,
have a look at modeldocextension:: custompropertymanager
and
custompropertymanager:: get2
in the solidworks api help topics.
there you can find some examples on how to retrieve custom properties.
as for rounding a number down if you are using vba try the round function:
round(expression [,numdecimalplaces])
expression required. numeric expression being rounded.
numdecimalplaces optional. number indicating how many places to
the right of the decimal are included in the rounding.
if omitted, integers are returned by the round function.
hope this helps
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
christopher,
i don't use a macro to do this - i just link text in the drawing template to the properties in the part or assembly document. however, i control the precision of the mass using the units section of the part or assembly's document properties. change the precision value of the 'length' item and that precision is reflected in the sw-mass evaluation.
unfortunately without api the only options you have are the templates document properties for the unit decimal places.
answer thanks for the replies guys. the code below now does exactly as i wanted.
what valerie and luke said about the document template is true - i'm lumped with a *maximum* precision of three decimal places on my userform unless i start tinkering with the template. this shouldn't really be a problem though.
thanks again,
chris
-- code --
dim swmodel as sldworks.modeldoc2
dim valout as string
dim resvalout as string
dim cpm as sldworks.custompropertymanager
set swapp = application.sldworks
set swmodel = swapp.activedoc
set cpm = swmodel.extension.custompropertymanager("")
if not cpm is nothing then
cpm.get2 "weight", valout, resvalout
end if
txtweight = varweight
christopher thorn | cswp
mechanical design engineer
atritor limited, coventry, england
christopher, since the weight is derived from the mass in the model, it is possible to control the # of decimal places by controlling the number of units as such:
set model = swapp.activatedoc2(modelpath, true, nerrors) 'this switches to the model,
model.setuserpreferenceintegervalue swunitsmasspropdecimalplaces, 3 'sets the weight # of decimal places to 3 [x.xxx],
set model = swapp.activatedoc2(dwgpath, true, nerrors) 'and switches back to the drawing.
additionally, you can create a userform that asks for the # of decimal places in conjunction with this snippet on the fly.
to defeat the wheat, go against the grain.
thanks very much tom, now i really can do exactly as i wanted
christopher thorn | cswp
mechanical design engineer
atritor limited, coventry, england
quick |
|