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!

Use Step Product file in scripting references??

Status
Not open for further replies.

Charlie

Mechanical
Dec 28, 2015
15
0
0
IN
I have a step product file containing two products 1 & 2.
product1 contains a hole. Now, i want to add a product 3 in which a hole is made concentric with this hole.
i write following program to excess cylinderical hole surface but it gives error.
Can anyone help that how to access this .

Sub

Dim products1 As Products
Set products1 = CATIA.ActiveDocument.Product.Products

'Add new part to product
Dim product2 As Product
Set product2 = products1.AddNewComponent("Part", "")

Dim PartNumber As String
PartNumber = product2.PartNumber & ".CATPart"

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.Documents.Item(PartNumber)

Dim part1 As part
Set part1 = partDocument1.part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")

part1.InWorkObject = body1

Dim hybridShapeFactory1 As Factory
Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim Selection1 As selection
Set Selection1 = partDocument1.selection

Dim selection
Set selection = Selection1

Dim InputObjectType(0), Status

InputObjectType(0) = "CylindricalFace"
Status = selection.SelectElement2(InputObjectType, "Select a Cylindrical Face:", True)

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromName(CylindricalFace.Name) 'showing Error

Dim hybridShapePlaneOffset1 As HybridShapePlaneOffset
Set hybridShapePlaneOffset1 = hybridShapeFactory1.AddNewAxisLine(reference1)

part1.Update

End Sub

I want to use this axis to concentric making of hole feature.
it gives error.Is there another better method.
I also want to use plane in product2 as a limit.
but same problem for creation of reference for plane.
Any suggestion would be great Help.
 
Replies continue below

Recommended for you

CylindricalFace.Name this is your error.

The CylindricalFace object is not defined.

the face is in the selection.item(1) oject.

you can create the reference with the following:

Code:
Set reference1 = partDocument1.selection.item(1).reference

also:
Code:
Dim selection
Set selection = Selection1

is not nice as Selection is a catia object. you should not create object with name already used by CATIA.

and also:

you get the status in the following line
Code:
Status = selection.SelectElement2(InputObjectType, "Select a Cylindrical Face:", True)

but you don't check the status before using the resulting selection... ?!? what if the user press "Cancel"?

Eric N.
indocti discant et ament meminisse periti
 
I have made all the corrections you suggested but still showing error,"method Addnewaxisline failed".
My new programchanged part is as:

Dim Selection1 As selection
Set Selection1 = partDocument1.selection

Dim selection2
Set selection2 = Selection1

Dim InputObjectType(0), Status
InputObjectType(0) = "CylindricalFace"
Status = selection2.SelectElement2(InputObjectType, "Select a Cylindrical Face:", True)

Dim reference1 As Reference
Set reference1 = Selection1.Item2(1).Reference

Dim hybridShapeAxis1 As HybridShapeAxisLine
Set hybridShapeAxis1 = hybridShapeFactory1.AddNewAxisLine(reference1)
body1.InsertHybridShape hybridShapeAxis1

part1.InWorkObject = hybridShapeAxis1
part1.Update
 
seems like hybridShapeFactory1 is not defined

check catiav5automation.chm in order to define HybridShapFactory (or google it)

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.
Back
Top