Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA V5 VBA Code Efficiency Renumbering Constraints 1

Status
Not open for further replies.

AeroTD

Aerospace
Feb 25, 2022
4
I know the following is NOT the most efficient method but I'm having a hard time finalizing the code even though I'm sure it's simple enough. I would appreciate 1. some feedback to eliminate the specific text (eg: Fix., Coincidence., Offset.) with a variable 2. I've had success calling the renumbering code as a sub routine but pulled it out for testing.

Option Explicit
Sub CATMain()

Dim osel As Selection
Dim i As Integer

Set osel = CATIA.ActiveDocument.Selection

osel.Search "(Name='Fix.*' & CATAsmSearch.MfConstraint),in"
For i = 1 To osel.Count
osel.Item(i).Value.Name = "Fix." & i
Next 'i

osel.Clear

osel.Search "(Name='Coincidence.*' & CATAsmSearch.MfConstraint),in"
For i = 1 To osel.Count
osel.Item(i).Value.Name = "Coincidence." & i
Next 'i

osel.Clear

osel.Search "(Name='Offset.*' & CATAsmSearch.MfConstraint),in"
For i = 1 To osel.Count
osel.Item(i).Value.Name = "Offset." & i
Next 'i

osel.Clear

End Sub

Thank you!
 
Replies continue below

Recommended for you

Do you really need to differentiate between different type of constraints? Can't you just use a single oSel.Search "CATAsmSearch.MfConstraint,all" search call to renumber all constraints at once?
 
I'm open to selecting all the constraints, BUT then I need assistance to search the string only to the character "." and remove anything after. The current code would result in "Fix.11" versus "Fix.1". Easy in excel, but not so much in CATIA.
 
Use [tt]Split(name, ".")[/tt] and extract first part from the result:

Code:
Option Explicit
Sub CATMain()
  CATIA.HSOSynchronized = false

  Dim osel As Selection
  Set osel = CATIA.ActiveDocument.Selection
  osel.Search "CATAsmSearch.MfConstraint,in"

  Dim i As Integer
  For i = 1 To osel.Count
    osel.Item(i).Value.Name = Split(osel.Item(i).Value.Name, ".")(0) + CStr(i)
  Next
  osel.Clear

  CATIA.HSOSynchronized = true
End Sub
 
Thank you! I was trying to use "InStr" with no success.

To complete the script, I updated to add the "." back into the name:

Code:
Sub CATMain()
  CATIA.HSOSynchronized = False

  Dim osel As Selection
  Set osel = CATIA.ActiveDocument.Selection
  osel.Search "CATAsmSearch.MfConstraint,in"

  Dim i As Integer
  For i = 1 To osel.Count
    osel.Item(i).Value.Name = Split(osel.Item(i).Value.Name, ".")(0) + "." & CStr(i)
  Next
  osel.Clear

  CATIA.HSOSynchronized = True
  
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor