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!

select a hole

Status
Not open for further replies.

mayrou

Electrical
Jan 8, 2014
55
0
0
TN
hi!
i want to create a macro that select a hole in a product
i developed this macro

Code:
MsgBox "selectionnez un trou"
Dim InputObjectType(0), Status1
InputObjectType(0)="Hole"
Status1=selection1.SelectElement2(InputObjectType,"Select un trou",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub

Dim reference1 As Reference
Set reference1 = selection1.Item(1).Reference

MsgBox reference1.Name
selection1.Clear

but there is a problem with "Set reference1 = selection1.Item(1).Reference"
i don't know why!
somebody can help me!
thx :)
 
Replies continue below

Recommended for you

Thank you Eric :)
one more thing! how to create a hole in front of that selected one!
Code:
Dim reference1 As Reference
Set reference1 = selection1.Item(1).Value

Dim hole1 As Hole
Set hole1 = part1.CreateReferenceFromObject(reference1)

Dim oDiameter As Length
Set oDiameter = oAssemblyHole.Diameter
oDiameter.Value = 10.000000

oAssemblyHole.Type = catCounterboredHole
oAssemblyHole.AnchorMode = catExtremPointHoleAnchor

Dim oHeadDiameter As Length
Set oHeadDiameter = oAssemblyHole.HeadDiameter
oHeadDiameter.Value = 15.000000

Dim oHeadDepth As Length
Set oHeadDepth = oAssemblyHole.HeadDepth
oHeadDepth.Value = 5.000000

Dim oBottomLimit As Limit
Set oBottomLimit = oAssemblyHole.BottomLimit
oBottomLimit.LimitMode = catOffsetLimit

Dim oDepth As Length
Set oDepth = oBottomLimit.Dimension
oDepth.Value = 30.000000

oAssemblyHole.BottomType = catVHoleBottom
I have a problem with
Set hole1 = part1.CreateReferenceFromObject(reference1)
method fails!
 
Could you try this:

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromObject(selection1.Item2(1).Value)


Deprecated:
V5R16 #Item2 . The Count and Item Methods have been replaced by the Count2 and Item2 methods because they did not process correctly features which are not exposed to automation (such as a ResourcesList feature of a .CATProcess document).


Then you can use the defined reference...

check this

Eric N.
indocti discant et ament meminisse periti
 
maybe you should show us the complete code.. and explain just a little more please..

are you trying to create an assembly hole selecting existing one??
 
I want to create a hole automatically where the user select its place
Code:
Sub CATMain()

'**********Declarations*******

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim product1 As Product
Set product1 = productDocument1.Product

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

Dim visPropertySet1 As VisPropertySet
Set visPropertySet1 = selection1.VisProperties

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim oselection1 As Selection
Set oselection1 = productDocument1.Selection

Dim partDocument1 As Document
Set partDocument1 = documents1.Item(part1)

Dim part1 As Part
Set part1 = partDocument1.Part
'...

'******Msg : hole selection********

MsgBox "select a hole"
Dim InputObjectType(0), Status1
InputObjectType(0)="Hole"
Status1=selection1.SelectElement2(InputObjectType,"Select un trou",false)
If Status1 = "Cancel" Then selection1.Clear: Exit Sub

Dim reference1 As Reference
Set oHole = selection1.Item(1).value
Set reference1 = oHole
MsgBox ("hole name ="& reference1.Name)   
selection1.Clear

