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!

Catia Macro to automatically measure spline

Status
Not open for further replies.

Costin Ruja

Electrical
Oct 19, 2011
87
RO
Good morning all !

So I made some formula (with the help of you guys) to measure some splines.It works perfectly but now I need to somehow automate the process.Not really knowing programming and stuff I just pushed the record macro button and all seemed OK. I just need to fill in the Part Description field with this formula:

"L="+ToString((1+int(((MeasureEdge.1\Length/1mm)+15/100*(MeasureEdge.1\Length/1mm))/50))*50)+"mm"

With the script that Catia has recorded, the output is like this

Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim relations1 As Relations
Set relations1 = part1.Relations

Dim parameters1 As Parameters
Set parameters1 = part1.Parameters

Dim parameter1 As Parameter
[highlight #EF2929]Set parameter1 = parameters1.Item("1510005-L1-504\Product Description")[/highlight]

Dim formula1 As Formula
Set formula1 = relations1.CreateFormula("Formula.2", "", parameter1, "" & """" & "L=" & """" & "+ToString((1+int(((MeasureEdge.2\Length/1mm)+15/100*(MeasureEdge.2\Length/1mm))/50))*50)+" & """" & "mm" & """" & "")

formula1.Rename "Formula.2"

End Sub


The error is in line 18, I think because this line contains the name of the part in which the script was recorded.

How can I get rid of this error and make the macro working for arbitrary parts ?

Have a nice weekend,

Costin



Best regards,
Costin Ruja
 
Replies continue below

Recommended for you

And I also saw that the macro doesn't record the operation of measuring the spline. Is this some kind of a bug ?

Best regards,
Costin Ruja
 
can you explain the big picture of what you're trying to do?

the script should create a parameter based on the length of a spline? How many spline you want to measure. why do you need this parameter?

I'm asking just to make sure we go in the right direction...

you script does use a measureedge, not sure this is the best solution....


Eric N.
indocti discant et ament meminisse periti
 
Hi

Try to avoid specific names, this is what is happening when you record macro. On recorded macro, you have to eliminate those parts of the code which is referring to specific names or specific instances in a part. You can force user to select what you want (eventually rename with a specific name if you need that) and then refer to that selection.

Indeed, more details will help us to understand what you want, Eric is right.

Regards
Fernando

- Romania
- EU
 
Good morning !

In principle , I have some splines that represent electrical conductors (no harness license here, just GSD). Finally, there should be some kind of length measured so the worker in the factory knows how to cut those wires. By trial and error over the years, we managed to translate this in a formula, the spline measured in Catia plus 15%, and rounded upwards to 50mm.

You can find below a picture
Capture_j1iqjf.jpg


The blue and the yellow wires are separate parts, each containing just a spline. The goal is to retrieve this length information in the drawing BOM, so when I modify the model or modify the path of the conductor, this also reflects in the BOM.

This works ok doing it manually with every spline part, just masuring the spline with "measure item", and then going to formula editor and entering the formula by hand.

I want to automate this and just open the spline part in a separate window and run a macro that measures the spline, applies the formula, and puts this information in the "product description" field, like in the image below:

Capture2_uxfakh.jpg


I would appeciate the help.

Thank you !

Costin Ruja



Best regards,
Costin Ruja
 
powa copy !

I have the feeling a nice powercopy could do the job. with reaction so if length change, description would be updated.

input could be geomset, part or curve as you said only one curve in part so a Part->Query would find the curve...

you can create length parameter using length(curve) that would make it associative, you can include also your magic in the formula or create a second length parameter link with the first one so you could have real length and BOM length as parameters.

then a reaction based on geometry updated that would update Description based on BOM length parameter.

I would use this as once it is instantiated in the part, any update of the part would not require any action as it would update by itself.

you might need some KWE/KWA license don't know exactly which one to create the reaction.

Eric N.
indocti discant et ament meminisse periti
 
Oooookkk,

So I managed to measure the spline correctly with "length(`Geometrical Set.1\Spline.1')" and not with the measure tool.

How do I manage to make the script to not refer to the current part ?

[highlight #EF2929]Set parameter1 = parameters1.Item("1510005-L1-504\Product Description")[/highlight]

So in theory i will have to get rid of names and make something general.
Costin

Best regards,
Costin Ruja
 
If you want to get the name of a selection (first one, lets suppose you push the user to select something) you can use

MySel.item(1).value.name

Lets say you are in a product and want to find the name of a selected part....be aware that you need something else depending how you are working (file system, PDM, v5 , v6....)

Code:
Sub CATMain()
Dim InputObjectType(0)

Set MySel = Catia.Activedocument.Selection
 InputObjectType(0)="Part"
 Status=MySel.SelectElement2 (InputObjectType, "Select any Object, you will get just Part",true)
 if (Status = "Cancel") or( status="Undo") then
    MySel.clear
 Else
     MsgBox MySel.item(1).value.name
End IF

MySel.clear

End Sub

Regards
Fernando

- Romania
- EU
 
@itsmyjob, powa copy saved my life :))

Sooooo, after some half a day fiddling with "powa copy", I managed to get the job done let's say 90%.

For the remaining 10% i need the help of you guys.

You can find attached the original power copy file with all the stuff needed.To make it work you just need a spline and a point.

The hard part is still self referral.
I am trying to fill in the Product Description field with "lungime_aproximata" parameter.
This works perfect in the original (model_conductor) part, but when I try to instance the power copy, everything is ok, except for formula 13.This is happening because "model_conductor" is still in the formula, a thing which now doesn't exist.

How do I get over this, so the formula retrieves the correct part name (the current part name), like this:

Formula.13:'part_xxx\Product Description'=lungime_aproximata

and not like this

Formula.13:'model_conductor\Product Description'=lungime_aproximata

Any help appreciated.

Capture_movkxk.jpg








Best regards,
Costin Ruja
 
like i said I would use reaction to update the description... do you have KWE / A license?

Eric N.
indocti discant et ament meminisse periti
 
Yes ! I do have it, it's knowledge advisor.And I already found the reaction button.Right now i'm looking for some details on how to use this.

Thanks !

Best regards,
Costin Ruja
 
Wait so you've got Knowledge Advisor, yet your employer is too cheap to buy the Electrical Harness licenses? I think this thread sums up perfectly the old Deming saying of: "We are being ruined by best efforts of people who are doing the wrong thing." You clearly are doing a lot of work trying to come up with a solution for your problems here, but the right solution would be to just buy the Electrical Harness licenses. And the further you delve into Macro's and Reactions and Parameters, the harder it will be to ever make that call.
 
@Belgiancadengineer

This is quite ok for us, let's say this stimulates our imagination. The very shitty part is that our company belongs to a group that uses Solidedge for their design work in a few weeks we will have to comply to their workflow. Think about using Catia for about 8 years and then going to Solidedge...

Best regards,
Costin Ruja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top