Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hole creation : point - face , vba 1

Status
Not open for further replies.

TudorM

Automotive
Mar 30, 2020
100
AT
Hello everyone , i am trying to make a simple code to create a hole using (AddNewHoleFromRefPoint).
I used twice "selecetelement2" : once for vertex , second for face and made them references , seems to look fine but code fails on this line:
Capture_kp6wce.jpg
Capture2_oy3ojs.jpg
and cannot understand why .

I tried also (AddNewHole) - wich requires only face as support and depth) and it works , so i am assuming that problem is somewhere with "vertex"
Could someone help me , please?

VBA code :
Sub CATMain()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim osel As Object
Set osel = partDocument1.Selection

Dim status As String
Dim InputObjectType(0)


InputObjectType(0) = "Vertex"
status = osel.SelectElement2(InputObjectType, "Select vertex", False)
If status = "Normal" And osel.Count = 1 Then


Dim vertex1 As Reference
Set vertex1 = osel.Item(1).Reference
Else
MsgBox ("Macro aborted, to execute the desired action, select the Macro again")

Exit Sub

End If

Dim EnabledObjectSelection1(0)
EnabledObjectSelection1(0) = "Face"
Dim osel2 As Object
Set osel2 = partDocument1.Selection
Dim status2 As String

status2 = osel2.SelectElement2(EnabledObjectSelection1, "Select face ", False)
If status2 = "Normal" And osel2.Count = 1 Then

Dim face1 As Reference
Set face1 = osel2.Item(1).Reference


Dim shapeFactory1 As ShapeFactory
Set shapeFactory1 = part1.ShapeFactory


Dim hole1 As Hole
Set hole1 = shapeFactory1.AddNewHoleFromRefPoint(vertex1, face1, 10#)

hole1.Type = catSimpleHole

hole1.AnchorMode = catExtremPointHoleAnchor

hole1.BottomType = catVHoleBottom

Dim limit1 As Limit
Set limit1 = hole1.BottomLimit

limit1.LimitMode = catOffsetLimit

Dim length1 As Length
Set length1 = hole1.Diameter

length1.Value = 10#

Dim angle1 As Angle
Set angle1 = hole1.BottomAngle

angle1.Value = 120#

hole1.ThreadingMode = catSmoothHoleThreading

hole1.ThreadSide = catRightThreadSide

length1.Value = 9#

Dim length2 As Length
Set length2 = limit1.Dimension

length2.Value = 25#

part1.Update

End If
End Sub
 
Replies continue below

Recommended for you

Hi Little Cthulhu , i do get the same error .
 
I think i allready tried , but let me check one more time
 
Try this code from coe (
Code:
Dim Selectedface As Object
Set Selectedface = MySelection.Item(1).Value

Dim sBRepName As String
sBRepName = Selectedface.Name
sBRepName = Replace(sBRepName, "Selection_", "")
sBRepName = Left(sBRepName, InStrRev(sBRepName, "));"))
sBRepName = sBRepName + ");WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)"

Dim oParent As Variant
Set oParent = Selectedface.Parent

Dim reference1 As Reference
Set reference1 = part1.CreateReferenceFromBRepName(sBRepName, oParent)
 
Good morning Little Cthulhu , it worked[bigsmile] ,thank you very much [thanks]!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top