Python/tr: Difference between revisions

From FreeCAD Documentation
(Created page with ": Bu örnekte, ilk argüman varsayılan bir değere sahip değildir, bu yüzden her zaman dahil edilmelidir.")
(Created page with "* Argümanlar açık anahtarla verildiğinde, isteğe bağlı argümanlar herhangi bir sırayla verilebilir. Bu, aşağıdaki çağrıların eşdeğer olduğu anlamına gelir:")
Line 33: Line 33:
: Bu örnekte, ilk argüman varsayılan bir değere sahip değildir, bu yüzden her zaman dahil edilmelidir.
: Bu örnekte, ilk argüman varsayılan bir değere sahip değildir, bu yüzden her zaman dahil edilmelidir.


* Argümanlar açık anahtarla verildiğinde, isteğe bağlı argümanlar herhangi bir sırayla verilebilir. Bu, aşağıdaki çağrıların eşdeğer olduğu anlamına gelir:
* When the arguments are given with the explicit key, the optional arguments can be given in any order. This means that the following calls are equivalent:
{{Code|code=
{{Code|code=
Wire = makeWire(pointslist, closed=False, placement=None, face=None)
Wire = makeWire(pointslist, closed=False, placement=None, face=None)

Revision as of 10:55, 9 January 2019

(Kasım 2018) FreeCAD başlangıçta Python 2 ile çalışmak üzere tasarlandı. Birçok özellik Python 3 ile çalışıyor, ancak bazıları çalışmıyor. FreeCAD'i Python 3 te tam olarak destekleme işi , devam etmekte olan bir iştir.

Tanım

Python genel amaçlı, büyük uygulamalarda komut dosyası veya makro oluşturarak bazı görevleri otomatikleştirmek için yaygın olarak kullanılan yüksek seviye bir programlama dilidir.

FreeCAD'de, Python kodu, grafiksel kullanıcı arayüzüne tıklamak zorunda kalmadan programatik olarak çeşitli elemanlar oluşturmak için kullanılabilir. Ek olarak, FreeCAD'in birçok aracı ve tezgahı Python'da programlanmıştır.

Python programlama dili hakkında bilgi edinmek için Python'a Giriş 'e, ardından da FreeCAD'de komut dosyasını başlatmak için Python betik kılavuzu ve FreeCAD betik kılavuzu' ne bakın.

Python kodunu yazarken Python Kodu için Stil Kılavuzu 'nu takip etmeniz önerilir.

Kurallar

Bu belgede, Python örnekleri için bazı kurallara uyulmalıdır.

Bu tipik bir fonksiyon imzasıdır.

Wire = makeWire(pointslist, closed=False, placement=None, face=None, support=None)
  • Anahtar / değer çiftlerine sahip bağımsız değişkenler, imzada belirtilen varsayılan değerlerle isteğe bağlıdır. Bu, aşağıdaki çağrıların eşdeğer olduğu anlamına gelir:
Wire = makeWire(pointslist, False, None, None, None)
Wire = makeWire(pointslist, False, None, None)
Wire = makeWire(pointslist, False, None)
Wire = makeWire(pointslist, False)
Wire = makeWire(pointslist)
Bu örnekte, ilk argüman varsayılan bir değere sahip değildir, bu yüzden her zaman dahil edilmelidir.
  • Argümanlar açık anahtarla verildiğinde, isteğe bağlı argümanlar herhangi bir sırayla verilebilir. Bu, aşağıdaki çağrıların eşdeğer olduğu anlamına gelir:
Wire = makeWire(pointslist, closed=False, placement=None, face=None)
Wire = makeWire(pointslist, closed=False, face=None, placement=None)
Wire = makeWire(pointslist, placement=None, closed=False, face=None)
Wire = makeWire(pointslist, support=None, closed=False, placement=None, face=None)
  • Python's guidelines stress readability of code; in particular, parentheses should immediately follow the function name, and a space should follow a comma.
p1 = Vector(0, 0, 0)
p2 = Vector(1, 1, 0)
p3 = Vector(2, 0, 0)
Wire = makeWire([p1, p2, p3], closed=True)
  • If code needs to be broken over several lines, this should be done at a comma inside brackets or parentheses; the second line should be aligned with the previous one.
a_list = [1, 2, 3,
          2, 4, 5]

Wire = makeWire(pointslist,
                False, None,
                None, None)
  • Functions may return an object that can be used as the base of another drawing function.
Wire = makeWire(pointslist, closed=True, face=True)
Window = makeWindow(Wire, name="Big window")

Imports

Python functions are stored in files called modules. Before using any function in that module, the module must be included in the document with the import instruction.

This creates prefixed functions, that is, module.function(). This system prevents name clashes with functions that are named the same but that come from different modules. For example, the two functions Arch.makeWindow() and myModule.makeWindow() may coexist without problem.

Full examples should include the necessary imports and the prefixed functions.

import FreeCAD, Draft

p1 = FreeCAD.Vector(0, 0, 0)
p2 = FreeCAD.Vector(1, 1, 0)
p3 = FreeCAD.Vector(2, 0, 0)
Wire = Draft.makeWire([p1, p2, p3], closed=True)
import FreeCAD, Draft, Arch

p1 = FreeCAD.Vector(0, 0, 0)
p2 = FreeCAD.Vector(1, 0, 0)
p3 = FreeCAD.Vector(1, 1, 0)
p4 = FreeCAD.Vector(0, 2, 0)
pointslist = [p1, p2, p3, p4]

Wire = Draft.makeWire(pointslist, closed=True, face=True)
Structure = Arch.makeStructure(Wire, name="Big pillar")