Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Catvba Edge fillet on Y direction 4

Status
Not open for further replies.

TudorM

Automotive
Mar 30, 2020
99
0
6
AT
Hello guys , i am trying to get the edges on Y direction and to fillet them , i found some info on other forum and trying to combine but i am getting an eror and do not know how to solve it , please help :
Captureghfghgfhf_wsiqbu.jpg


the error is on refEdge.GetDirection dir

Here is the full code :

Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part


Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search ("Topology.CGMEdge,sel")

Dim Num_edges1 As Integer
Num_edges1 = selection1.Count

Dim edges_ref() As Reference

ReDim edges_ref(1 To Num_edges1)

Dim i

For i = 1 To Num_edges1

Dim refEdge As Edge
Set refEdge = selection1.Item(i).Reference

Dim dir(1)

refEdge.GetDirection dir

Debug.Print dir(0) & " / " & dir(1) & " / " & dir(2)

If dir(1) = 1 Then

Set edges_ref(i) = selection1.Item(i).Reference
End If

Next


Dim oEdgeFillet1 As ConstRadEdgeFillet
Set oEdgeFillet1 = part1.ShapeFactory.AddNewEdgeFilletWithConstantRadius(edges_ref(1), 1, 3)

For i = 2 To Num_edges1
oEdgeFillet1.AddObjectToFillet edges_ref(i)
Next

oEdgeFillet1.Radius.Value = 3
oEdgeFillet1.EdgePropagation = 1
part1.Update

End Sub
 
Replies continue below

Recommended for you

i like the attitude... star from me.

Not everybody would ask to wait to post solution so they can search and learn...

Tell me when or show me your working code

Eric N.
indocti discant et ament meminisse periti
 
a little hint:
For i = 2 To Num_edges1
If Not edges_ref(i) Is Nothing Then oEdgeFillet1.AddObjectToFillet edges_ref(i)​
Next

regards,
LWolf
 
LWolf thank you for hint , but i think it confused me even more , cause i do not want to be nothing in edges_ref , i want to add in them only the dir"direction". Something like 'itsmyjob said " to keep only those wich i want....
i appreciate your sugestion as well thank you !

Guys, could you give me a reference script, please, maybe from ferdo portable script suggestion so at least i know where to look ?
 
go one step at a time.

you search for edges : done

you need to filter out the edge that are not along Y and also maybe some other edges not from the solid that could be in Y direction... maybe you put them in a new array or you remove the other one from the array you already have.

arrays are tricky to manage when you don't know how many element you have to manage. You can use Collection to replace array if you want. read this

once you have an array or a collection with just the edge to fillet you go to next step: do the fillet on each edge.

Eric N.
indocti discant et ament meminisse periti
 
watch out I had to change some element as I am working with 3DX21X