diametre= oHole.Diameter.Value 
nom_piece= oHole.Diameter.Name
nom_trou =reference1.Name
MsgBox ("le diametre du trou=" & diametre &"mm")                  '''''''''hole diametre 
MsgBox ("la piece a percer =" & oHole.Diameter.Name)               ''''''''la pierce a percer

'************************Origine du trou********************************

'get the origin of the hole using the variant object
Dim origin(2)
oHole.GetOrigin (origin)

Msgbox "Origin = " & origin(0) & ", " & origin(1) & ", " & origin(2)

'****************************************************************************

Dim hole1 As Hole [COLOR=#EF2929] (where the problem is)[/color]
Set hole1 = part1.AddNewHoleFromPoint(origin(0), origin(1), origin(2), reference1, 6.000000)

my code is not working! the creation is failed
 
I dont know if this is what you need... but its something... hope it helps


i took this piece of code from V5Automation.chm file and i made a few modifications...
Code:
Sub Assembly_hole()

Set oDocument = CATIA.ActiveDocument
Set oHole = oDocument.Selection.FindObject("CATIAHole")

Dim oRootProduct As Product
Set oRootProduct = CATIA.ActiveDocument.Product

Dim oSkeletton As Product
Set oSkeletton = oRootProduct.Products.Item("Part2.1")

Dim oPlaque1 As Product
Set oPlaque1 = oRootProduct.Products.Item("Part2.1")

Dim oPlaque2 As Product
Set oPlaque2 = oRootProduct.Products.Item("Part4.1")

Dim oSkelDocument As PartDocument
Set oSkelDocument = CATIA.Documents.Item("Part2.CATPart")

Dim oBody As Body
Set oBody = oSkelDocument.Part.Bodies.Item("PartBody")

Dim oPosSketch As Sketch
Set oPosSketch = oHole.Sketch
'Set oPosSketch = oBody.Sketches.Item("Positioning sketch for assembly hole")

Dim oAssemblyFeatures As AssemblyFeatures
Set oAssemblyFeatures = oRootProduct.GetTechnologicalObject("AssemblyFeatures")

Dim oAssemblyHole As AssemblyHole
Set oAssemblyHole = oAssemblyFeatures.AddAssemblyHole(oPosSketch, oSkeletton, 10#, oSkeletton)

'oAssemblyHole.AddAffectedComponent oPlaque1
oAssemblyHole.AddAffectedComponent oPlaque2

Dim oDiameter As Length
Set oDiameter = oAssemblyHole.Diameter
oDiameter.Value = 10#

oAssemblyHole.Type = catCounterboredHole
oAssemblyHole.AnchorMode = catExtremPointHoleAnchor

Dim oHeadDiameter As Length
Set oHeadDiameter = oAssemblyHole.HeadDiameter
oHeadDiameter.Value = 15#

Dim oHeadDepth As Length
Set oHeadDepth = oAssemblyHole.HeadDepth
oHeadDepth.Value = 5#

Dim oBottomLimit As Limit
Set oBottomLimit = oAssemblyHole.BottomLimit
oBottomLimit.LimitMode = catOffsetLimit

Dim oDepth As Length
Set oDepth = oBottomLimit.Dimension
oDepth.Value = 30#

oAssemblyHole.BottomType = catVHoleBottom

Dim oBottomAngle As Angle
Set oBottomAngle = oAssemblyHole.BottomAngle
oBottomAngle.Value = 120#

oRootProduct.Update

End Sub
 
I'm not sure if your reference works.. your selection it's a hole and the function needs a plane.. i think

see the function ..

Func AddNewHoleFromPoint( double iX,
double iY,
double iZ,
Reference iSupport,
double iDepth) As Hole

Creates and returns a new hole within the current shape.
Actual hole shape is defined by editing hole properties after its creation.
Parameters:
iX
Origin point x absolute coordinate
iY
Origin point y absolute coordinate
iZ
Origin point z absolute coordinate
Sets the origin point which the hole is anchored to.
If mandatory, the entry point will be projected onto a tangent plane.
iSupport
The support defining the hole reference plane.
The following
Boundary object is supported: Face.
iDepth
The hole depth.
Returns:
The created hole



 
Thank you for you help!
at the beginning, my macro hide the tangent plane, iSupport (reference1), then i select the hole, then the plane is displayed, in the end, the hole creation on that iSupport!

AlexLozoya said:
Func AddNewHoleFromPoint( double iX,
double iY,
double iZ,
Reference iSupport,
double iDepth) As Hole
I tried with: Set hole1 =part1.AddNewHoleFromPoint (origin(0), origin(1), origin(2), reference1, 3.000000) As Hole --> this object does not support this property or method
then I tried with: Set hole1 =shapeFactory1.AddNewHoleFromPoint (origin(0), origin(1), origin(2), reference1, 3.000000) As Hole: incompatible type!!

one more thing ! can I use: AddNewHoleFromRefPoint ? and how?
thank you one more time :)



 
Well i did it partially! the hole is created!
Code:
Dim reference11 As Reference

Set reference11 = part1.CreateReferenceFromBRepName("FSur:(Face:(Brp:(Pad.1;2);None:();Cf11:());WithTemporaryBody;WithoutBuildError;WithInitialFeatureSupport;MonoFond;MFBRepVersion_CXR15)", pad1)

Dim hole1 As Hole
Set hole1 = ShapeFactory1.AddNewHoleFromPoint(23, 11, 20, reference11, 20.000000)

the last thing that i want now is how to join between my selected hole and this last one! knowing that
oHole.GetOrigin (origin) gives a wrong values!!!
 
Status
Not open for further replies.
Back
Top