Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro generation in Catia V5

Status
Not open for further replies.
Jan 24, 2008
5
0
0
IN
Hello all,

how to create a macro in catia V5 to generate equi distance multiple points on 2 ends of curve(spline) to a specified distance (approx 8mm).

Thanks in advance for your reply.


Regards

SK
 
Replies continue below

Recommended for you

Hi SK,
below is an example which creates equidistant points (4 of them at 8 mm) from the beginning of a curve in a drawing. Create a view where the first (or only) element is 2D curve like a spline, line, etc., activate the view and launch a macro.

Code:
Sub EquidistantPoints()
    Dim myView As DrawingView
    Set myView = CATIA.ActiveDocument.Sheets.ActiveSheet.Views.ActiveView
    
    Dim fact2D As Factory2D
    Set fact2D = myView.Factory2D
    
    Dim myCurve
    Set myCurve = myView.GeometricElements.Item(2)
    
    Dim paramExtents(1)
    myCurve.GetParamExtents paramExtents
    
    Dim curveLength As Double
    curveLength = myCurve.GetLengthAtParam(paramExtents(0), paramExtents(1))
    
    Dim dist, distances()
    distances = Array(8, 16, 24, 32)
    
    For Each dist In distances
        Dim pointParam As Double
        pointParam = myCurve.GetParamAtLength(paramExtents(0), dist)
        
        Dim myPoint(1)
        myCurve.GetPointAtParam pointParam, myPoint
        
        fact2D.CreatePoint myPoint(0), myPoint(1)
    Next
End Sub

EquidistantPoints_gsocoe.png


Hope it helps,

Tesak
- Play Tetris in CATIA V5 drawing
 
Hi Tesak,

Good Morning,

Thanks for your Reply. But I need to export points from 3D model Space for a spline data to do some dimensional analysis. I tried with this code and I could not get them.

Can you Please help me.

Regards
Saravana
 
Then you can use something like the code below:

Code:
Sub EquidistantPoints3D()
    Dim partDoc As PartDocument
    Set partDoc = CATIA.ActiveDocument
    
    Dim activePart As Part
    Set activePart = partDoc.Part
    
    ' change it as you need, to properly identify your body
    Dim myHybridBody As HybridBody
    Set myHybridBody = activePart.HybridBodies.Item("Geometrical Set.1")
    
    Dim hsFactory As HybridShapeFactory
    Set hsFactory = activePart.HybridShapeFactory
    
    ' change it as you need, to properly identify your spline
    Dim myCurve As HybridShapeSpline
    Set myCurve = myHybridBody.HybridShapes.Item("Spline.1")
    
    Dim ref As Reference
    Set ref = activePart.CreateReferenceFromGeometry(myCurve)
    
    Dim dist, distances()
    distances = Array(8, 16, 24, 32)
    
    For Each dist In distances
        Dim pt As HybridShapePointOnCurve
        Set pt = hsFactory.AddNewPointOnCurveFromDistance(ref, dist, True)
        
        myHybridBody.AppendHybridShape pt
    Next
End Sub

If you adjust it to your needs, you should get 4 equidistant points.

EquidistantPoints3D_eqtbhl.png


Tesak
- Play Tetris in CATIA V5 drawing
 
Hi Tesak, Good Morning,

Actually there was a change of scope, I tried to get this weekend but I was not getting the right method to do, so contacting you again. can you please help me.

I am here with attaching the presentation and cat model.

Thanks for your time. as just now I have started I need to understand more.

Regards
Saravana

 
 https://files.engineering.com/getfile.aspx?folder=914caced-e7b9-4c04-b0af-4edc726b323e&file=CATIA_VB.zip
Status
Not open for further replies.
Back
Top