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!

Macro to measure lenght

Status
Not open for further replies.

TiagoFigueiredo

Industrial
May 22, 2013
494
PT
I everyone,

Once again i need some help in a macro to measure the lenght of some lines.

I have found a macro that almost suits what i need, is located in the following thread:


I was trying to reply in the thread, but i don't know why, it wasn't allowed.

My problem is the following. Using the macro located in that thread, i have writed this macro:

Sub CATMain()



Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Coordenadas")

Dim hybridShapes1 As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes

Dim hybridShapePolyline1 As HybridShapePolyline
Set hybridShapePolyline1 = hybridShapes1.Item(6)


Dim hybridShapePolyline2 As HybridShapePolyline
Set hybridShapePolyline2 = hybridShapes1.Item(7)



'---- End resolution script

Dim referenceObject1 As Reference
Set referenceObject1= hybridShapePolyline1
Dim TheSPAWorkbench As Workbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench")


Dim TheMeasurable1 As Measurable
Set TheMeasurable1 = TheSPAWorkbench.GetMeasurable(referenceObject1)



Dim referenceObject2 As Reference
Set referenceObject2= hybridShapePolyline2


Dim TheMeasurable2 As Measurable
Set TheMeasurable2 = TheSPAWorkbench.GetMeasurable(referenceObject2)

MsgBox TheMeasurable1.Length

MsgBox TheMeasurable2.Length

TheMeasurable1.Clear

End Sub



The macro works, but it's strange how it works. The first time that i use it (when I start computer), it works, but the second time doesn't, and in some times it works. i have no way to explain this.

When the macro doesn't work it makes a error on the follwing line:

MsgBox TheMeasurable2.Length

Can you try to help me?

The CATIA is in attachment.

Best regards
 
Replies continue below

Recommended for you

Hi,

The part is not in attachment but I found it on COE. The problem is that you are using Item(6) and Item(7) which means in other words "measure the item number 6 and 7 in the Geometrical Set named Coordenadas" ....well, is very possible that you will not have those items in another part ....so you need to write something general not so particular, for example choose in a selection (picked by user) to measure....there are several examples here in the forum.

This is happening generally when you are recording macros and don't modify them after that according to a general purpose.

The other thread is closed, that's why you can't use it.

Regards
Fernando

 


Hello,

My idea is to assemble this macro in another one that creates that 2 lines. My problem ocours with just this CATPart open.

But i don't understand why some times works, and another times doesn't. But allways same Catpart same geométric posicion same lines and positions.
 
Wouldn't you need to set the reference like this:
Set referenceObject2 = CreateReferenceFromObject( hybridShapePolyline2)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top