こちらに刺激を受け、CATIA V5のマクロを書かせてみました。
ChatGPTを使ってFusion 360の3Dモデリングのスクリプトをつくってもらう方法|神原 友徳 tomo1230|note
呪文1
CATIA V5のVBAで星型をつくるマクロを教えてください
返答1
Sub CreateStar() Dim oDoc As PartDocument Set oDoc = CATIA.ActiveDocument Dim oSketch As Sketch Set oSketch = oDoc.Part.Sketches.Add(oDoc.Part.Origin, oDoc.Part.XYPlane) Dim numPoints As Integer numPoints = 5 Dim innerRadius As Double innerRadius = 1 Dim angleBetweenPoints As Double angleBetweenPoints = 360 / (numPoints * 2) Dim i As Integer For i = 0 To numPoints * 2 - 1 Dim angle As Double angle = i * angleBetweenPoints Dim x As Double Dim y As Double If i Mod 2 = 0 Then ' Outer point x = Sin(angle * Pi / 180) y = Cos(angle * Pi / 180) Else ' Inner point x = Sin(angle * Pi / 180) * innerRadius y = Cos(angle * Pi / 180) * innerRadius End If Dim point(2) As Double point(0) = x point(1) = y point(2) = 0 oSketch.Factory2D.CreatePoint point Next i oSketch.CloseEdition Dim oProfile As Profile Set oProfile = oSketch.Profile Dim oSketchBasedFeature As SketchBasedFeature Set oSketchBasedFeature = oDoc.Part.Features.SketchBasedFeatures.Add(oProfile) Dim oShapeFactory As ShapeFactory Set oShapeFactory = oDoc.Part.ShapeFactory Dim oShape As shape Set oShape = oShapeFactory.AddNewWire(oProfile) oDoc.Part.Update End Sub
結構、それっぽいものを書き出してくれます。
"oDoc " とかハンガリアン記法で回答してくるあたりが、
"結構、お勉強されているな" と言う印象で感心します。
(僕は絶対に書きませんが・・・)
しかし実行するとエラーです。
呪文2
上のマクロで oSketch.Factory2D.CreatePoint point がエラーになりました。修正して欲しい
返答2
Sub CreateStar() Dim oDoc As PartDocument Set oDoc = CATIA.ActiveDocument Dim oSketch As Sketch Set oSketch = oDoc.Part.Sketches.Add(oDoc.Part.Origin, oDoc.Part.XYPlane) Dim numPoints As Integer numPoints = 5 Dim innerRadius As Double innerRadius = 1 Dim angleBetweenPoints As Double angleBetweenPoints = 360 / (numPoints * 2) Dim i As Integer For i = 0 To numPoints * 2 - 1 Dim angle As Double angle = i * angleBetweenPoints Dim x As Double Dim y As Double If i Mod 2 = 0 Then ' Outer point x = Sin(angle * Pi / 180) y = Cos(angle * Pi / 180) Else ' Inner point x = Sin(angle * Pi / 180) * innerRadius y = Cos(angle * Pi / 180) * innerRadius End If Dim point(0 To 2) As Double point(0) = x point(1) = y point(2) = 0 oSketch.Factory2D.CreatePoint point Next i oSketch.CloseEdition Dim oProfile As Profile Set oProfile = oSketch.Profile Dim oSketchBasedFeature As SketchBasedFeature Set oSketchBasedFeature = oDoc.Part.Features.SketchBasedFeatures.Add(oProfile) Dim oShapeFactory As ShapeFactory Set oShapeFactory = oDoc.Part.ShapeFactory Dim oShape As shape Set oShape = oShapeFactory.AddNewWire(oProfile) oDoc.Part.Update End Sub
謝りながら修正してくれましたが、同じ位置でエラーでした。
呪文3
'oSketch.Factory2D.CreatePoint のパラメータは配列では無いようです。修正して下さい。 http://catiadoc.free.fr/online/interfaces/interface_Factory2D.htm#CreatePoint
ドキュメントのリンクを入れてみました。何処かで"画像は読めませんが文字は読む"
様な記述を見かけたので。
返答3
Sub CreateStar() Dim oDoc As PartDocument Set oDoc = CATIA.ActiveDocument Dim oSketch As Sketch Set oSketch = oDoc.Part.Sketches.Add(oDoc.Part.Origin, oDoc.Part.XYPlane) Dim numPoints As Integer numPoints = 5 Dim innerRadius As Double innerRadius = 1 Dim angleBetweenPoints As Double angleBetweenPoints = 360 / (numPoints * 2) Dim i As Integer For i = 0 To numPoints * 2 - 1 Dim angle As Double angle = i * angleBetweenPoints Dim x As Double Dim y As Double If i Mod 2 = 0 Then ' Outer point x = Sin(angle * Pi / 180) y = Cos(angle * Pi / 180) Else ' Inner point x = Sin(angle * Pi / 180) * innerRadius y = Cos(angle * Pi / 180) * innerRadius End If oSketch.Factory2D.CreatePoint x, y Next i oSketch.CloseEdition Dim oProfile As Profile Set oProfile = oSketch.Profile Dim oSketchBasedFeature As SketchBasedFeature Set oSketchBasedFeature = oDoc.Part.Features.SketchBasedFeatures.Add(oProfile) Dim oShapeFactory As ShapeFactory Set oShapeFactory = oDoc.Part.ShapeFactory Dim oShape As shape Set oShape = oShapeFactory.AddNewWire(oProfile) oDoc.Part.Update End Sub
先程までのエラー部分をきっちり直してきました。すごい。
しかしまだエラーです。
結論から書くとReference関係の観念が無さそうです。
それも教え込めばクリアする予感はしましたが、面倒な為諦めました。
しかし、ハンガリアンで返してくるのはウケる。