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?
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
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
RE: Macro for normal to surface lines
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
RE: Macro for normal to surface lines
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Macro for normal to surface lines
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
Is difficult to say what is not working for you...are you using CATScript or catvba?
Did you respect the GS structure ? How is looking ? Normally should work, no matter which CATIA release is.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro for normal to surface lines
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 SubThanks for any help.
RE: Macro for normal to surface lines