Good day to all.
Recently I've been learning to program in catia, and currently occupy a small script. which should create a point between two "geometrical set" groups of points .
In the picture would be "FG2_5_C3" and "Geometrical Set.5". Each group has the same amount of points and I will establish the new "Medium".
Currently from the line:
"Set PNT1 = HBody1.HybridShapes.Item (P1)"
It does not work. I guess I have some error.
My code:
PD. excuse my bad English.
Recently I've been learning to program in catia, and currently occupy a small script. which should create a point between two "geometrical set" groups of points .
In the picture would be "FG2_5_C3" and "Geometrical Set.5". Each group has the same amount of points and I will establish the new "Medium".
Currently from the line:
"Set PNT1 = HBody1.HybridShapes.Item (P1)"
It does not work. I guess I have some error.
My code:
Code:
'##ALGORITMO CATScript
Sub CATMain()
'CREA UN PUNTO INTERMEDIO DE DOS GRUPOS DE GS
'Documento Activo
Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part
If Err.Number <> 0 Then
Message = MsgBox("Este script solo funciona con un CATPart como documento activo", vbCritical, "Error")
Exit Sub
End If
'Selecciona GS1
Dim EnableSelectionFor(0)
EnableSelectionFor(0) = "HybridBody"
' Reset the Selection
Set sSEL = CATIA.ActiveDocument.Selection
' sSEL.Clear
' Define Selection
MsgBox "Seleccione el Geometrical Set dónde están los puntos iniciales"
UserSelection = sSEL.SelectElement2(EnableSelectionFor, "Seleccione otro Geometrical Set", False)
' Evaluation if the selectio is correct or not
If UserSelection <> "Normal" Then
MsgBox "Error con la seleccion"
Exit Sub
Else
'--Guarda nombre t1.N
Set ohybridbody1 = sSEL.Item(1).Value
REM MsgBox ohybridbody1.Name
Dim Sel_count As Selection
Set Sel_count = CATIA.ActiveDocument.Selection
'Busca los puntos en la seleccion
Sel_count.Search "CATPrtSearch.Point,sel"
Dim oCount
oCount = Sel_count.Count2
REM MsgBox "# de rep " & oCount
End If
'Selecciona GS2
EnableSelectionFor(0) = "HybridBody"
' Reset the Selection
Set sSEL2 = CATIA.ActiveDocument.Selection
sSEL2.Clear
' Define Selection
MsgBox "Seleccione el Geometrical Set dónde están los puntos de Finales"
UserSelection = sSEL2.SelectElement2(EnableSelectionFor, "Seleccione otro Geometrical Set", False)
' Evaluation if the selectio is correct or not
If UserSelection <> "Normal" Then
MsgBox "Error con la seleccion"
Exit Sub
Else
'--Guarda nombre t2.N
Set ohybridbody2 = sSEL2.Item(1).Value
' sSEL2.Clear
End If
REM MsgBox ohybridbody2.Name
'Selecciona Ratio
EnableSelectionFor(0) = "Parameter"
' Reset the Selection
Set sSEL3 = CATIA.ActiveDocument.Selection
' sSEL3.Clear
' Define Selection
MsgBox "Seleccione el parametro(Ratio):"
UserSelection = sSEL3.SelectElement2(EnableSelectionFor, "Seleccione otro Parametro", False)
' Evaluation if the selectio is correct or not
If UserSelection <> "Normal" Then
MsgBox "Error con la seleccion"
Exit Sub
Else
'--Guarda nombre Parametro
REM Set oRatio1 = sSEL3.Item(1).Value 'Con esto funcionaba
REM MsgBox oRatio1.Name
Set oRatio1 = sSEL3.Item(1)
REM MsgBox "V " & oRatio1.Value.Value
REM MsgBox "N " & oRatio1.Value.Name
REM MsgBox "VS " & oRatio1.Value.ValueAsString
Dim str_R1
Set str_R1 = "=" & oRatio1.Value.Name
End If
'=============================================
REM MsgBox "El Geometrical Set Inicial es: " & ohybridbody1.Value.Name & Chr(10) & " El Geometrical Set Final es: " & ohybridbody2.Value.Name & Chr(10) & " El Ratio es: " & oRatio1.Value.Name
'=============================================
'-----Ubicacion de intermedios ---------------
Dim WHBody
Dim wrkHBody As HybridBody
'Selecciona GS_Intermedio
EnableSelectionFor(0) = "HybridBody"
' Reset the Selection
Set sSEL4 = CATIA.ActiveDocument.Selection
sSEL4.Clear
' Define Selection
MsgBox "Seleccione el Geometrical Set dónde estaran los puntos intermedios"
UserSelection = sSEL4.SelectElement2(EnableSelectionFor, "Seleccione otro Geometrical Set", False)
' Evaluation if the selectio is correct or not
If UserSelection <> "Normal" Then
MsgBox "Error con la seleccion"
Exit Sub
Else
'--Guarda nombre t3.N
Set ohybridbody3 = sSEL4.Item(1).Value
' sSEL4.Clear
End If
REM MsgBox ohybridbody3.Name
Set WHBody = sSEL4.Item(1) 'ohybridbody3.Name
Set wrkHBody = oPartDoc.HybridBodies.Item(WHBody)
REM MsgBox WHBody.Value.Name ' es = a -3 lineas
'=====Creacion Punto inter ==========
Dim oWork3D As HybridShapeFactory
Set oWork3D = oPartDoc.HybridShapeFactory
'=====GS1============================
Dim GS1, GS2
Dim HBody1 As HibridBody
GS1 = sSEL.Item(1)
Set HBody1 = oPartDoc.HybridBodies.Item(GS1)
'===GS2==============================
Dim HBody2 As HybridBody
GS2 = sSEL2.Item(1)
Set HBody2 = oPartDoc.HybridBodies.Item(GS2)
'Ciclo FOR, i to count =========================
Dim P1, P2, i, T1, T2, Pnt1, Pnt2
Dim Ref1, Ref2 As Reference
Dim oSelec_1 as Selection
Dim oSelec_2 As Selection
Dim Pnt_i As HybridShapePointBetween
REM MsgBox "Num de Rep " & oCount
REM MsgBox "N.Ratio: " & oRatio1.Value.Name
T1 = ohybridbody1.Name
T2 = ohybridbody2.Name
REM MsgBox T1
For i = 1 To oCount
'----Lee T1.N, Busca el nombre GS1
Set oSelec_1 = CATIA.ActiveDocument.Selection
oSelec_1.Search "Name=" & T1 & ",all"
oSelec_1.Search "CATPrtSearch.Point,sel"
'oSelec_1.Item(i).Value.Name
Set P1 = oSelec_1.Item2(i) 'Selecciona Punto1.i
REM MsgBox P1.Value.Name
'----Lee T2.N
Set oSelec_2 = CATIA.ActiveDocument.Selection
oSelec_2.Search "Name=" & T2 & ",all"
oSelec_2.Search "CATPrtSearch.Point,sel"
'---Selecciona Punto2.i
Set P2 = oSelec_2.Item(i)
REM MsgBox P2.Value.Name
'---Puntos Seleccionados
MsgBox "Nombre del punto " & i & " es " & Chr(10) & "Pnt Inicial : " & P1.Value.Name & Chr(10) & "Pnt Final : " & P2.Value.Name
REM OK
'---Crea el Punto Intermedio
Set Pnt1 = HBody1.HybridShapes.Item(P1) '<=============ERROR =================
Set Ref1 = oPartDoc.CreateReferenceFromObject(Pnt1)
Set Pnt2 = HBody2.HybridShapes.Item(P2)
Set Ref2 = oPartDoc.CreateReferenceFromObject(Pnt2)
Set Pnt_i = oWork3D.AddNewPointBetween(Ref1, Ref2, str_R1, 1)
wrkHBody.AppendHybridShape Pnt_i
oPartDoc.InWorkObject = Pnt_i
oPartDoc.Update
'---Limpia Seleccion
Next
'===============================================
End Sub
PD. excuse my bad English.