Draft OCA: Difference between revisions

From FreeCAD Documentation
No edit summary
(Scripting...)
Line 46: Line 46:
See [[Import_Export_Preferences|Import Export Preferences]].
See [[Import_Export_Preferences|Import Export Preferences]].


==Scripting== <!--T:10-->
==Scripting==

{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].
<!--T:10-->
See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].


<!--T:11-->
<!--T:11-->
You can export elements to OCA by using the following function:
To export objects to OCA use the {{incode|export}} method of the importOCA module.

</translate>
</translate>
{{Code|code=
{{Code|code=
Line 56: Line 59:
}}
}}
<translate>
<translate>

* For the Windows OS: use a {{FileName|/}} (forward slash) as the path separator in {{Incode|filename}}.


<!--T:12-->
<!--T:12-->
Example:
Example:

</translate>
</translate>
{{Code|code=
{{Code|code=
import FreeCAD, Draft, importOCA
import FreeCAD as App
import Draft
import importDXF


doc = App.newDocument()
p1 = FreeCAD.Vector(0, 0, 0)
p2 = FreeCAD.Vector(1000, 1000, 0)
p3 = FreeCAD.Vector(2200, 1500, 0)
p4 = FreeCAD.Vector(2500, -100, 0)


obj1 = Draft.makeWire([p1, p2, p3, p4])
polygon1 = Draft.make_polygon(3, radius=500)
obj2 = Draft.makeWire([p1, -2.3*p2, -0.8*p3, -1.8*p4])
polygon2 = Draft.make_polygon(5, radius=1500)


doc.recompute()
objects = [obj1, obj2]


objects = [polygon1, polygon2]
importOCA.export(objects, "/home/user/Pictures/myfile.oca")
importOCA.export(objects, "/home/user/Pictures/myfile.oca")
}}
}}

Revision as of 14:50, 1 September 2021

This documentation is a work in progress. Please don't mark it as translatable since it will change in the next hours and days.

Description

Draft OCA is a software module used by the Std Open, Std Import and Std Export commands to handle the OCA file format.

The OCA file format is a community effort to create a free, simple and open CAD file format. OCA is largely based on the GCAD file format generated from gCAD3D. Both formats can be imported in FreeCAD, and the OCA files exported by FreeCAD can be opened in gCAD3D.

Importing

The following OCA objects can be imported:

  • Lines
  • Arcs and Circles
  • Closed areas

Exporting

The following FreeCAD objects can be exported:

  • Lines and wires (polylines)
  • Arcs and circles
  • Faces

Preferences

See Import Export Preferences.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

To export objects to OCA use the export method of the importOCA module.

importOCA.export(exportList, filename)
  • For the Windows OS: use a / (forward slash) as the path separator in filename.

Example:

import FreeCAD as App
import Draft
import importDXF

doc = App.newDocument()

polygon1 = Draft.make_polygon(3, radius=500)
polygon2 = Draft.make_polygon(5, radius=1500)

doc.recompute()

objects = [polygon1, polygon2]
importOCA.export(objects, "/home/user/Pictures/myfile.oca")