Continue to Site

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!

create (and keep) a mass measurement using catvba

Status
Not open for further replies.

simspec

Automotive
Sep 10, 2013
5
GB
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?
 
Replies continue below

Recommended for you

Unfortunately not. This gives a static measurement (you have to rerun it everytime you change the body to get the updated value).
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).
 
Perhaps you can create a volume parameter and measure the volume of the part. Create a density parameter and have the user input the density (unless you can harvest from a material) then add a mass parameter to calculate mass using density and volume. This can all be done in VBA.
 
How do i setup a volume measurement in vba (that wont require someone to run a macro to update the volume value when the body gets changed)?

I thought volume was part of the InertiaVolume measurement?
 
In the event you are unaware, if you are in VBA and you type a CATIA specific word like "Parameter", double-click it to highlight it, then press F1 on your keyboard, it will open CATIA Specific help about that topic. You can also search once help is open.

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")


 
But these are still static values arent they? When the volume of the body changed the macro would have to be run again to update the values?

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.
 
Hi,

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:
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 Sub

Regards
Fernando

- Romania
- EU
 
Thanks Ferdo for the extra codes.

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.
 
Yes that is correct, but i have just found that when someone changes the material the density in the formula changes to density_DELETED and the mass does not update anymore (i also dont think the people i work with would actually know how to correct the formula or would bother to). (Measurements can cope with changes of material or no material without needing to be fixed so i would prefer to use them if i can)

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).
 
Perhaps it would be best to post a detailed, bullet-list explanation of what you are trying to accomplish and where you plan on harvesting data from (I.e. Density).

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top