Catia Macro to automatically measure spline
Catia Macro to automatically measure spline
(OP)
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
Set parameter1 = parameters1.Item("1510005-L1-504\Product Description")
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
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
Set parameter1 = parameters1.Item("1510005-L1-504\Product Description")
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





RE: Catia Macro to automatically measure spline
Best regards,
Costin Ruja
RE: Catia Macro to automatically measure spline
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....
indocti discant et ament meminisse periti
RE: Catia Macro to automatically measure spline
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
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Catia Macro to automatically measure spline
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
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:
I would appeciate the help.
Thank you !
Costin Ruja
Best regards,
Costin Ruja
RE: Catia Macro to automatically measure spline
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.
indocti discant et ament meminisse periti
RE: Catia Macro to automatically measure spline
RE: Catia Macro to automatically measure spline
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 ?
Set parameter1 = parameters1.Item("1510005-L1-504\Product Description")
So in theory i will have to get rid of names and make something general.
Costin
Best regards,
Costin Ruja
RE: Catia Macro to automatically measure spline
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 --> CATScript
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU
RE: Catia Macro to automatically measure spline
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.
Best regards,
Costin Ruja
RE: Catia Macro to automatically measure spline
indocti discant et ament meminisse periti
RE: Catia Macro to automatically measure spline
Thanks !
Best regards,
Costin Ruja
RE: Catia Macro to automatically measure spline
RE: Catia Macro to automatically measure spline
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
RE: Catia Macro to automatically measure spline