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!

Change radius of circle using macro

Status
Not open for further replies.

makyy

Automotive
Mar 2, 2021
19
0
0
JP
hello everyone,
I created a macro in which I guide the user till the intersection of two elements. But I cannot seem to change the radius of circle using Userform.

The code I created:
Sub CATMain()



Dim oDoc As Object
Set oDoc = CATIA.ActiveDocument

Dim oPart As Part
Set oPart = oDoc.Part

Dim hybridShapeFactory1 As Object
Set hybridShapeFactory1 = oPart.HybridShapeFactory


Dim oSec As Object
Set oSec = oDoc.Selection

oSec.Clear


Dim Msg As String
Msg = "作成したポイントを選択してください。"

Dim InputObjectType()
ReDim InputObjectType(0)
InputObjectType(0) = "Plane"

Dim Status As String
Dim hybridShapeCurveExplicit1 As Object

If Status <> "Cancel" Then
Status = oSec.SelectElement2(InputObjectType, _
"方向を選択してください。", False)
End If


Dim reference As reference
Set reference = oSec.Item(1).reference

Dim InputType()
ReDim InputType(0)
InputType(0) = "Point"

Dim Status1 As String

If Status1 <> "Cancel" Then
Status1 = oSec.SelectElement2(InputType, _
"ポイントを選択してください。", False)

End If

Dim reference1 As reference
Set reference1 = oSec.Item(1).reference


Dim hybridBodies1
Set hybridBodies1 = oPart.HybridBodies
Dim hybridBody1
Set hybridBody1 = hybridBodies1.Item(1)

Dim hybridShapePlaneNormal1
Set hybridShapePlaneNormal1 = hybridShapeFactory1.AddNewPlaneOffsetPt(reference, reference1)

hybridBody1.AppendHybridShape hybridShapePlaneNormal1

oPart.InWorkObject = hybridShapePlaneNormal1

oPart.Update


Dim Status2 As String

If Status2 <> "Cancel" Then
Status2 = oSec.SelectElement2(InputObjectType, _
"方向を選択してください。", False)
End If


Dim reference2 As reference
Set reference2 = oSec.Item(1).reference



Dim hybridShapeCircleCtrRad
Set hybridShapeCircleCtrRad = hybridShapeFactory1.AddNewCircleCtrRad(reference1, reference2, False, 150)



hybridShapeCircleCtrRad.SetLimitation 1

hybridBody1.AppendHybridShape hybridShapeCircleCtrRad

oPart.InWorkObject = hybridShapeCircleCtrRad

oPart.Update



Dim hybridShapeFill1
Set hybridShapeFill1 = hybridShapeFactory1.AddNewFill()

Dim reference3
Set reference3 = oPart.CreateReferenceFromObject(hybridShapeCircleCtrRad)

hybridShapeFill1.AddBound reference3

hybridShapeFill1.Continuity = 1

hybridShapeFill1.Detection = 2

hybridShapeFill1.AdvancedTolerantMode = 3

hybridShapeFill1.MaximumDeviationValue = 0.005

hybridBody1.AppendHybridShape hybridShapeFill1

oPart.InWorkObject = hybridShapeFill1

oPart.Update



Dim InputObject()
ReDim InputObject(0)
InputObject(0) = "AnyObject"

Dim Status3 As String


If Status3 <> "Cancel" Then
Status3 = oSec.SelectElement2(InputObject, _
"一つ目のエレメントを選択してください。", False)
End If

Dim reference4 As reference
Set reference4 = oSec.Item(1).reference

Dim Status4 As String

If Status4 <> "Cancel" Then
Status4 = oSec.SelectElement2(InputObject, _
"二つ目のエレメントを選択してください。", False)
End If

Dim reference5 As reference
Set reference5 = oSec.Item(1).reference

Dim hybridShapeIntersection1
Set hybridShapeIntersection1 = hybridShapeFactory1.AddNewIntersection(reference4, reference5)

hybridShapeIntersection1.PointType = 0

hybridBody1.AppendHybridShape hybridShapeIntersection1

oPart.InWorkObject = hybridShapeIntersection1

oPart.Update


End Sub

And this is the userform i created:
%E7%84%A1%E9%A1%8C1_g9el6t.png


I want the text box to enter the radius value of circle and on pressing the button OK the circle i created in the above code changes its radius.I tried the code given below but it does not seem to work.

Private Sub OKButton_Click()

Dim HybridShapeCircleRadius As Length


If TextBox1.Value > 0 Then
Change.Value = HybridShapeCircle.Radius


oPart.Update
End If

End Sub

any help will be appreciated. Thankyou.
 
Status
Not open for further replies.
Back
Top