MGSvgImport命令
MGSvgImport 不可撤消, 可以查询且可以创建或编辑。
该命令主要用来批量导入SVG图片为Picker按钮,或者查询SVG图片的一些基本信息。
跳转到: [MEL例子] [Python例子]
概要
MGSvgImport( conformed=boolean, elements=boolean, elementTypeMap=(string, string), fitMode=unsignedint, highlightImage=string, hoverImage=string, image=string, idAsMember=boolean, newGroup=boolean, parentGroup=string, pressedImage=string, setNewGroupBG=(boolean, string), setParentBG=(boolean, string), setSceneBG=(boolean, string), size=boolean, view=string, )
MGSvgImport命令 |
|---|
-conformed(-cfd)
|
仅用于查询,与 返回结果将是处理过的易于ID,因为SVG标准的关系,很多字符不允许被用做ID,一些向量软件会将这部分非法字符替换成一些特殊的合法字符组合, 用这个标签后,将会把这些特殊字符组合变回原来在向量软件里显示的字符。 在实际导入时,你要用的是实际的ID而不是这些易于阅读的ID。 不指定情况下这个值是false. |
-elements(-ems)
|
仅用于查询,需要与 也可以配合 |
-elementTypeMap(-etm) string string
|
指定每个元素要创建什么按钮,格式是(元素ID, 按钮类型)。未指定的元素将不会被导入。 元素ID必须是实际的SVG元素ID, 而支持的按钮类型是 比如: MGSvgImport(elementTypeMap=[(elementId1, "selectButton"), (elementId2, "commandButton"), ], ...)
|
-fitMode(-fm) unsignedint
|
导入的按钮的图片缩放模式, |
-highlightImage(-hi) string
|
导入的按钮的高亮显示图片路径。 |
-hoverImage(-hvi) string
|
导入的按钮的鼠标经过图片路径。 |
-image(-i) string
|
导入的按钮的图片路径。这个标签是必须的。 |
-idAsMember(-iam) boolean
|
如果导入为选择按钮,是否将元素ID作为选择按钮的成员。默认情况下这个值是True。 |
-newGroup(-ng) boolean
|
是否创建一个新的组来包含所有其它创建的按钮。默认情况下这个值是False。 |
-parentGroup(-pg) string
|
指定一个组或面板来包含所有创建的按钮,包括由 |
-pressedImage(-pi) string
|
导入的按钮的鼠标按下图片路径。 |
-setNewGroupBG(-snb) boolean string
|
如果选择创建新组,则这个标签的第一个布尔值决定是否设置这个新组的背景图片,第二个字符窜指定使用的元素ID。空元素ID意味整个SVG图片。 |
-setParentBG(-spb) boolean string
|
这个标签的第一个布尔值决定是否设置父组或父面板的背景图片,第二个字符窜指定使用的元素ID。空元素ID意味整个SVG图片。 |
-setSceneBG(-ssb) boolean string
|
这个标签的第一个布尔值决定是否设置Picker视图的背景图片,第二个字符窜指定使用的元素ID。空元素ID意味整个SVG图片。 |
-size(-sz)
|
仅用于查询,需要与-image标签一直使用,来查询SVG图片长宽大小。 |
-view(-v) string
|
在哪个视图进行批量导入,如果不指定,则是在当前激活的视图。 |
标签可以在创建模式中使用;
标签可以在编辑模式中使用
标签可以在查询模式中使用
标签可以在一条命令中多次使用。
MEL例子
string $svgFile = "path/to/svgFile.svg";
// Query the size of SVG file:
int $sizes[] = `MGSvgImport -q -size -image $svgFile`;
print("size of SVG file: " + $sizes[0] + ", " + $sizes[1]+"\n");
// Query the actual element IDs of SVG file:
string $elements[] = `MGSvgImport -q -elements -image $svgFile`;
string $elementStr = `stringArrayToString $elements ", "`;
print("Actual elements: " + $elementStr+"\n");
// Query the conformed element IDs of SVG file:
string $coformedElements[] = `MGSvgImport -q -elements -image $svgFile -conformed`;
string $coformedElementStr = `stringArrayToString $coformedElements ", "`;
print("Conformed UI-friendly elements: " + $coformedElementStr+"\n");
// now do your own mapping for element and the desired picker buttons.
// Now we do the batch import, you can use either create / edit mode.
// Specify view argument if you want to import to a inactive view:
string $importedButtons[] = `MGSvgImport
-parentGroup "panel1"
-image $svgFile
-fitMode 2
-idAsMember true
-newGroup true
-setParentBG 1 "backgroundElementId"
-elementTypeMap "element1" "selectButton"
-elementTypeMap "element2" "selectButton"
-elementTypeMap "element3" "commandButton"`;
Python例子
from mgpicker import mgp
svgFile = "path/to/svgFile.svg"
# Query the size of SVG file:
print("size of SVG file", mgp.MGSvgImport(q=True, size=True, image=svgFile))
elements = mgp.MGSvgImport(q=True, elements=True, image=svgFile, conformed=False)
print("Actual elements of SVG file", elements)
conformedElements = mgp.MGSvgImport(
q=True, elements=True, image=svgFile, conformed=True
)
print("Conformed UI-friendly elements of SVG file", conformedElements)
# construct a map between original and conformed element IDS, if you need it:
elementMap = {
element: conformed for element, conformed in zip(elements, conformedElements)
}
# now do your own mapping for element and the desired picker buttons.
elementTypeMap = [
("element1", "selectButton"),
("element2", "selectButton"),
("element3", "commandButton"),
]
# Now we do the batch import, you can use either create / edit mode.
# Specify view argument if you want to import to a inactive view:
importedButtons = mgp.MGSvgImport(
parentGroup="panel1",
image=svgFile,
fitMode=2, # scale to fit panel1, but also keep the image ratio.
elementTypeMap=elementTypeMap,
idAsMember=True,
newGroup=False,
setParentBG=(True, "backgroundElementId"),
)