Continue to Site

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!

Assign array to selection

Status
Not open for further replies.

Gilgamesh99

Automotive
Jun 11, 2013
45
MX
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:
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):

VBA said:
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.

 
Replies continue below

Recommended for you

Combining the codes...

Code:
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

 
THANKS A LOT for the code!!!. The good thing is that I think Im improving.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top