Distance entre deux objets

Distance entre deux objets - VB/VBA/VBS - Programmation

Marsh Posté le 24-02-2014 à 14:53:48    

bonjour tout le monde!
 
je voulais créer une macro en vbs sous catia! dont elle mesure la distance entre un point appartenant à une piece et un plan appartenant à une autre piece!
j'ai developpé ce bout de code!  :??:  
 
Sub CATMain()
 
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
 
Dim documents1 As Documents
Set documents1 = CATIA.Documents
 
Dim partDocument1 As Document
Set partDocument1 = documents1.Item("piece1.CATPart" )
 
Dim part1 As Part
Set part1 = partDocument1.Part
 
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
'****
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Construction " )
 
Dim hybridShapes1 As HybridShapes
Set hybridShapes1 = hybridBody1.HybridShapes
 
Dim hybridShapePointCenter1 As HybridShape
Set hybridShapePointCenter1 = hybridShapes1.Item("Point.1" )
 
Dim partDocument2 As Document
Set partDocument2 = documents1.Item("piece2.CATPart" )
 
Dim part2 As Part
Set part2 = partDocument2.Part
 
Dim originelements2 As OriginElements
Set originelements2 = part2.OriginElements
 
Dim reference1 As Reference
Set reference1 = originelements2.PlaneXY
msgbox(reference1.Name)
 
part2.Update
'******
 
Dim TheSPAWorkbench As SPAWorkbench
Set TheSPAWorkbench = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench" )
 
Dim Measurable1 As Measurable
Set Measurable1 = TheSPAWorkbench.GetMeasurable(hybridShapePointCenter1)
 
Dim Measurable2 As Measurable
Set Measurable2 = TheSPAWorkbench.GetMeasurable(reference1)
 
Dim distance As Variant
distance = Measurable2.GetMinimumDistance(hybridShapePointCenter1)
 
MsgBox "distance du 1er pt " & distance & " "
 
End Sub
 
mais ce dernier donne des fausses données!  
en fait il mesure la distance entre le point1 de la 1ere piece et le plan xy de la meme piece!!!
merci bien :)

Reply

Marsh Posté le 24-02-2014 à 14:53:48   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed