CyberChaos(さいばかおす)

プログラミング言語、トランスパイラ、RPA、ChatGPT、データマイニング、リバースエンジニアリングのための忘備録

GitHubの魔界に潜入

2023-06-11 05:03:13 | CATIA
GitHubは魔界だ!

今まで必死になってググっても、ChatGPTに質問しても出てこなかった情報がウジャウジャ出てくる。

ただし、ほとんどが外国語。
日本語で書かれた情報は皆無に等しい。
だから翻訳しなければならない。

なぜ日本のIT業界が遅れているのかというと、その理由はGitHubの魔界を探索すれば良く分かるであろう。

罪日バカチョンチャンコロ売国奴産業スパイが特許だの著作権だの企業秘密だのほざいてひた隠しにし、意図的に間違ったことを書籍として出版する。

仕事では新人教育を軽視し、未経験者・転職回数の多い者、中高年を徹底的に拒絶し、排除し、採用しない。

これじゃあ日本のIT業界のレベルがベトナムや北朝鮮といった極貧発展途上国の足元にすら及ばないのも当たり前だ。

以下の情報も本当かどうかはあやしい。

とりあえずCATIAをPythonで自動化する例が出ていたので、本当かどうかは別として、とりあえず転載しておく。

他にはAutoCADのプラグインをC#で作ったりしているのもあった。

GitHubの検索ボックスCATIAやAutoCADなどのキーワードを入れれば出てくる。

https://github.com/robertpardillo/rice#installing-getting-started


Catia を制御するための Python API


CATIA V5を使用して3Dモデルの作成を簡単に自動化するためのAPIです。RICE は、ソリッドとサーフェスを操作するためのいくつかの操作を実装します。


インストール

はじめに

ライブラリのインストール: src フォルダーをダウンロードし、シェル経由でインストールします。


python setup.py


それからインポートして、


from Rice.application import Application


ライブラリのコピー: src フォルダーをダウンロードし、プロジェクトのルート フォルダーにコピーします。 次に、通常のモジュールと同様にインポートします。


from Rice.application import Application


(例)キューブ




from Rice.application import Application

import os


# Initializing connection with Catia


app = Application()


# Get created parts


parts = app.get_parts()

part = parts[0]


# Get created bodies


body = part.get_bodies()[0]


# Add a sketch on XY plane


sketch = body.add_sketch('xy')


# Add a close path to sketch


sketch.close_path([[0,0],[50,0],[50,50],[0,50]])


# Generating "Pad" operation with "sketch" and 50 mm height


pad = body.pad(sketch, 50)


# Save part, name.CatPART


part.save(os.path.join(os.path.abspath(''),'name'))


コンプレッサーブレード





from Rice.application import Application

import os import pickle


# Getting blade geometry


f = open('blade_data', 'rb') blade_data = pickle.load(f) args=blade_data


# Initializing connection with Catia


app = Application()


# Get created parts


parts = app.get_parts()

part = parts[0]


# Get created bodies


body = part.get_bodies()[0]


# Formatting data


list_profiles_up = [args[i]['profile_UP']

for i in range(len(args)-1)] list_profiles_down = [args[i]['profile_DOWN']

for i in range(len(args)-1)] spline_extrados = list() spline_intrados = list()

list_z = [args[i]['r']

for i in range(len(args)-1)]

for i, n, j in zip(list_profiles_up, list_profiles_down, list_z):


# Creating plane


plane = part.plane('Offset from plane', 'XY', j * 1000)


# Adding sketch on "plane"


sketch = body.add_sketch(plane)


# Adding 2D spline to "sketch"


spline = sketch.spline2D([[p[0] * 1000, p[1] * 1000] for p in i]) spline_extrados.append(spline)


# Adding sketch on "plane"


sketch2 = body.add_sketch(plane)


# Adding 2D spline to "sketch2"


spline2 = sketch2.spline2D([[i[0][0]*1000, i[0][1]*1000]]+[[p[0] * 1000, p[1] * 1000] for p in n]+[[i[-1][0]*1000, i[-1][1]*1000]]) spline_intrados.append(spline2)


# Creating leading edge spline


spline_delante = part.spline([[args[i]['profile_UP'][0][0]*1000, args[i]['profile_UP'][0][1]*1000, args[i]['r']*1000]


for i in range(len(args)-1)])


# Creating trailing edge spline spline_detas = part.spline([[args[i]['profile_UP'][-1][0]*1000, args[i]['profile_UP'][-1][1]*1000, args[i]['r']*1000]

for i in range(len(args)-1)]) fill = list() for i in range(len(spline_intrados)-1):


objs = list() objs.append(spline_delante) objs.append(spline_intrados[i]) objs.append(spline_detas) objs.append(spline_intrados[i+1])


# Creating "fill"


fill.append(part.fill(objs))

objs = list() objs.append(spline_delante) objs.append(spline_extrados[i]) objs.append(spline_detas) objs.append(spline_extrados[i + 1])


# Creating "fill" fill.append(part.fill(objs)) part.update()


# Joining all the created surfaces join = part.join(fill)

part.update()


# Exporting model with "stl" format, test.stl part.export_data(os.path.abspath('')+r' est','stl')


部品設計

本文を追加


from Rice.application import Application


# Initializing connection with CATIA

app = Application()


# Getting "parts" created. Once CATIA connection is enabled, a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Adding "Body" to "part". part.add_body()


# Getting created "bodies"


bodies = part.get_bodies()


パッド


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts() part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Add a close path to sketch.


sketch.close_path([[0,0],[50,0],[50,50],[0,50]])


# Creating a "pad" 50 mm height from "sketch".


body.pad(sketch, 50)


ポケット


from Rice.application import Application


# Initializing connection with CATIA app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Add a close path to sketch.


sketch.close_path([[0,0],[50,0],[50,50],[0,50]])


# Creating a "pad" 50 mm height from "sketch".


pad = body.pad(sketch, 50)


# Creating a "sketch" on the upper face of the "pad".


sketch2 = body.add_sketch(pad['up'])


# Adding a circle with centre (25mm,25mm) and radius 10 mm.


sketch2.circle([25,25], 10)


# Creating a pocket from "sketch2".


body.pocket(sketch2,10)


スケッチ 2D ライン


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Creating 2D line, (0,0) start point and (10,10) end point.


sketch.line2D([0,0],[10,10])


アーク


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Creating an arc with (0,0) centre, 20 mm radius and from 0 to 270 degrees.


sketch.arc([0,0],20, 0, 270)




from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Creating a (0,0) center and 20mm radius circle sketch.circle([0,0],20)


パスを閉じる


from Rice.application import Application


# Initializing connection with CATIA

app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Creating a close path with a list of points.


sketch.close_path([[0,0],[10,0],[15,7.5],[15,15],[0,15]])


2D スプライン


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Add a spline 2D through a list of points.


sketch.spline2D([[0,0],[10,0],[15,7.5],[15,15],[0,15]])


点による円弧


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()


part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY') sketch.arc_by_points([0,0],[10,0],20, 0)


制約


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Generating close path


lines = sketch.close_path([[0,0],[50,0],[50,50],[0,50]])


# Adding a Length constraint to the first line of "lines".


const = sketch.set_constraint(5, lines[0])


# Adding an Angle constraint between the first and the second line of "lines".


const2 = sketch.set_constraint(6, lines[0], lines[1])



生成形状設計

塗りつぶし


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Creating spline 2D on "sketch"


sketch.spline2D([[0, 15], [5, 10], [10, 5], [20, 15]])


# Creating 3D lines.


line1 = part.line3D([0, 15, 0], [0, 15, 15])

line2 = part.line3D([20, 15, 0], [20, 15, 15])

