I've created my first useful macro which creates a line normal from a multi-section generated surface using a point that has been created along a curve. You need to select the items first with the surface being your first selection. Also, you should have a geometric set called Vectors.
I share this as I struggled to find something that worked, that I understood and therefore modify for my own requirements. Hopefully the below will help point you in the right direction.
If you don't have the same surface or point types as described above check the V5Automation.chm (in your CATIA installation directory) document and search for Hybrid Shapes Automation Objects. You can then swap out hybridShapeLoft and hybridShapePointOnCurve with your specifc hybrid shape type.
As always, if there are any tips on how I could improve things please do let me know.
What's a good way of avoiding being tied down to surface and point types within a macro? IMO the nature of the task means a good script wouldn't care what type of surface or point you have and would be more flexible.
I share this as I struggled to find something that worked, that I understood and therefore modify for my own requirements. Hopefully the below will help point you in the right direction.
If you don't have the same surface or point types as described above check the V5Automation.chm (in your CATIA installation directory) document and search for Hybrid Shapes Automation Objects. You can then swap out hybridShapeLoft and hybridShapePointOnCurve with your specifc hybrid shape type.
Code:
Sub CATMain()
Dim myDocument
Set myDocument = CATIA.ActiveDocument
Dim i As Integer
Dim mySelection As Selection
Set mySelection = myDocument.Selection
Dim ThePart As Part
Set ThePart = myDocument.Part
Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = ThePart.HybridShapeFactory
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = ThePart.HybridBodies
Dim SelectedElement1 As SelectedElement
Set SelectedElement1 = mySelection.Item(1)
Dim hybridShapeLoft1 As hybridShapeLoft
Set hybridShapeLoft1 = SelectedElement1.Value
Dim reference1 As Reference
Set reference1 = ThePart.CreateReferenceFromObject(hybridShapeLoft1)
For i = 2 To myselection.Count
Dim Select2 As SelectedElement
Set SelectedElement2 = mySelection.Item(i)
Dim hybridShapePointOnCurve1 as hybridShapePointOnCurve
Set hybridShapePointOnCurve1 = SelectedElement2.Value
Dim reference2 As Reference
Set reference2 = ThePart.CreateReferenceFromObject(hybridShapePointOnCurve1)
Dim hybridShapeLineNormal1 As hybridShapeLineNormal
Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(reference1, reference2, 15, -15, False)
Set hybridBody1 = hybridBodies1.Item("Vectors")
hybridBody1.AppendHybridShape hybridShapeLineNormal1
ThePart.InWorkObject = hybridShapeLineNormal1
ThePart.Update
Next 'i
End Sub
As always, if there are any tips on how I could improve things please do let me know.
What's a good way of avoiding being tied down to surface and point types within a macro? IMO the nature of the task means a good script wouldn't care what type of surface or point you have and would be more flexible.