Draft AnnotationStyleEditor/ru: Difference between revisions

From FreeCAD Documentation
No edit summary
(Updating to match new version of source page)
Line 26: Line 26:
The [[Image:Draft_AnnotationStyleEditor.svg|24px]] '''Draft AnnotationStyleEditor''' command allows you to define styles that affect the visual properties of annotation-like objects, such as those create by the [[Draft_Text|Draft Text]], [[Draft_Dimension|Draft Dimension]] and [[Draft_Label|Draft Label]] commands.
The [[Image:Draft_AnnotationStyleEditor.svg|24px]] '''Draft AnnotationStyleEditor''' command allows you to define styles that affect the visual properties of annotation-like objects, such as those create by the [[Draft_Text|Draft Text]], [[Draft_Dimension|Draft Dimension]] and [[Draft_Label|Draft Label]] commands.


{{Version|1.0}}: Several bugs have been fixed and a separate Text color button has been added.
[[File:Draft_AnnotationStyleEditor_example.png]]

[[File:Draft_AnnotationStyleEditor_Dialog.png]]
{{Caption|The Annotation Styles Editor dialog box}}
{{Caption|The Annotation Styles Editor dialog box}}


Line 46: Line 48:


See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].
See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].

{{Version|1.0}}: The information in this paragraph has been updated and reflects FreeCAD version 1.0.


The annotation styles are saved as serialized dictionaries in the {{incode|Meta}} attribute of the document. This attribute is inspected by the annotation style editor when it is opened.
The annotation styles are saved as serialized dictionaries in the {{incode|Meta}} attribute of the document. This attribute is inspected by the annotation style editor when it is opened.


{{Code|code=
{{Code|code=
>>> print(App.ActiveDocument.Meta["Draft_Style_Lane 1:100"])
>>> print(App.ActiveDocument.Meta["Draft_Style_Text red"])
{"FontName": "DejaVu Sans", "FontSize": "8.0000 ", "LineSpacing": "1 cm", "ScaleMultiplier": 1.0, "ShowUnit": false, "UnitOverride": "", "Decimals": 2, "ShowLines": true, "LineWidth": 2, "LineColor": 1095216660480, "ArrowType": 0, "ArrowSize": "5.0000 ", "DimensionOvershoot": "1.0000 ", "ExtensionLines": "5.0000 ", "ExtensionOvershoot": "1.0000 "}
{"FontName": "DejaVu Sans", "FontSize": 10.0, "LineSpacing": 1.0, "TextColor": 4278190335, "ScaleMultiplier": 1.0, "ShowUnit": false, "UnitOverride": "", "Decimals": 2, "ShowLine": true, "LineWidth": 2, "ArrowType": 0, "ArrowSize": 2.0, "LineColor": 255, "DimOvershoot": 0.0, "ExtLines": 0.0, "ExtOvershoot": 4.0}
}}
}}


Line 57: Line 61:


You may define any new style by adding the necessary information to a key that starts with {{incode|Draft_Style_}}. The corresponding value of this key must be a dictionary serialized using {{incode|json}}.
You may define any new style by adding the necessary information to a key that starts with {{incode|Draft_Style_}}. The corresponding value of this key must be a dictionary serialized using {{incode|json}}.

{{Code|code=
{{Code|code=
import json
import json


meta = App.ActiveDocument.Meta
meta = App.ActiveDocument.Meta
props = {"LineWidth": 6, "ArrowSize": "7"}
props = {"LineWidth": 6, "ArrowSize": 7.0}
meta["Draft_Style_Thick_lines"] = json.dumps(props)
meta["Draft_Style_Thick_lines"] = json.dumps(props)
App.ActiveDocument.Meta = meta
App.ActiveDocument.Meta = meta
}}
}}

The values not entered will be filled automatically when this style is selected in the style editor.
The properties not entered will be filled automatically when this style is selected in the style editor and the {{Button|OK}} button is pressed.


In a similar way, any serialized dictionary can be unpacked for edition.
In a similar way, any serialized dictionary can be unpacked for edition.

{{Code|code=
{{Code|code=
import json

meta = App.ActiveDocument.Meta
meta = App.ActiveDocument.Meta
new_dict = json.loads(meta["Draft_Style_Thick_lines"])
new_dict = json.loads(meta["Draft_Style_Thick_lines"])
}}
}}


The properties must have the following types:
Because the graphical interface widgets check the units of the input values, many of these values must be saved as strings, rather than floating point numbers.


Strings:
Strings:

{{Code|code=
{{Code|code=
props = {
props = {
"FontName": "DejaVu Sans",
"FontName": "DejaVu Sans",
"FontSize": "12.0000 ",
"UnitOverride": ""
"LineSpacing": "1 cm",
"UnitOverride": "m",
"ArrowSize": "5.0000 ",
"DimensionOvershoot": "1.0000 ",
"ExtensionLines": "5.0000 ",
"ExtensionOvershoot": "1.0000 "
}
}
}}
}}


Floats (must be supplied with a decimal point):
Numbers:

{{Code|code=
{{Code|code=
props = {
props = {
"ScaleMultiplier": 1.0,
"FontSize": 10.0,
"Decimals": 2,
"LineSpacing": 1.0,
"LineWidth": 1,
"ScaleMultiplier": 1.0,
"LineColor": 1095216660480,
"ArrowSize": 2.0,
"ArrowType": 0
"DimOvershoot": 0.0,
"ExtLines": 0.0,
"ExtOvershoot": 4.0
}
}
}}
}}
The line color corresponds to the 32-bit integer, from which the individual RGBA values can be extracted.


Integers:
Boolean:

{{Code|code=
props = {
"TextColor": 4278190335,
"Decimals": 2,
"LineWidth": 2,
"ArrowType": 0,
"LineColor": 255
}
}}

The {{Incode|TextColor}} and {{Incode|LineColor}} correspond to a 32-bit integer, from which the individual RGBA values can be extracted. The {{Incode|ArrowType}} is an enumerator.

Booleans:

{{Code|code=
{{Code|code=
props = {
props = {
"ShowUnit": False,
"ShowUnit": false,
"ShowLines": True
"ShowLine": true
}
}
}}
}}

Revision as of 18:39, 15 February 2023

Draft AnnotationStyleEditor

Системное название
Draft AnnotationStyleEditor
Расположение в меню
Annotation → Annotation styles
Верстаки
Draft
Быстрые клавиши
-
Представлено в версии
0.19
См. также
Draft Text, Draft Dimension, Draft Label

Description

The Draft AnnotationStyleEditor command allows you to define styles that affect the visual properties of annotation-like objects, such as those create by the Draft Text, Draft Dimension and Draft Label commands.

introduced in version 1.0: Several bugs have been fixed and a separate Text color button has been added.

The Annotation Styles Editor dialog box

Usage

  1. There are several ways to invoke the command:
  2. The Annotation Styles Editor dialog box opens.
  3. Select a style from the Style name dropdown list, or choose Add new... to define a new style.
  4. Optionally adjust the properties of the style.
  5. Optionally press the Rename button to rename the style.
  6. Optionally press the Delete button to delete the style.
  7. Optionally press the button to import all styles from a .json file. This will overwrite existing styles with the same name.
  8. Optionally press the button to export all styles to a .json file.
  9. Press the OK button to close the dialog box and finish the command.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

introduced in version 1.0: The information in this paragraph has been updated and reflects FreeCAD version 1.0.

The annotation styles are saved as serialized dictionaries in the Meta attribute of the document. This attribute is inspected by the annotation style editor when it is opened.

>>> print(App.ActiveDocument.Meta["Draft_Style_Text red"])
{"FontName": "DejaVu Sans", "FontSize": 10.0, "LineSpacing": 1.0, "TextColor": 4278190335, "ScaleMultiplier": 1.0, "ShowUnit": false, "UnitOverride": "", "Decimals": 2, "ShowLine": true, "LineWidth": 2, "ArrowType": 0, "ArrowSize": 2.0, "LineColor": 255, "DimOvershoot": 0.0, "ExtLines": 0.0, "ExtOvershoot": 4.0}

Each style that appears in the editor is internally saved with the style name prefixed by Draft_Style_; this will prevent name clashes with other keys that may be saved in Meta, which can hold arbitrary information.

You may define any new style by adding the necessary information to a key that starts with Draft_Style_. The corresponding value of this key must be a dictionary serialized using json.

import json

meta = App.ActiveDocument.Meta
props = {"LineWidth": 6, "ArrowSize": 7.0}
meta["Draft_Style_Thick_lines"] = json.dumps(props)
App.ActiveDocument.Meta = meta

The properties not entered will be filled automatically when this style is selected in the style editor and the OK button is pressed.

In a similar way, any serialized dictionary can be unpacked for edition.

import json

meta = App.ActiveDocument.Meta
new_dict = json.loads(meta["Draft_Style_Thick_lines"])

The properties must have the following types:

Strings:

props = {
    "FontName": "DejaVu Sans",
    "UnitOverride": ""
}

Floats (must be supplied with a decimal point):

props = {
    "FontSize": 10.0,
    "LineSpacing": 1.0,
    "ScaleMultiplier": 1.0,
    "ArrowSize": 2.0,
    "DimOvershoot": 0.0,
    "ExtLines": 0.0,
    "ExtOvershoot": 4.0
}

Integers:

props = {
    "TextColor": 4278190335,
    "Decimals": 2,
    "LineWidth": 2,
    "ArrowType": 0,
    "LineColor": 255
}

The TextColor and LineColor correspond to a 32-bit integer, from which the individual RGBA values can be extracted. The ArrowType is an enumerator.

Booleans:

props = {
    "ShowUnit": false,
    "ShowLine": true
}