line3 = part.line3D([0, 15, 15], [20, 15, 15])


# Join with a surface "line1", "sketch", "line2" and "line3".


part.fill([line1, sketch, line2, line3])


加入


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Add a "sketch" on "XY" plane.


sketch = body.add_sketch('XY')


# Creating spline 2D on "sketch"


sketch.spline2D([[0, 15], [5, 10], [10, 5], [20, 15]])


# Creating 3D lines.


line1 = part.line3D([0, 15, 0], [0, 15, 15])

line2 = part.line3D([20, 15, 0], [20, 15, 15])

line3 = part.line3D([0, 15, 15], [20, 15, 15])


# Join with a surface "line1", "sketch", "line2" and "line3".


fill1 = part.fill([line1, sketch, line2, line3])


# Creating sketch on 'XY' plane


sketch2 = body.add_sketch('xy')


# Creating spline 2D on "sketch2"


sketch2.spline2D([[0, 15], [5, 20], [10, 25], [20, 15]])


# Join with a surface "line1", "sketch2", "line2" and "line3".


fill2 = part.fill([line1, sketch2, line2, line3])


# Joining surface "fill1" and "fill2".


part.join([fill1, fill2])


一般

平面の作成

平面からのオフセット


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Creating 20 mm offset plane from 'XY' plane.


plane = part.plane('Offset from plane', 'xy', 20)


やるべきこと

3Dライン

ライン

ポイントツーポイント


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Creating 3D line.


part.line3D([0,0,0], [10,20,50])


やるべきこと

3D ポイント

コードからのポイント


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Creating 3D point.


part.point3D([0,0,0])


やるべきこと

3D スプライン

from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Creating 3D spline.


part.spline([[0,0,0], [5,5,7], [10,5,15]])


パラメータの作成


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Creating a real parameter called "Parameter1" with 50m initial value


param = part.create_param('real', "Parameter1", 50)


リレーションの作成

方式


from Rice.application import Application


# Initializing connection with CATIA


app = Application()


# Getting "parts" created. Once CATIA connection is enabled a part is created automatically.


parts = app.get_parts()

part = parts[0]


# Getting "bodies". PartBody body is automatically created.


body, = part.get_bodies()


# Creating 20 mm offset plane from 'XY' plane.


plane = part.plane('Offset from plane', 'xy', 20)


# Creating a real parameter called "Parameter1" with 0.03m initial value


param = part.create_param('real', "Parameter1", 0.03)


# Setting up a formula to set plane offset equal to two times the "Parameter1" value.


part.create_formula('formula1', plane.offset(), '{}*2'.format(param.name))


やるべきこと

保存


from Rice.application import Application

import os


# Initializing connection with Catia


app = Application()


# Get created parts


parts = app.get_parts()

part = parts[0]


# Get created bodies


body = part.get_bodies()[0]


# Add a sketch on XY plane


sketch = body.add_sketch('xy')


# Add a close path to sketch


sketch.close_path([[0,0],[50,0],[50,50],[0,50]])


# Generating "Pad" operation with "sketch" and 50 mm height


pad = body.pad(sketch, 50)


# Save part, name.CatPART


part.save(os.path.join(os.path.abspath(''),'name'))


データのエクスポート


from Rice.application import Application

import os


# Initializing connection with Catia


app = Application()


# Get created parts


parts = app.get_parts()

part = parts[0]


# Get created bodies


body = part.get_bodies()[0]


# Add a sketch on XY plane


sketch = body.add_sketch('xy')


# Add a close path to sketch


sketch.close_path([[0,0],[50,0],[50,50],[0,50]])


# Generating "Pad" operation with "sketch" and 50 mm height


pad = body.pad(sketch, 50)


# Save part as "stl" format, name.stl


part.export_data(os.path.join(os.path.abspath(''),'name'),"stl")



最新の画像もっと見る

コメントを投稿

ブログ作成者から承認されるまでコメントは反映されません。