Created
October 19, 2011 22:39
-
-
Save jl2/1299897 to your computer and use it in GitHub Desktop.
Quick Ruby script to create a cube in CATIA using COM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'win32ole' | |
def get_catia() | |
catia = nil | |
catia = WIN32OLE.connect('CATIA.Application') | |
if catia == nil then | |
catia = WIN32OLE.new('CATIA.Application') | |
end | |
if catia == nil then | |
puts "Could not connect to CATIA!" | |
end | |
catia | |
end | |
cubeWidth = 20 | |
catia = get_catia() | |
part1 = catia.Documents.Add("Part").Part | |
ad = catia.ActiveDocument | |
bod = part1.MainBody | |
bod.Name="Cube Generated From Ruby" | |
skts = bod.Sketches() | |
xyPlane = part1.CreateReferenceFromGeometry(part1.OriginElements.PlaneXY) | |
shapeFact = part1.Shapefactory | |
ms = skts.Add(xyPlane) | |
ms.Name="Cube Outline" | |
fact = ms.OpenEdition() | |
fact.CreateLine(-cubeWidth, -cubeWidth, cubeWidth, -cubeWidth) | |
fact.CreateLine(cubeWidth, -cubeWidth, cubeWidth, cubeWidth) | |
fact.CreateLine(cubeWidth, cubeWidth, -cubeWidth, cubeWidth) | |
fact.CreateLine(-cubeWidth, cubeWidth, -cubeWidth, -cubeWidth) | |
ms.CloseEdition() | |
mpad = shapeFact.AddNewPad(ms, cubeWidth) | |
mpad.Name = "Ruby Pad" | |
mpad.SecondLimit.Dimension.Value = cubeWidth | |
sel = ad.Selection | |
sel.Add(mpad) | |
vp = sel.VisProperties | |
vp.SetRealColor(255,0,0,1) | |
sel.Clear() | |
part1.Update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment