Kikoupe
Mechanical
- Jul 7, 2021
- 17
Hello Guys,
I have a trouble here... One year ago I posted this topic and it was OK. I've got a code working well but now it's did not work at all.. could you guys help ?
I have a error on the leafproduct method...
I have a trouble here... One year ago I posted this topic and it was OK. I've got a code working well but now it's did not work at all.. could you guys help ?
I have a error on the leafproduct method...
Code:
Option Explicit
Sub CATMain()
Dim USel As Selection
Dim USelLB
Dim InputObject(0)
Dim oStatus
Dim i As Integer
Dim sName As String
InputObject(0) = "AnyObject" 'selection filter forces user to select specific objects, AnyObject allows selection of any object
Set USel = CATIA.ActiveDocument.Selection
Set USelLB = USel
MsgBox "Please select fix points." & vbCrLf & "Select a curve only !" & vbCrLf & "Presse escape to cancel the process."
USel.Clear 'clear the selection before making a selection
oStatus = USelLB.SelectElement3(InputObject, "Select objects to list names", True, CATMultiSelTriggWhenUserValidatesSelection, False)
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = "Here the result"
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
If (oStatus = "Cancel") Then 'User hit esc on keyboard
MsgBox "Macro canceled by user"
Exit Sub
Else 'Loop through selected objects and list names
'----------------------------'
i=1
Dim doc: set doc = USel.Item(i).LeafProduct.ReferenceProduct.Parent
Dim meas: set meas = doc.GetWorkbench("SPAWorkbench").GetMeasurable(refObject)
ReDim cog(2)
USel.Item(1).LeafProduct.GetTechnologicalObject("Inertia").GetCOG cog
'ReDim cog(2)
'USel.Item(i).LeafProduct.GetTechnologicalObject("Inertia").GetCOG cog
'----------------------------'
For i = 1 To USel.Count
Dim refObject as Reference
set refObject = USel.Item(i).Value
sName = USel.Item(i).Value.Name
sName = Replace(sName, "Selection_", "")
'MsgBox (sName)
Dim hybridShapePointCenter1 As HybridShapePointCenter
Set hybridShapePointCenter1 = hybridShapeFactory1.AddNewPointCenter(refObject)
hybridBody1.AppendHybridShape hybridShapePointCenter1
hybridShapePointCenter1.Name = "Point " & i
'MsgBox hybridShapePointCenter1.Name
part1.InWorkObject = hybridShapePointCenter1
part1.Update
Next
End If
msgbox "ok"
USel.Clear
End Sub