×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Macro for normal to surface lines
3

Macro for normal to surface lines

Macro for normal to surface lines

(OP)
Hi,

I want to create a macro with the next structure:
Input: a geometrical set which contains a surface and a lot of points (200 up to 1000 points)
Output: a new geometrical set that contain normal to input surface through each input point

I have already done a the next script.
I have to specify that in my geometrical set the surface is on the firs position of selection and after that are those points.
My macro fails at the red line, if I replace parameters1.Item(1) with parameters1.Item("surface_name") it works, but i want to make the macro for any different surfaces names.

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set selection1 = partDocument1.Selection

selection1.Search "(CATGmoSearch.Surface + CATGmoSearch.Point),sel"

Set part1 = partDocument1.Part

Set hybridShapeFactory1 = part1.HybridShapeFactory

Set parameters1 = part1.Parameters

Set hybridShapeSurfaceExplicit1 = parameters1.Item(1)

Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")

Set hybridShapes1 = hybridBody1.HybridShapes

Dim i As Integer

For i = 2 To selection1.Count

Set hybridShapePointOnSurface1 = hybridShapes1.Item(i)

Set reference2 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)

Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, -15#, 15#, False)

hybridBody1.AppendHybridShape hybridShapeLineNormal1

part1.InWorkObject = hybridShapeLineNormal1

part1.Update

Next i

End Sub

So any idea?

RE: Macro for normal to surface lines

Hi,

You can try in your selection to rename first the surface with what name you want (eventually you can setup a counter) or you can try to use references.

An old macro doing same thing is here

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: Macro for normal to surface lines

(OP)
Thank Ferdo for your help, but I don't want to rename the surface for the simple fact that I can have 2 or 3 different geometrical sets where to create those lines and every time I will have to change names in script or in Catia. Please help me to debug that red line so that the macro can recognize and create lines on the first surface from the selected geometrical set.

RE: Macro for normal to surface lines

My suggestion is to get the name of the surface in the GS (if you don't want t change the name), something like bellow

selection1.Search "(CATGmoSearch.Surface + CATGmoSearch.Point),sel"
surfaceforlines = selection1.Item(1).Value.Name
MsgBox surfaceforlines

then change the red line with

Set hybridShapeSurfaceExplicit1 = parameters1.Item(surfaceforlines)

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: Macro for normal to surface lines

(OP)
Thank you, it works now properly.

RE: Macro for normal to surface lines

Hi, in my case it doesn´t work, fail at line "Dim i As Integer"
I have hundred of copied and linked points in a geoset, I have introduced the surface into the geoset in the first position and introduced the name of the surface inside the text but it doesn´t work. I tried to use Ferdo´s modification on the script but it also fails
I am using V5R20
Can you help me?I am not so familiar with those scripts
Regards,

RE: Macro for normal to surface lines

Hi,

I'm very new to scripting in CATIA but I was hoping to gain some help to get the above working. I've had to make some changes to get it progress a little further without erroring ...

1. Add a ' to Next line at the end of the script.
2. Changed Set hybridShapePointOnSurface1 = hybridShapes1.Item(i) to Set hybridShapePointOnSurface1 = parameters1.Item(i) (I couldn't get Ferdo's suggestion to work).

When I run the script the correct surface and points are highlighted. But, how would I modify the script to use a multisection generated surface and points drawn along a curve? After much head scratching I've realised that if I convert these to explicit entities the script runs fine.


CODE --> CATScript

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set selection1 = partDocument1.Selection
Set part1 = partDocument1.Part
Set hybridShapeFactory1 = part1.HybridShapeFactory
Set parameters1 = part1.Parameters

selection1.Search "(CATGmoSearch.Surface + CATGmoSearch.Point),sel"
surfaceforlines = selection1.Item(1).Value.Name
MsgBox surfaceforlines

Set hybridShapeSurfaceExplicit1 = parameters1.Item(1)

Set reference1 = part1.CreateReferenceFromObject(hybridShapeSurfaceExplicit1)

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Item("Vectors")

Set hybridShapes1 = hybridBody1.HybridShapes

Dim i As Integer

For i = 2 To selection1.Count

Set hybridShapePointOnSurface1 = parameters1.Item(i)

Set reference2 = part1.CreateReferenceFromObject(hybridShapePointOnSurface1)

Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, -15, 15, False)

hybridBody1.AppendHybridShape hybridShapeLineNormal1

part1.InWorkObject = hybridShapeLineNormal1

part1.Update

Next 'i

End Sub 

Thanks for any help.

RE: Macro for normal to surface lines

Made some typo's for my changes at item 2 but can't edit. I'll leave it at that for now as it's probably not important right now and I can't edit. :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources