create (and keep) a mass measurement using catvba
create (and keep) a mass measurement using catvba
(OP)
I need to create and keep a mass measurement (so that it will update a formula as the mass changes) using catvba.
I can do the formula with catvba but i cannot see how to create the measurement with catvba.
Any ideas?
I can do the formula with catvba but i cannot see how to create the measurement with catvba.
Any ideas?





RE: create (and keep) a mass measurement using catvba
RE: create (and keep) a mass measurement using catvba
I think i phrased the question badly.
I want to create (and keep) an inertia measurement (the InertiaVolume.1 etc.. measurment that appears in the hierarchy tree) using vba.
The measurment will supply an uptodate value to a formula (which wont require vba to update the value whenever the mass of the body changes).
RE: create (and keep) a mass measurement using catvba
RE: create (and keep) a mass measurement using catvba
I thought volume was part of the InertiaVolume measurement?
RE: create (and keep) a mass measurement using catvba
You can also search your computer for V5Automation.chm and make a shortcut on your desktop for quick access.
You obviously don't need Length/width/height, you need a parameter for volume
You would add a volume parameter similar to the parameters below but you would need a relation to measure the volume of the part. I cant remember off the top of my head what the string is to enter in the relation, you can search google to see if you can find it.
Dim CATDocs As Documents
Set CATDocs = CATIA.Documents
Dim part1 As Document
Set part1 = CATDocs.Add("CATPart")
Dim width As RealParam
Set width = part1.Part.Parameters.CreateReal("width", 1.)
Dim height As RealParam
Set height = part1.Part.Parameters.CreateReal("height", 2.)
Dim depth As RealParam
Set depth = part1.Part.Parameters.CreateReal("depth", 3.)
Dim density As RealParam
Set density = part1.Part.Parameters.CreateReal("density", 1.5)
Dim mass As RealParam
Set mass = part1.Part.Parameters.CreateReal("mass", 0.)
Dim computemass As RealParam
Set computemass = part1.Part.Relations.CreateFormula
("computemass",
"Computes the cuboid mass", mass,
"(width*height*depth)*density")
RE: create (and keep) a mass measurement using catvba
I can get the mass and density values via vba.
I can create a formula and parameters and relations to link those parameters to user properties on the properties card of the catpart using catvba.
But unless they link to something that catia will automatically update (without using scripting) such as a measurement (so when the body changes the values change)they will be static.
RE: create (and keep) a mass measurement using catvba
Lardman is right, you don't need Measurements...but you need to specify from begging your final goal
In catvbs, this is a quick code joined from two different macros without testing and I'm pretty sure can be cleaner. You have also to set to automatically update the formula/parameters in Tools-Options
CODE --> CATVBS
Language="VBSCRIPT" Sub CATMain() Set Doc =CATIA.ActiveDocument ' Get current document Set Part = Doc.Part ' Get the part Set PartBody = Part.MainBody ' Grab the mainbody PartBody.Name = "MAIN_BODY" ' Rename Body 'PartBody.Name = "PartBody" ' Rename Body Set parameters1 = Part.Parameters Set dimension1 = parameters1.CreateDimension("", "VOLUME", 0.000000) dimension1.Rename "VOLUME" Set relations1 = Part.Relations Set formula1 = relations1.CreateFormula("Formule.1", "", dimension1, "smartVolume(`MAIN_BODY` ) ") formula1.Rename "Formule.1" Dim partDocument1 ''As Document Set partDocument1 = CATIA.ActiveDocument Dim part1 ''As Part Set part1 = partDocument1.Part Dim product1 ''As CATBaseDispatch Set product1 = partDocument1.GetItem("MAIN_BODY") Set product1 = product1.ReferenceProduct Dim parameters1 ''As Parameters Set parameters1 = product1.UserRefProperties Dim realParam2 ''As RealParam Set realParam2 = parameters1.CreateReal("volum", VOLUME) realParam2.ValuateFromString VOLUME Dim relations1 ''As Relations Set relations1 = part1.Relations Dim formula2 ''As Formula Set formula2 = relations1.CreateFormula("Formula.5", "", realParam2, "VOLUME " ) formula2.Rename "Formula.5" formula2.Update partDocument1.Update End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: create (and keep) a mass measurement using catvba
Simspec,
You know how you can create a volume parameter and add a formula to measure the SmartVolume of the PartBody? That volume will constantly update as the part updates. You can then manually add density and mass parameters. Then manually write a relation to calculate the mass parameter (m=d*v). Instead of you manually creating the 3 parameters and the relations, you can do it in VBA just like Ferdo shows. These parameters will live in the part and constantly update...no need to run the macro again.
RE: create (and keep) a mass measurement using catvba
Anyway what i am trying to do is upgrade several thousand catparts (some currently being designed and some catalog items) so that they have the same property fields as a Starter.CATPart i have defined.
I am trying to get as much info stored in the catparts rather than have it split between catparts and various spreadsheets, as there have been discrepancies.
The people i am working with are working a file / folder based system with lots of spreadsheets and its a bit of a nightmare.(currently some of them dont even define material or get mass from the Catparts).
If the info comes from the catpart then at least i will know it actually relates to that part when i query it to build boms etc...
So if i add all the info to the catparts i can persuade them to use a single master (the cad) rather than multiple masters (cad, spreadsheet and back of envelope) and it all needs to be done without requiring the cad users to do anything (other than define a material for each catpart).
That is the end goal (for now).
RE: create (and keep) a mass measurement using catvba
Your project has a very large scope; be sure to break it up into manageable portions and take it one step at a time. Work out what you want to do manually in CATIA and figure out if you need Knowledgeware features or VBA, etc.
You may be able to set up a reaction to fire an internal CATScript to recreate the mass formula, to eliminate the "deleted" issue. Or, if volume changes...mass changes so just use a reaction that is triggered when the volume changes and let it do whatever it is you need. It is hard to say without knowing what you need.
To update parts with specific features (geosets, parameters, etc.) you will need VBA to detect if the feature exists, if it does not...make it. Set oSomeFeature = oPart.FindObjectByName("NameOfFeature") is a good way to handle this...as long as the feature you are looking for has a very specific name...so try to name your features in a way that makes them unique. You can also add a hidden parameter when your macro is run to signal it has been updated/has all the correct features...search for just that parameter to see if the part has been updated. If it doesn't exist, make all the features that you need in the part.