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!

VB Macro get line parent from a selected rib, measure it

Status
Not open for further replies.

Pierre Hubert

New member
Mar 29, 2019
1
FR
Hello,

I have a big hydraulic circuit in a CATpart where every pipe are made with a rib.
Pipe_with_rib_yksbtc.png

I'm working on a macro but I'm really newbie in VB for Catia. The aims of this macro are:
-Renumber the ribs and their parent lines
-Measure the lines lengths in X, Y and Z directions
-Export these data to an excel sheet

By now, I only succeed to renumber the ribs.
I don't succeed to modify the parent line number.

Could you help me please?

Thank you

Here is my code

Code:
Public oList As Variant

Option Explicit

Sub CATMain()
On Error Resume Next

'Declarations
Dim MyDoc As Document
Dim oTopProd As ProductDocument
Dim oCurrentPart As Part
Dim oCurrentProd As Product
Dim n As Integer


'Check if the active document is a Part, else exit
Set MyDoc = CATIA.ActiveDocument

 If MyDoc Is Nothing Then
        MsgBox "Must have a Part open"
        Exit Sub
    End If
   
If Right(MyDoc.Name, 7) <> "CATPart" Then
    MsgBox "Active document should be a CATPart"
    Exit Sub
End If


Set oCurrentPart = MyDoc.Part

Set oList = CreateObject("Scripting.dictionary")


CATIA.StatusBar = "Working On" & " " & oCurrentPart.Name


On Error Resume Next

Dim varFilter(1) As Variant
Dim objSel As Selection
Dim objSelLB As Object
Dim strReturn, strMsg, Index_ini, Answer As String
Dim end_flag As Boolean
Dim i, objcount As Integer
Dim myrib
Dim visProperty

Index_ini = InputBox("Renseigner le numéro du premier élément à renuméroter :") '"Give the number of the first element
MsgBox "Sélectionner les éléments à numéroter (l'ordre de sélection est important!)" '"Select the first element to renumber (be careful the sequence matter!)

varFilter(0) = "Rib"
varFilter(1) = "Rib"            'Doesn't work with only one

Set objSel = CATIA.ActiveDocument.Selection
Set objSelLB = objSel
objSel.Search ("Name=Nervure*,all")
myrib = objSel.Item2(1).Value.Name
objcount = objSel.Count
MsgBox myrib

end_flag = 0
i = Index_ini

    While end_flag = False
    
    strMsg = "Select a rib"
    objSel.Clear
    strReturn = objSelLB.SelectElement2(varFilter, strMsg, False)
    'myrib(0) = objSel.FindObject("CATIARib")
    
    If strReturn = "Normal" Then
       If objSel.Count2 > 0 Then
            myrib = objSelLB.Item(1).Value.Name
            MsgBox myrib
            objSel.Item2(1).Value.Name = "Nervure." & i
            objSel.Search ("Name=Nervure*,all")
       End If
   End If
'get the line associate to this rib
'set mymeas = SPAWorkbench.GetMeasurable(line)
'length=mymeas.
'export each rib/line number and the associated measurement in a xls file

    
    Answer = MsgBox("Avez vous d'autres éléments à renuméroter", vbQuestion + vbYesNo, "On continue?") '"Do you have more elements to renumber?
    If Answer = vbNo Then
        end_flag = True
    End If
    i = i + 1
    Wend
    

MsgBox "Done"

End Sub


Pierre
 
Replies continue below

Recommended for you

according to v5automation.chm a rib object is a subclass of the sweep object

sweep.CenterCurveElement returns or set the center curve as Reference...

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top