Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Hello Guys, I have a trouble her

Status
Not open for further replies.

Kikoupe

Mechanical
Jul 7, 2021
17
0
0
FR
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...


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
 
Replies continue below

Recommended for you

Hi,

Well you gave us no error message...

But...
Code:
'
    ReDim cog(2)
    USel.Item(i).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

[b]set refObject = USel.Item(i)[COLOR=#EF2929].Value[/color][/b]    
'...

Notice that variable [tt]i[/tt] is outside the For...Next loop. Therefore the LeafProduct method has an undefined Item value.

ALSO, why Redim and GetCOG TWICE?

ALSO, you never Set an Object to a Value. It's an OBJECT!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Hi guys,

Thaks for the support, I change the code, my mistake i paste the code i was working on but nothing change i have a error on the leafproduct method...

Why it's work on the product and not on the part ?

what is the code to select the part from the edge/curve selection and get the COG ?
Thanks :)
 
Code:
Dim prd as Product
Dim partDocument1 as PartDocument
If TypeName(CATIA.ActiveDocument) = "PartDocument" then
  Set prd = CATIA.ActiveDocument.Product
  Set partDocument1 = CATIA.ActiveDocument
Else
  Set prd = CATIA.ActiveDocument.Selection.Item(1).LeafProduct
  Set partDocument1 = prd.ReferenceProduct.Parent
End if
 
Status
Not open for further replies.
Back
Top