×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

select a hole

select a hole

select a hole

(OP)
hi!
i want to create a macro that select a hole in a product
i developed this macro

CODE --> vbs

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 :)

RE: select a hole

selection1.Item(1).value

Eric N.
indocti discant et ament meminisse periti

RE: select a hole

(OP)
Thank you Eric :)
one more thing! how to create a hole in front of that selected one!

CODE --> vbs

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!

RE: select a hole

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

RE: select a hole

(OP)
well ...still not working cry

" uncorrected value, indicate a value between 0 and 1 "

RE: select a hole

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??

RE: select a hole

(OP)
I want to create a hole automatically where the user select its place

CODE --> vbs

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  (where the problem is)
Set hole1 = part1.AddNewHoleFromPoint(origin(0), origin(1), origin(2), reference1, 6.000000) 


my code is not working! the creation is failed

RE: select a hole

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 

RE: select a hole

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



RE: select a hole

(OP)
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!

Quote (AlexLozoya)

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 :)



RE: select a hole

(OP)
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!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources