×
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

Assign array to selection

Assign array to selection

Assign array to selection

(OP)
Hi:

Working with the centerpoint extractor (Place Points in a tube macro post). I figured out how to get the edges and filter them (assigning them to an array). The issue now is that I cannot assign the filtered array to the selection in order to create the points. This is the code that Im using:

CODE --> VBA

Sub CATMain()
 
Dim productDocument1
Set productDocument1 = CATIA.ActiveDocument

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1
Set partDocument1 = documents1.Item(1)

Dim part1 As Part
Set oPart = CATIA.ActiveDocument.Part

Dim reference1 As Reference
Set oHSF = oPart.HybridShapeFactory
 
'===========================================================
 
Dim objSel As Selection
Set objSel = CATIA.ActiveDocument.Selection
objSel.Search ("Type=Edge,Selection_BorderREdge")
objcount = objSel.Count

'MsgBox objcount

Dim i As Integer
Dim InputObject(99)
Dim InputObject2(99)
Dim j As Integer

'MsgBox objSel.Count
For i = 1 To objSel.Count
InputObject(i) = objSel.Item(i).Value.Name

 If (InStrRev(InputObject(i), "Selection_REdge", -1) = 1) Then
     'MsgBox "The current edge is a BorderREdge"
        
        For j = 1 To 1
        
        InputObject2(j) = InputObject(i)
        MsgBox InputObject2(j)

     Next j
     
     End If
     
    
Next i 

The code to create the points was provided by ferdo (CATIA portable script center V2.0):

Quote (VBA)

Dim oCentre
Set oCentre = CATIA.ActiveDocument.Selection

Dim j As Integer
For j = 1 To (objSel.Count)
Set otemp = oCentre.Item(j)
Set oRef = otemp.Reference
Set oPoint = oHSF.AddNewPointCenter(oRef)
'Set oHB = oPart.HybridBodies.Add()
oPoint.Compute
oHB.AppendHybridShape oPoint
Next j

'objSel.Clear

Unfortunately this last portion of code only works with a selection and I dont find the way either to assign the array InputObject2 to the selection or replace the selection with the InputObject2.

At this point I tried everything to get this task accomplished but every effort of mine seems to be useless.

RE: Assign array to selection

Combining the codes...

CODE --> CATScript

Sub CATMain()
 
REM Works in an active CATPart
REM You need a geometrical set named "Points" to be already created 
 
Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part    
If Err.Number <> 0 Then                   
Message = MsgBox("Sorry, This script works with a CATPart as Active document, so please open CATPart in a new window", vbCritical, "Error")
Exit Sub
End If
 
Dim  productDocument1 As ProductDocument
Set productDocument1 = CATIA.ActiveDocument
 
Dim documents1 As Documents
Set documents1 = CATIA.Documents
 
Dim partDocument1 As PartDocument
Set partDocument1 = documents1.Item(1)
 
Set oPart = CATIA.ActiveDocument.Part 

Dim objSel As Selection
Set objSel = CATIA.ActiveDocument.Selection
objSel.Search ("Type=Edge,Selection_BorderREdge")
objcount = objSel.Count
 
Dim i As Integer
Dim InputObject(99)
Dim InputObject2(99)
Dim j As Integer
Dim oCentre
For i = 1 To objSel.Count
InputObject(i) = objSel.Item(i).Value.Name
 If (InStrRev(InputObject(i), "Selection_REdge", -1) = 1) Then
 
Set oHSF = oPart.HybridShapeFactory
Set oCentre = CATIA.ActiveDocument.Selection.Item(i)
 
Set oTemp = oCentre 
Set oRef = oTemp.Reference
Set oPoint = oHSF.AddNewPointCenter(oRef)
Set oHB = oPart.HybridBodies.Item("Points")
oPoint.Compute
oHB.AppendHybridShape oPoint
''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
End If
Next

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

RE: Assign array to selection

(OP)
THANKS A LOT for the code!!!. The good thing is that I think Im improving.

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