Hi all,
Two months ago I began to use CATIA, so it was already time to get into a forum .
I've been struggling with a vba code that creates intersections between lines and solids: the .part file I am working with contains a geometrical set with lines and several bodies that form a single structure. Each body contains a single solid element. All lines begin on a common point located in space (outside the structure) and end on a solid surface point (there are about 1000 points spreaded over the surfaces of the solid elements).
What I would like to know is if a line intersects with the structure (all bodies) at some point, just wether the line intersects or not. I tried to create those intersections but unfortunately I am always getting problems with the "part.Update" and intersections are not created properly. Even if they are not created properly, I can check if the line intersects or not as I am getting an error. But the problem is that all end line points ending in one of the solid surfaces will always intersect (the solution will be the very end point located on the surface of the solid). I do not want to consider that type of points as intersections, just the intersections created when the lines passes through the solid, so in order to discriminate those, I was comparing the coordinates of the intersection point with the ending line point and check if they were the same, thing that I can no longer apply as intersections are not well created.
Having Bodies splitted by pads, holes.. gives me no problems when creating intersections. However, having a "solid" element makes my code get errors when creating them.
Hope you can help me! Thanks!
Two months ago I began to use CATIA, so it was already time to get into a forum .
I've been struggling with a vba code that creates intersections between lines and solids: the .part file I am working with contains a geometrical set with lines and several bodies that form a single structure. Each body contains a single solid element. All lines begin on a common point located in space (outside the structure) and end on a solid surface point (there are about 1000 points spreaded over the surfaces of the solid elements).
What I would like to know is if a line intersects with the structure (all bodies) at some point, just wether the line intersects or not. I tried to create those intersections but unfortunately I am always getting problems with the "part.Update" and intersections are not created properly. Even if they are not created properly, I can check if the line intersects or not as I am getting an error. But the problem is that all end line points ending in one of the solid surfaces will always intersect (the solution will be the very end point located on the surface of the solid). I do not want to consider that type of points as intersections, just the intersections created when the lines passes through the solid, so in order to discriminate those, I was comparing the coordinates of the intersection point with the ending line point and check if they were the same, thing that I can no longer apply as intersections are not well created.
Having Bodies splitted by pads, holes.. gives me no problems when creating intersections. However, having a "solid" element makes my code get errors when creating them.
Hope you can help me! Thanks!
Code:
Function Create_Intersection(objPart, part, parts, partcount1, j)
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part.HybridShapeFactory
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item(partcount1)
Set objHShape = objPart.HybridBodies.Item(partcount1).HybridShapes.Item(j)
Dim reference1 As Reference
Set reference1 = objPart.CreateReferenceFromObject(objHShape)
Dim bodies1 As Bodies
Set bodies1 = part.Bodies
For l = 2 To part.Bodies.Count
Dim body1 As Body
Set body1 = bodies1.Item(l)
Dim shapes1 As Shapes
Set shapes1 = body1.Shapes
Dim solid1 As Solid
Set solid1 = shapes1.Item(1)
Dim reference2 As Reference
Set reference2 = part.CreateReferenceFromObject(solid1)
Dim hybridShapeIntersection1 As HybridShapeIntersection
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference1, reference2)
hybridShapeIntersection1.PointType = 0
hybridBody1.AppendHybridShape hybridShapeIntersection1
part.InWorkObject = hybridShapeIntersection1
part.Update
Next
Create_Intersection = True
End Function