1

I working with CATscript in CATIA to create Macros. I am trying to create a CATscript to translate a feature in CATIA.

When I run the CATscript I Should select the feature that should be translated and and the feature will be translated.

But I am getting an runtime error Type mismatch:'part1.CreateReferenceFromObject'

I could not find the solution for this problem. Looking forward for your help.

Thanks in Advance.

   Sub CATMain()

  Set partDocument1 = CATIA.ActiveDocument
  Set part1 = partDocument1.Part

  Set hybridShapeFactory1 = part1.HybridShapeFactory
  Set hybridShapeDirection1 =        hybridShapeFactory1.AddNewDirectionByCoord(1.000000, 0.000000, 0.000000)
  Set hybridShapeTranslate1 = hybridShapeFactory1.AddNewEmptyTranslate()


Set UserSel = partDocument1.Selection
Dim type1(0)
    type1(0) = "HybridShape"
    '--------------------------------------

    'Dim input As Object
    input = UserSel.SelectElement2(type1, "select input.", False)

 Set reference1 = part1.CreateReferenceFromObject(input)
 hybridShapeTranslate1.ElemToTranslate = reference1

  hybridShapeTranslate1.Direction = hybridShapeDirection1
   hybridShapeTranslate1.DistanceValue = 1.000000
   Set hybridBody2 = hybridBodies1.Item("Geometrical Set.3")

hybridBody2.AppendHybridShape hybridShapeTranslate1

part1.InWorkObject = hybridShapeTranslate1

part1.Update 

End Sub
FunThomas
  • 23,043
  • 3
  • 18
  • 34
user3714887
  • 77
  • 3
  • 16

1 Answers1

1

your problem is that you are trying to create a reference from a Selection object.

input = UserSel.SelectElement2(type1, "select input.", False)

This returns the type Selection. You can dig into the input and get the actual object that you select.

try:

Dim myReference as Reference
Dim myExpectedObject as HybridShape 'or use variant
Set mySelectedObject = input.Item2(1).Value 'this will grab the first item from the selection collection
set myReference = part1.CreateReferenceFromObject(mySelectedObject)
'continue the rest of your code

Also, you should always clear the selection before you use a user selection as a good habit.

UserSel.Clear 'call this before you call a SelectElement selection function
GisMofx
  • 982
  • 9
  • 27