Code:
Sub CATMain()
    
    [COLOR=#73D216]' get myPart[/color]
    Dim myPart As Part
    Set myPart = CATIA.ActiveEditor.ActiveObject
    
    [COLOR=#73D216]' get selection object[/color]
    Dim selection1 As Selection
    Set selection1 = CATIA.ActiveEditor.Selection
    [COLOR=#73D216]
    ' search all edge in part[/color]
    selection1.Search ("Topology.CGMEdge,in")
    
    [COLOR=#73D216]' loop all selection[/color]
    For i = 1 To selection1.Count
    
        [COLOR=#73D216]' get edge from selection[/color]
        Dim myEdge As Edge
        Set myEdge = selection1.Item(i).Value

        [COLOR=#73D216]' get edge Dir[/color]
        Dim dir(2)
        myEdge.GetDirection dir
        
        [COLOR=#73D216]' for info[/color]
        Debug.Print dir(0) & " / " & dir(1) & " / " & dir(2)
        
        [COLOR=#73D216]' checking if dir is along Y and also that edge is not from sketch[/color]
        If Abs(dir(1)) = 1 And InStr(1, TypeName(myEdge), "monodim", vbTextCompare) = 0 Then
            myPart.ShapeFactory.AddNewSolidEdgeFilletWithConstantRadiusmyEdge,  catTangencyFilletEdgePropagation , 3
        End If
    
    Next
    
    myPart.Update

End Sub

Eric N.
indocti discant et ament meminisse periti
 
when i select edges from my part I will find edge of solid, surfaces and wire frame... I did not try to put too much in my code but what you can do is do a first selection of the mainBody, then search in that selection, limiting the number of edges you find. But still you might have edges from sketches. That's why I remove them by checking the TypeName of the edge. I let you use Debug.Print or use the Locals to find out more about typename of edge.

best file to work with is the help file : DSYAutomation.chm in your install/code/bin folder.

also it's strange but I pass the edge and not a reference to the fillet function and it works...

I am using AddNewSolidEdgeFilletWithConstantRadius as AddNewEdgeFilletWithConstantRadius is deprecated

Eric N.
indocti discant et ament meminisse periti
 
Thank you itsmyjob , i will try to see what happens.
Sorry LWolf i had a wrong virtaul intonation yesterday just was mad cause didn't get this . I think i will ask for some lessons from someone to get more into the things and not to bother anyone.

Regards,
Tudor
 
Hi

To help you more, I just took Eric's code and translate it to V5 in vba (I have access to both versions and it was easy to do the translation)

Code:
Sub CATMain()
    
    ' get myPart
    Dim myPart ''As Part
     Set myPart = CATIA.ActiveDocument.Part
    
    ' get selection object
    Dim selection1 ''As Selection
    Set selection1 = CATIA.ActiveDocument.Selection
    
    ' search all edge in part
    selection1.Search ("Topology.CGMEdge,in")
    
    ' loop all selection
    For i = 1 To selection1.Count
    
        ' get edge from selection
        Dim myEdge As Edge
        Set myEdge = selection1.Item(i).Value
        

        ' get edge Dir
        Dim dir(2)
        myEdge.GetDirection dir
        
        ' for info
        Debug.Print dir(0) & " / " & dir(1) & " / " & dir(2)
                Dim MyFillet As ConstRadEdgeFillet
        ' checking if dir is along Y and also that edge is not from sketch
        If Abs(dir(1)) = 1 And InStr(1, TypeName(myEdge), "monodim", vbTextCompare) = 0 Then
            MsgBox myEdge.Name
            Set MyFillet = myPart.ShapeFactory.AddNewSolidEdgeFilletWithConstantRadius(myEdge, 1, 3)
        End If
    
    Next
    
    myPart.Update

End Sub

You can learn more if you will look in documentation also, I just commented few lines to make it work for my CATIA setup

Code:
Option Explicit
' COPYRIGHT DASSAULT SYSTEMES 2000
Dim Language As String
Language="VBSCRIPT"

' ****************************************************************************
'   Purpose     :  Create two EdgeFillet on the vertical edges of a pad
'                  and on the top and bottom faces
'
'   Author      :
'   Languages   :  VBScript
'   Locales     :  English
'   CATIA Level :  V5R6
'*****************************************************************************

Sub CATMain()

    
    '~ Dim sDocPath As String
    '~ sDocPath=CATIA.SystemService.Environ("CATDocView")

    '~ Dim oPartDocument As PartDocument
    '~ Set oPartDocument = CATIA.Documents.Open(sDocPath & "\online\CAAScdPriUseCases\samples\Pad.CATPart")

    Dim oPart As Part
    Set oPart =  CATIA.ActiveDocument.Part

    '~ ' Retrieve the part body of the document containing the pad to be used
    '~ Dim oBody As Body
    '~ Set oBody = oPart.Bodies.Item  ( "MechanicalTool.1" ) 

    ' Retrieve the pad of the body
    Dim oPad As Pad
    Set oPad = oBody.Shapes.Item  ( "Pad.1" )

    ' Retrieve the vertical edges of the pad to be filleted
    Dim oEdge1 As Reference
    Set oEdge1 = oPart.CreateReferenceFromBRepName  ( "REdge:(Edge:(Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;1)));None:());Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;2)));None:());None:(Limits1:();Limits2:()));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport)", oPad ) 

    Dim oEdge2 As Reference
    Set oEdge2 = oPart.CreateReferenceFromBRepName  ( "REdge:(Edge:(Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;2)));None:());Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;3)));None:());None:(Limits1:();Limits2:()));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport)", oPad ) 

    Dim oEdge3 As Reference
    Set oEdge3 = oPart.CreateReferenceFromBRepName  ( "REdge:(Edge:(Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;3)));None:());Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;4)));None:());None:(Limits1:();Limits2:()));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport)", oPad ) 

    Dim oEdge4 As Reference
    Set oEdge4 = oPart.CreateReferenceFromBRepName  ( "REdge:(Edge:(Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;4)));None:());Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;1)));None:());None:(Limits1:();Limits2:()));WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport)", oPad ) 

    ' Define the fillet to be created with the first edge
    Dim oEdgeFillet1 As ConstRadEdgeFillet
    Set oEdgeFillet1 = oPart.ShapeFactory.AddNewEdgeFilletWithConstantRadius  ( oEdge1, 1, 5.000000 ) 

    ' Add the others edges to be filleted 
    oEdgeFillet1.AddObjectToFillet oEdge2
    oEdgeFillet1.AddObjectToFillet oEdge3
    oEdgeFillet1.AddObjectToFillet oEdge4

    ' Define the fillet radius to 5 mm
    oEdgeFillet1.Radius.Value = 5.000000

    ' Define the fillet to be propagated to all the tangent contiguous edges
    oEdgeFillet1.EdgePropagation = 1

    ' Update the document
    oPart.Update

    ' Retrieve the top face of the pad to be filleted
    Dim oTopFace As Reference
    Set oTopFace = oPart.CreateReferenceFromBRepName  ( "RSur:(Face:(Brp:(Pad.1;2);None:());WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport)", oEdgeFillet1 ) 

    ' Retrieve the bottom face of the pad to be filleted 
    Dim oBottomFace As Reference
    Set oBottomFace = oPart.CreateReferenceFromBRepName  ( "RSur:(Face:(Brp:(Pad.1;1);None:());WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport)", oEdgeFillet1 ) 

    ' Define the fillet to be created with the first face
    Dim oEdgeFillet2 As ConstRadEdgeFillet
    Set oEdgeFillet2 = oPart.ShapeFactory.AddNewEdgeFilletWithConstantRadius  ( oTopFace, 1, 15.000000 )

    ' Define the fillet radius to 5 mm
    oEdgeFillet2.Radius.Value = 5.000000

    ' Add the other face
    oEdgeFillet2.AddObjectToFillet oBottomFace

    ' Update the document
    oPart.Update

End Sub

Looking at what you were telling about lessons...this will be a little bit difficult in Romania if you want a more advanced level...and I suppose most of the peoples here learned scripting by themselves...looking in docs and forums, at least this was my case.

Now, for what you want with this script, here is another example from Dieter Zahner, one of the best book authors for CATIA scripting in my opinion. When you will have time, try to modify these scripts and see what you can obtain...

Code:
' Version:                1.0
' Code:                CATIA CATScript
' Zweck:                Beispiel fur die Erzeugung mehrerer Verrundungen in einer Operation
' Vorbereitung: 
'							- neues CATPart
'							- im Hauptkorper einen Block "Pad.1" erzeugen
'							- Skizze liegt auf XY-Ebene und ist ein Rechteck
' Autor:                Dieter Ziethen

CATIA.StatusBar = "CATScript, Version 1.0"

Sub CATMain ()

' korper deklarieren und in Bearbeitung setzen ---------------------
Dim Bauteil As Part
Set Bauteil = CATIA.ActiveDocument.Part
Dim MBody As Body
Set MBody = Bauteil.Mainbody
Bauteil.InWorkObject = MBody

' Referenzen deklarieren -------------------------------------------
Dim Block As AnyObject
Set Block = MBody.Shapes.Item ("Pad.1")
Dim Face(4), Edge(4), REdge(4), Ref(4), I, II, S, RefL

For I = 1 To 4
        Face(I) = "Face:(Brp:(Pad.1;0:(Brp:(Sketch.1;" & I & ")));None:())"
Next

For I = 1 To 4
        II = I + 1
        If II > 4 Then II = 1
        Edge(I)= "Edge:(" & Face(I) & ";" & Face(II) & ";None:(Limits1:();Limits2:()))"
Next

S = "WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport"

For I = 1 To 4
        REdge(I) = "REdge:(" & Edge(I) & ";" & S & ")"
        Set Ref(I) = Bauteil.CreateReferenceFromBRepName (REdge(I), Block)
Next

Set RefL = Bauteil.CreateReferenceFromName ("")

' Werkzeugkasten deklarieren ---------------------------------------
Dim Wzk3D As ShapeFactory
Set Wzk3D = Bauteil.ShapeFactory

' Verrundung mit Leerreferenz erzeugen und Kanten erganzen ---------
Dim Rundung As ConstRadEdgeFillet
Set Rundung = Wzk3D.AddNewSolidEdgeFilletWithConstantRadius (RefL, 1, 10)

For I = 1 To 4
        Rundung.AddObjectToFillet Ref(I)
Next

Bauteil.Update

End Sub



Regards
Fernando

 
I learned a lot this couple of days from this script and from all the info shared,need to keep up wih searching and trying more .

The script is working well , i just need to improve a little to put all edges in one edge fillet 'probably i need to declare a reference and to use Addobjecttofillet, but i will figure out myself , huge thank you to all!!!
 
Hi

I am trying to use Surface Edge Fillet in my coding. I have a trimmed two intersecting surfaces and need to use "Surface edge fillet" on intersecting edge. I tried to use that coding mentioned above with bit modification but it does not work. Could you please help me how to do surface edge fillet between two intersecting surfaces?

Thanks.
 
Above are several codes and who knows wich one you used and what you modified, could you post it to see where is problem ?
 
Did you try to record a macro?
Are you working with two Surfaces or with two faces of a solid?

Plz make a new Thread if you want to work with surfaces.

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