×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATIA VBA: Increase JOIN speed

CATIA VBA: Increase JOIN speed

CATIA VBA: Increase JOIN speed

(OP)
Hello. I've created a CATVBA program that finds all the edges of a surface and then joins them together. The problem is if there are 700 edges (a medium sized part) then it takes 5 - 10 minutes for the macro to run as it adds all the edges one by one. Is there any way to increase the speed so it runs faster? Most of my code is shown below:

CODE --> VBA

Sub CATMain()
 Dim colDocum As Documents
 Dim DocActivo As Document
 Dim part1 As Part
 Dim colBodies As Bodies
 Dim hSFact As Factory
 Dim colHBody As HybridBodies
 Dim OpenBody1 As HybridBody
 Dim sStatus As String
 Dim MySelection As Selection
 Dim InputObjectType(0)
 
 InputObjectType(0) = "HybridShapeAssemble"
 Dim refBorde As Reference

 Set DocActivo = CATIA.ActiveDocument
 Set part1 = DocActivo.Part
 Set MySelection = DocActivo.Selection
 Set hSFact = part1.HybridShapeFactory
 Set colBodies = part1.Bodies
 
Dim dummy
Set dummy = MySelection

Dim Result As String
Result = dummy.SelectElement2(InputObjectType, "Select a face", False)

    If (sStatus = "Cancel") Then
     Exit Sub
    End If

 Set refBorde = MySelection.Item(1).Value
 Dim hybridShapeExtract1 As HybridShapeExtract
 Set hybridShapeExtract1 = hSFact.AddNewExtract(refBorde)
     hybridShapeExtract1.PropagationType = 3
     hybridShapeExtract1.ComplementaryExtract = False
     hybridShapeExtract1.IsFederated = False
 Set refBorde = hybridShapeExtract1
 hybridShapeExtract1.Name = "Extracted_Face"

 ''''' Create Open Body
 Dim HB1 As HybridBodies
 Set HB1 = CATIA.ActiveDocument.Part.HybridBodies
 Dim Hierarchie1, ImKoerper As HybridBody
 Set Hierarchie1 = HB1.Add
 Hierarchie1.Name = "Extracted_Elements"
 ''''''''
 Set colHBody = part1.HybridBodies
 Set OpenBody1 = part1.InWorkObject
 OpenBody1.AppendHybridShape hybridShapeExtract1
 part1.InWorkObject = hybridShapeExtract1

 part1.Update


dummy.Clear
dummy.Add hybridShapeExtract1

 Dim partDocument1 As Document
 Set partDocument1 = CATIA.ActiveDocument

 Dim selection1 As Selection
 Set selection1 = partDocument1.Selection

 selection1.Search "Topology.CGMEdge,sel"

     MsgBox selection1.Count2 & " Edges are found from the selected face"
  
     
Dim HSF1 As HybridShapeFactory
Set HSF1 = part1.HybridShapeFactory
Dim myedge
Dim myEdge2
Dim myEdgeRef As Reference
Dim myEdgeRef2 As Reference


'--if only one surface 
If selection1.Count = 1 Then

   Set myedge = selection1.Item(1)
     Set myEdgeRef = myedge.Reference

Dim hybridShapeAssemble1 As HybridShapeAssemble
Set hybridShapeAssemble1 = HSF1.AddNewJoin(myEdgeRef, myEdgeRef)

OpenBody1.AppendHybridShape hybridShapeAssemble1
part1.InWorkObject = hybridShapeAssemble1
part1.Update

hybridShapeAssemble1.RemoveElement 2



Else

'---if exactly two surfaces------------

   Set myedge = selection1.Item(1)
   Set myEdge2 = selection1.Item(2)
    Set myEdgeRef = myedge.Reference
    Set myEdgeRef2 = myEdge2.Reference

Set hybridShapeAssemble1 = HSF1.AddNewJoin(myEdgeRef, myEdgeRef2)

hybridShapeAssemble1.SetConnex 0
hybridShapeAssemble1.SetManifold 0
hybridShapeAssemble1.SetSimplify 0
hybridShapeAssemble1.SetSuppressMode 0
hybridShapeAssemble1.SetDeviation 0.001
hybridShapeAssemble1.SetAngularToleranceMode 0
hybridShapeAssemble1.SetAngularTolerance 0.5
hybridShapeAssemble1.SetFederationPropagation 0

OpenBody1.AppendHybridShape hybridShapeAssemble1
part1.InWorkObject = hybridShapeAssemble1
part1.Update
'join complete if only 2 surfaces

'if more than 3 surfaces, need to add each surface one by one

If selection1.Count > 2 Then

Dim i As Integer


For i = 3 To selection1.Count

Set myedge = selection1.Item(i)
Set myEdgeRef = myedge.Reference
   

hybridShapeAssemble1.AddElement myEdgeRef

Next

Else

End If
End If

hybridShapeAssemble1.Name = "EdgeJoin"
selection1.Clear
part1.Update
MsgBox "JOIN Success!"
End 

RE: CATIA VBA: Increase JOIN speed

Hi,

Let us know more. The time is long when you extract the edges? Or in join operation ?

I modified a bit the code and put AnyObject instead of HybridShapeAssemble , I don't know how is looking your part (maybe you can upload a sample, doesn't meter the release, I have access to all DS products - but I don't know to use all of them bigsmile ).

I know the first part of the code but that was done only to extract one surface and the edges. What is your goal? Do you want to extract all edges on the part and after that to join all of them?

I done a test with this scenario and to extract more then 1300 edges took me almost 4 minutes and after that joining them it was easy to do it.

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: CATIA VBA: Increase JOIN speed

(OP)
Sorry, I should have listed out all the steps to make the purpose of the program more clear. Here are the steps:

1. Run the program
2. User selects a Join surface in the CATPart
3. Macro searches for all edges of the selected surface and selects them (1000 edges takes around 20 seconds to select them all)
4. Macro creates a new join geometry by assembling all the edges together in one join operation (1000 edges takes about 15 minutes to add to the join, sometimes errors out before finish versus manual join operation takes only a couple of seconds)
5. Measure the length of the Join created in step 4 using a length parameter (does not matter if cannot get the join created faster).

RE: CATIA VBA: Increase JOIN speed

Quote (you)

Macro searches for all edges of the selected surface

you need internal edges also? Cause if you don't just do a boundary function from the surface.

Also working with selection has never been a fast way in CATIA, sadly I do not know if topology edges could be found without selection.

on another topic, I recently used ms timer in a script to find out what exactly was slow

I used the code from Mike Woodhouse on stackoverflow

You can start as many counter a you like and get the timeelapsed from start on each one...

if you need the JOIN just to measure it and its creation take 15', maybe you could measure each edge, it might be faster? Measurable object work with Reference, and you can get it from Selection.Item(i).Reference...
With the above counter you can check if adding an edge to the JOIN is faster or slower than getting its measure.

with something like

CODE --> code

for i = 1 to selection1.count
set theMeasurable = spawb.GetMeasurable (oSel.item(i).Reference)
totalLength = totalLength + theMeasurable.Length
next i 

if you need the JOIN, then maybe create an EXTRACT from each edge and JOIN them... check time to see the more efficient way...or create extract from selected face and copy in new file, save a iges an play with iges format to get curve.






Eric N.
indocti discant et ament meminisse periti

RE: CATIA VBA: Increase JOIN speed

(OP)
Yes, I need all edges including internal edges.

I tried deleting the JOIN step as you suggested and it does help some. The search for edges step (selection1.Search "Topology.CGMEdge,sel") is usually pretty quick, less than 15 seconds.

Just adding up the length of the edges using Measurable object work with Reference seems to work very quick for some parts but not for others (some parts around 1min, others 10+ minutes). If I copy and paste the surface into a brand new part as a dead surface, it seems to work the fastest but does add that additional step that is not desirable.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources