Continue to Site

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!

Macro for normal to surface lines 3

Status
Not open for further replies.

macocata

Aerospace
Oct 29, 2012
3
RO
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?
 
Replies continue below

Recommended for you

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.
 
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

 
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,
 
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:
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.
 
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. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor