Sketcher scripting/pl: Difference between revisions
(Created page with "Przesuwając kursor myszy nad linią jej numer można zobaczyć w lewym dolnym rogu okna programu FreeCAD, patrz następny rysunek.") |
(Created page with "Niestety numeracja wyświetlana w oknach programu FreeCAD zaczyna się od 1, podczas gdy numeracja linii użytej w skrypcie zaczyna się od 0: oznacza to, że musisz odjąć jeden za każdym razem, gdy chcesz odwołać się do linii.") |
||
Line 121: | Line 121: | ||
[[File:PartDesignConstraintPointOnPointScriptingFigure2.jpg|600px]] |
[[File:PartDesignConstraintPointOnPointScriptingFigure2.jpg|600px]] |
||
Niestety numeracja wyświetlana w oknach programu FreeCAD zaczyna się od 1, podczas gdy numeracja linii użytej w skrypcie zaczyna się od 0: oznacza to, że musisz odjąć jeden za każdym razem, gdy chcesz odwołać się do linii. |
|||
Unfortunately the numbering displayed on the FreeCAD windows start from 1 whereas the numbering of the line used to script start from 0: this means that you have to subtract one each time you want to refer to a line. |
|||
Positive numbers indicate sketch edges (straight lines, circles, conics, B-splines, and so on). The following values can be used to denote elements that are not sketch edges: |
Positive numbers indicate sketch edges (straight lines, circles, conics, B-splines, and so on). The following values can be used to denote elements that are not sketch edges: |
Revision as of 08:32, 14 May 2023
Tworzenie obiektu Szkicu przy użyciu środowiska Python
Tworzymy obiekt Szkic w następujący sposób:
import FreeCAD as App
import Part
import Sketcher
doc = App.newDocument()
sketch = doc.addObject("Sketcher::SketchObject", "Sketch")
sketch.addGeometry(Part.LineSegment(App.Vector(1.2, 1.8, 0),
App.Vector(5.2, 5.3, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(6.5, 1.5, 0),
App.Vector(10.2, 5.0, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(12.2, 1.0, 0),
App.Vector(15.4, 5.0, 0)), False)
doc.recompute()
Dodaje również trzy linie w nowo utworzonym Szkicu.
Tworzenie wiązań przy użyciu środowiska Python
Wiązania geometryczne oraz można tworzyć z poziomu makropoleceń oraz z poziomu konsoli Python za pomocą następującego polecenia:
sketch.addConstraint(Sketcher.Constraint(ConstraintType, EdgeOrPartOfEdge…))
Wiązania wymiarowe oraz specjalne wiązanie prawo Snell'a można tworzyć z poziomu makropoleceń oraz konsoli Python za pomocą poniższego polecenia:
sketch.addConstraint(Sketcher.Constraint(DimensionalConstraintType, EdgeOrPartOfEdge…, App.Units.Quantity("float_value unit")))
na przykład
sketch.addConstraint(Sketcher.Constraint(DimensionalConstraintType, EdgeOrPartOfEdge…, App.Units.Quantity("123.0 mm")))
Pierwszy argument ConstraintType
jest opisany poniżej w akapicie Rodzaje wiązań.
A constraint can take up to six arguments which are edges or indicate which sub-part of an edge is used by the constraint. See the documentation of individual constraints for details on what combinations of edges and sub-parts of edges can be passed as arguments. The main issue with this function is to identify correctly the line number and the vertex number of the lines you want to process. The sections below describe how to identify the numbering of a line, and how to Identify the numbering of the sub-parts of a line.
Rodzaje wiązań
For geometric constraints, the first argument is one of the following. See the corresponding feature page for the possible combinations of arguments allowed for each constraint.
Code | Icon | Feature |
---|---|---|
"Coincident" |
Coincident | |
"PointOnObject" |
Point On Object | |
"Vertical" |
Vertical | |
"Horizontal" |
Horizontal | |
"Parallel" |
Parallel | |
"Perpendicular" |
Perpendicular | |
"Tangent" |
Tangent | |
"Equal" |
Equal | |
"Symmetric" |
Symmetric | |
"Block" |
Block |
For dimensional constraints, the first argument is one of the following. See the corresponding feature page for the possible combinations of arguments allowed for each constraint.
Code | Icon | Feature |
---|---|---|
"DistanceX" |
Horizontal distance | |
"DistanceY" |
Vertical distance | |
"Distance" |
Distance | |
"Radius" |
Radius | |
"Diameter" |
Diameter | |
"Angle" |
Angle | |
"AngleViaPoint" |
Angle |
The Snell's law constraints behave like dimensional contraints for the purposes of scripting. Again, see the corresponding feature page for the possible combinations of arguments allowed for each constraint.
Code | Icon | Feature |
---|---|---|
"SnellsLaw" |
Snell's law |
The Lock constraint is a GUI command which creates a Horizontal distance and a Vertical distance constraint, it is not a constraint of its own.
Identyfikacja numeracji linii
Narysowałem trzy linie, jak pokazano na poniższym rysunku.
Przesuwając kursor myszy nad linią jej numer można zobaczyć w lewym dolnym rogu okna programu FreeCAD, patrz następny rysunek.
Niestety numeracja wyświetlana w oknach programu FreeCAD zaczyna się od 1, podczas gdy numeracja linii użytej w skrypcie zaczyna się od 0: oznacza to, że musisz odjąć jeden za każdym razem, gdy chcesz odwołać się do linii.
Positive numbers indicate sketch edges (straight lines, circles, conics, B-splines, and so on). The following values can be used to denote elements that are not sketch edges:
-1
denotes the horizontal x axis-2
denotes the vertical y axis-n
denotes the external geometry element numbern-3
(e.g. the external geometry element with index 0 in the flattened listsketch.ExternalGeometry
would be denoted by -3, the following element in the flattened list would be -4 and so on).
Identifying the numbering of the sub-parts of a line
When qualifying which part of a line is affected by a constraint, the following values can be used:
0
to indicate that the constraint affects the entire edge.1
to indicate that the constraint affects the starting point of the edge (a full circle has no starting point).2
to indicate that the constraint affects the end point of the edge.3
to indicate that the constraint affects the center point of the edge. For Circles and Conics (ellipses), this is the center of the circle or center (intersection of major and minor axes) of the ellipse. For straight Lines,3
cannot be used to indicate the center point.n
to indicate that the constraint affects the n-th pole of a B-Spline.
The vertices indicated by 1 and 2 are numbered according to their order of creation. To find out the order of their creation (If you have a lot of lines, you cannot remember which vertex you have created first), you just have to move the cursor of your mouse above the two vertices of one line, see following figure.
If you read e.g. 4 and 5, it means that the vertex with the lower number (4 in this example) will be referenced by using the number 1 (first in the script command and the vertex with the higher number (5 in this example) will be referenced by using the number 2 in the script command.
Example
Let us take the previous example of the three lines. The subsequent figure indicates the numbering of each line and their vertices according to the convention for scripting.
blue text: numbering of line, black text: numbering of vertices
The command sketch.addConstraint(Sketcher.Constraint("Coincident", 1, 2, 2, 1))
yields following result:
The full code to draw the three lines and add a Coincident constraint on two points from two lines is like this:
import FreeCAD as App
import Part
import Sketcher
doc = App.newDocument()
sketch = doc.addObject("Sketcher::SketchObject", "Sketch")
sketch.addGeometry(Part.LineSegment(App.Vector(1.2, 1.8, 0),
App.Vector(5.2, 5.3, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(6.5, 1.5, 0),
App.Vector(10.2, 5.0, 0)), False)
sketch.addGeometry(Part.LineSegment(App.Vector(12.2, 1.0, 0),
App.Vector(15.4, 5.0, 0)), False)
sketch.addConstraint(Sketcher.Constraint("Coincident", 1, 2, 2, 1))
doc.recompute()
- Przybory: Nowy szkic, Edycja szkicu, Mapuj szkic na powierzchnię, Zmień orientację szkicu, Sprawdź poprawność szkicu, Połącz szkice, Odbicie lustrzane szkicu, Zamknij szkic, Widok szkicu, Widok przekroju, Włącz / wyłącz siatkę, Włącz / wyłącz przyciąganie, Kolejność renderowania, Przerwij operację
- Geometrie szkicownika: Punkt, Linia, Komponent utwórz łuk, Łuk, Utwórz łuk przez 3 punkty, Komponent utwórz okrąg, Okrąg, Utwórz okrąg przez 3 punkty, Komponent utwórz stożek, Utwórz elipsę względem środka, Utwórz elipsę przez 3 punkty, Utwórz łuk elipsy, Utwórz łuk hyperboli, Utwórz łuk paraboli, Komponent utwórz krzywą złożoną, Utwórz krzywą złożoną, Utwórz okresową utwórz krzywą złożoną, Polylinia (linia wielopunktowa), Prostokąt, Komponent utwórz wielokąt foremny, Trójkąt, Kwadrat, Pięciokąt, Sześciokąt, Siedmiokąt, Ośmiokąt, Utwórz wielokąt foremny, Rowek, Zaokrąglenie, Zaokrąglenie z zachowaniem wiązań, Przytnij, Rozszerz, Geometria zewnętrzna, Kalka techniczna, Tryb konstrukcyjny
- Wiązania szkicownika
- Wiązania geometryczne Wiązanie zbieżności punktów, Wiązanie punktu na obiekcie, Wiązanie pionowe, Wiązanie poziome, Wiązanie równoległości, Wiązanie prostopadłości, Wiązanie styczności, Wiązanie równości, Wiązanie symetrii, Wiązanie zablokowania
- Wiązania wymiarów Wiązanie blokady odległości, Zwiąż odległość poziomą, Zwiąż odległość pionową, Wiązanie odległości, Wiązanie promienia, Wiązanie średnicy, Zwiąż automatycznie promień / średnicę, Wiązanie kąta, Wiązanie prawo Snella
- Narzędzia wiązań: Przełącz kontrolę wiązania, Przełącz aktywność wiązania
- Narzędzia szkicownika Wybierz elementy bez wiązań, Wybierz powiązane więzy, Wybierz powiązaną geometrię, Wybierz zbędne wiązania, Wybierz wiązania konfliktowe, Pokaż / ukryj geometrię wewnętrzną, Wybierz odniesienie położenia, Wybierz oś poziomą, Wybierz oś pionową, Odbicie lustrzane, Klonuj, Kopiuj, Przesuń, Szyk prostokątny, Usuń wyrównanie osi, Usuń wszystkie geometrie, Usuń wszystkie wiązania
- Narzędzia B-spline dla szkicownika. Pokaż / ukryj stopień krzywej złożonej, Pokaż/ukryj ramkę kontrolną krzywej złożonej, Pokaż / ukryj grzebień krzywizny krzywej złożonej, Pokaż / ukryj wyświetlanie węzłów krzywej złożonej, Pokaż / ukryj wagę punktu kontrolnego krzywej złożonej, Konwertuj geometrię na krzywą złożoną, Zwiększ stopień krzywej złożonej, Zmniejsz stopień krzywej złożonej, Zwiększ krotność węzłów krzywej złożonej, Zmniejsz krotność węzła krzywej złożonej, Wstaw węzeł, Połącz krzywe
- Przestrzeń wirtualna szkicownika Przełącz przestrzeń wirtualną
- Dodatkowe: Okienko dialogowe Szkicownika, Preferencje, Skrypty Szkicownika
- Jak zacząć
- Instalacja: Pobieranie programu, Windows, Linux, Mac, Dodatkowych komponentów, Docker, AppImage, Ubuntu Snap
- Podstawy: Informacje na temat FreeCAD, Interfejs użytkownika, Profil nawigacji myszką, Metody wyboru, Nazwa obiektu, Edytor ustawień, Środowiska pracy, Struktura dokumentu, Właściwości, Pomóż w rozwoju FreeCAD, Dotacje
- Pomoc: Poradniki, Wideo poradniki
- Środowiska pracy: Strona Startowa, Architektura, Assembly, CAM, Rysunek Roboczy, MES, Inspekcja, Siatka, OpenSCAD, Część, Projekt Części, Punkty, Inżynieria Wsteczna, Robot, Szkicownik, Arkusz Kalkulacyjny, Powierzchnia 3D, Rysunek Techniczny, Test Framework