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!

Catia VBA Intersection Loop 2

Status
Not open for further replies.

Costeldvd

Automotive
Mar 12, 2018
5
RO
Hi, I want to create a series of intersections that have as input references the result of 2 iterations.

More concrete i have 2 geometrical sets ("Geometrical set A", "Geometrical set B"), with a series of n elements. In both sets the number of elements are the same. What i want to do is select the first geometrical set and then the second, and after that i want the macro to make intersections between elements in this way: first element from "Geometrical set A" with the first from the "Geometrical set B", second element from "Geometrical set A" with the second from the "Geometrical set B", and so on, until the end of the selection.



Thank you for future help! :)
 
Replies continue below

Recommended for you

How far have you gotten so far? What is not working?

regards,
LWolf
 
please share your progress, we will help you get there.
it's not difficult, so even if you're a beginner, don't be afraid.

Eric N.
indocti discant et ament meminisse periti
 
Hello, at this moment my macro looks like this:
_____________

Private Sub CommandButton5_Click()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody2 As HybridBody
Set hybridBody2 = hybridBodies1.Add()

hybridBody2.Name = "Intersections internal EDGES"

Dim hybridShapeBoundary1 As HybridShapeBoundary

Dim InputObjectType(0)
Dim SearchSelection As Selection

Dim reference As reference

Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim s As Integer
Dim q As Integer

Dim BoundarySelection1 As Selection
Set BoundarySelection1 = partDocument1.Selection
BoundarySelection1.Search "Name=Complete Boundary from Design Explode,all"
Set hybridBody1 = BoundarySelection1.Item2(1).Value
BoundarySelection1.Search "CATGmoSearch.GSMBoundary,sel"
Dim reference10 As reference

For s = 1 To BoundarySelection1.Count

Set reference10 = part1.CreateReferenceFromObject(BoundarySelection1.Item2(s).Value)

Dim BoundarySelection2 As Selection
Set BoundarySelection2 = partDocument1.Selection
BoundarySelection2.Search "Name=Complete Boundary on Join,all"
Set hybridBody1 = BoundarySelection2.Item2(1).Value
Dim reference11 As reference


BoundarySelection2.Search "CATGmoSearch.GSMBoundary,sel"

For q = 1 To BoundarySelection2.Count

Set reference11 = part1.CreateReferenceFromObject(BoundarySelection2.Item2(q).Value)

Dim hybridShapeIntersection1 As HybridShapeIntersection
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference10, reference11)

hybridShapeIntersection1.PointType = 0

hybridBody2.AppendHybridShape hybridShapeIntersection1

part1.InWorkObject = hybridShapeIntersection1

part1.Update

Next
Next

End Sub

________

At this moment it make intersection with first element from first loop and every element from second loop. what is strange is that at the end of iteration it creates 2 aditional intersects that have update problem.


Catia that i use: Catia V5 R23

Thanks!
 
as you want to intersect groupA.item(1) with groupB.item(1)...groupA.item(n) with groupB.item(n), you only need one loop.
Code:
For [COLOR=#EF2929]s[/color] = 1 To BoundarySelection1.Count

[...]
Set reference10 = part1.CreateReferenceFromObject(BoundarySelection1.Item2([b][COLOR=#EF2929]s[/color][/b]).Value)

[...]
Set reference11 = part1.CreateReferenceFromObject(BoundarySelection2.Item2([b][COLOR=#EF2929]s[/color][/b]).Value)

[...]

next

Eric N.
indocti discant et ament meminisse periti
 
Thank you itsmyjob![thumbsup]
This was the a thing that i did not knew.
I've tested your suggestion and it works flawless.
Lower you can find the final structure of the loop.
Thank you all for replying!
_____________________________
Dim s As Integer

Dim BoundarySelection1 As Selection
Set BoundarySelection1 = partDocument1.Selection
BoundarySelection1.Search "Name=Complete Boundary from Design Explode,all"
Set hybridBody1 = BoundarySelection1.Item2(1).Value
BoundarySelection1.Search "CATGmoSearch.GSMBoundary,sel"


For s = 1 To BoundarySelection1.Count

Dim BoundarySelection3 As Selection
Set BoundarySelection3 = partDocument1.Selection
BoundarySelection3.Search "Name=Complete Boundary from Design Explode,all"
Set hybridBody1 = BoundarySelection3.Item2(1).Value
BoundarySelection3.Search "CATGmoSearch.GSMBoundary,sel"

Dim reference10 As reference
Set reference10 = part1.CreateReferenceFromObject(BoundarySelection1.Item2(s).Value)



Dim BoundarySelection2 As Selection
Set BoundarySelection2 = partDocument1.Selection
BoundarySelection2.Search "Name=Complete Boundary on Join,all"
Set hybridBody1 = BoundarySelection2.Item2(1).Value
BoundarySelection2.Search "CATGmoSearch.GSMBoundary,sel"
Dim reference11 As reference

Set reference11 = part1.CreateReferenceFromObject(BoundarySelection2.Item2(s).Value)


Dim hybridShapeIntersection1 As HybridShapeIntersection
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference10, reference11)


hybridShapeIntersection1.PointType = 0

hybridBody2.AppendHybridShape hybridShapeIntersection1

part1.InWorkObject = hybridShapeIntersection1

Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top