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
but there is a problem with "Set reference1 = selection1.Item(1).Reference"
i don't know why!
somebody can help me!
thx :)
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
indocti discant et ament meminisse periti
RE: select a hole
one more thing! how to create a hole in front of that selected one!
CODE --> vbs
Set hole1 = part1.CreateReferenceFromObject(reference1)
method fails!
RE: select a hole
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
indocti discant et ament meminisse periti
RE: select a hole
" uncorrected value, indicate a value between 0 and 1 "
RE: select a hole
are you trying to create an assembly hole selecting existing one??
RE: select a hole
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 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 SubRE: select a hole
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
this is "Before"
RE: select a hole
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!
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
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!!!