LWolf (Automotive)
16 Oct 20 10:00
jzecha...
here are my premises:
I have a set with points called HoleCenterPoints, located directly under part.
I have an empty body called Holes (holes will end up here)
I have an empty set called Hole_References (line normal to surface and plane normal to curve will be added here for each HoleCenterPoint-point).
My surface is a dead one, i.e. a parameter... called InputSurface (I tested the script on a sphere)
Parameters of the holes are metric, you will need to change it according to your needs.
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim Sel As Selection
Set Sel = partDocument1.Selection
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As hybridBodies
Set hybridBodies1 = part1.hybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.item("Hole_References")
part1.InWorkObject = hybridBody1
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim parameters1 As Parameters
Set parameters1 = part1.Parameters
Dim hybridShapeSurfaceExplicit1 As HybridShapeSurfaceExplicit
Set hybridShapeSurfaceExplicit1 = parameters1.item("InputSurface")
Dim hybridBody2 As HybridBody
Set hybridBody2 = hybridBodies1.item("HoleCenterPoints")
Dim myHybridShape As HybridShape
Dim coord(2)
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.item("Holes")
For Each myHybridShape In hybridBody2.HybridShapes
myHybridShape.GetCoordinates coord
Dim hybridShapeLineNormal1 As HybridShapeLineNormal
Set hybridShapeLineNormal1 = hybridShapeFactory1.AddNewLineNormal(hybridShapeSurfaceExplicit1, myHybridShape, 0, 20, False)
Dim hybridShapePlaneNormal1 As HybridShapePlaneNormal
Set hybridShapePlaneNormal1 = hybridShapeFactory1.AddNewPlaneNormal(hybridShapeLineNormal1, myHybridShape)
hybridBody1.AppendHybridShape hybridShapePlaneNormal1
part1.InWorkObject = hybridShapePlaneNormal1
part1.UpdateObject hybridShapePlaneNormal1
part1.InWorkObject = body1
Dim shapeFactory1 As ShapeFactory
Set shapeFactory1 = part1.ShapeFactory
Dim hole1 As Hole
Set hole1 = shapeFactory1.AddNewHoleFromPoint(coord(0), coord(1), coord(2), hybridShapePlaneNormal1, 10)
hole1.Type = catSimpleHole
hole1.AnchorMode = catExtremPointHoleAnchor
hole1.BottomType = catVHoleBottom
Dim limit1 As Limit
Set limit1 = hole1.BottomLimit
limit1.LimitMode = catOffsetLimit
Dim length1 As Length
Set length1 = hole1.Diameter
length1.Value = 10
Dim angle1 As Angle
Set angle1 = hole1.BottomAngle
angle1.Value = 120
hole1.SetDirection hybridShapeLineNormal1
hole1.ThreadingMode = catSmoothHoleThreading
hole1.ThreadSide = catRightThreadSide
part1.UpdateObject hole1
Sel.Clear
Sel.Add hybridShapePlaneNormal1
Sel.Add hybridShapeLineNormal1
Set visPropertySet1 = Sel.VisProperties
visPropertySet1.SetShow 1
Next
End Sub
regards,
LWolf