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:
The code to create the points was provided by ferdo (CATIA portable script center V2.0):
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.
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
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 SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Assign array to selection