⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boltvbscript.html

📁 CATIA二次开发
💻 HTML
字号:
<html>
<head>
<title>VBScript</title>
</head>
<body>
<h1>Creating a BOLT in CATIA V5 from HTML with VBScript</h1>
<FORM>
<INPUT TYPE="button" VALUE="BOLT" NAME="btn1">
</FORM>
<script language="VBscript">
sub btn1_onclick
  Dim CATIA 'As Object
    
  'Get CATIA or Launch it if necessary.
  On Error Resume Next
  Set CATIA = GetObject(, "CATIA.Application")
  If Err.Number <> 0 Then
     Set CATIA = CreateObject("CATIA.Application")
    CATIA.Visible = True
  End If
  On Error GoTo 0
  
  ' Add a new Part
  Set MyDocument = CATIA.Documents.Add("Part")
  Set PartFactory = MyDocument.Part.ShapeFactory  ' Retrieve the Part Factory.
  Set MyBody1 = MyDocument.Part.Bodies.Item("PartBody")
  CATIA.ActiveDocument.Part.InWorkObject = MyBody1 ' Activate "PartDesign"
  
' Creating the Shaft
  Set ReferencePlane1 = MyDocument.Part.CreateReferenceFromGeometry(MyDocument.Part.OriginElements.PlaneYZ)
  
  ' Create the sketch1 on ReferencePlane1
  Set Sketch1 = MyBody1.Sketches.Add(ReferencePlane1)
  Set MyFactory1 = Sketch1.OpenEdition() ' Define the sketch

  h1 = 80 ' height of the bolt
  h2 = 300 ' total height
  r1 = 120 ' external radius
  r2 = 60 ' Internal radius
  s1 = 20 ' Size of the chamfer
  
  Set l101 = MyFactory1.CreateLine(0, 0, r1 - 20, 0)
  Set l102 = MyFactory1.CreateLine(r1 - 20, 0, r1, -20)
  Set l103 = MyFactory1.CreateLine(r1, -20, r1, -h1 + 20)
  Set l104 = MyFactory1.CreateLine(r1, -h1 + 20, r1 - 20, -h1)
  Set l105 = MyFactory1.CreateLine(r1 - 20, -h1, r2, -h1)
  Set l106 = MyFactory1.CreateLine(r2, -h1, r2, -h2 + s1)
  Set l107 = MyFactory1.CreateLine(r2, -h2 + s1, r2 - s1, -h2)
  Set l108 = MyFactory1.CreateLine(r2 - s1, -h2, 0, -h2)
  Set l109 = MyFactory1.CreateLine(0, -h2, 0, 0)
  Sketch1.CenterLine = l109
  
  Sketch1.CloseEdition
  Set AxisPad1 = PartFactory.AddNewShaft(Sketch1)
  
' Creating the Pocket
  Set ReferencePlane2 = MyDocument.Part.CreateReferenceFromGeometry(MyDocument.Part.OriginElements.PlaneXY)
    
  ' Create the sketch2 on ReferencePlane2
  Set Sketch2 = MyBody1.Sketches.Add(ReferencePlane2)
  Set MyFactory2 = Sketch2.OpenEdition() ' Define the sketch
  D = 1 / 0.866
  
  Set l201 = MyFactory2.CreateLine(D * 100, 0, D * 50, D * 86.6)
  Set l202 = MyFactory2.CreateLine(D * 50, D * 86.6, D * -50, D * 86.6)
  Set l203 = MyFactory2.CreateLine(D * -50, D * 86.6, D * -100, 0)
  Set l204 = MyFactory2.CreateLine(D * -100, 0, D * -50, D * -86.6)
  Set l205 = MyFactory2.CreateLine(D * -50, D * -86.6, D * 50, D * -86.6)
  Set l206 = MyFactory2.CreateLine(D * 50, D * -86.6, D * 100, 0)

  ' Create a big circle around the form to get a Hole
  Set c2 = MyFactory2.CreateClosedCircle(0, 0, 300)
  
  Sketch2.CloseEdition
  Set AxisHole2 = PartFactory.AddNewPocket(Sketch2, h1)
  
  MyDocument.Part.Update


end sub
</script></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -