Home  Previous Next

command (MEL/Python)

MGSvgImport v2_transparent

跳转到: 概要. MEL例子. Python例子.

概要

MGSvgImport ([conformed=boolean], [elements=boolean], [elementTypeMap=[(string, string),..]], [fitMode=UnsignedInt], [highlightImage=string], [hoverImage=string], [image=string], [idAsMember=boolean], [newGroup=boolean], [parentGroup=boolean], [pressedImage=string],[setNewGroupBG=(boolean, string)],[setParentBG=(boolean, string)], [size=boolean], [view=string])

MGSvgImport 不可撤消, 可以查询且可以创建或编辑

该命令主要用来批量导入SVG图片为Picker按钮,或者查询SVG图片的一些基本信息。

 

 

长名 (短名

参数类型

属性

-conformed(-cfd) v2_transparent

boolean

query

 

仅用于查询,与-elements 标签一起使用,来查询SVG文件里的所有元素的ID。
返回结果将是处理过的易于ID,因为SVG标准的关系,很多字符不允许被用做ID,一些向量软件会将这部分非法字符替换成一些特殊的合法字符组合, 用这个标签后,将会把这些特殊字符组合变回原来在向量软件里显示的字符。在实际导入时,你要用的是实际的ID而不是这些易于阅读的ID。

不指定情况下这个值是false.

-elements(-ems)v2_transparent

boolean

query

 

仅用于查询,需要与-image标签一起使用,来查询SVG文件里的所有元素的ID。
也可以配合-conformed标签来返回比较方便阅读或处理的ID。

-elementTypeMap(-etm)v2_transparent

string string

createeditmultiuse

 

指定每个元素要创建什么按钮,格式是(元素ID, 按钮类型)。未指定的元素将不会被导入。

元素ID必须是实际的SVG元素ID,而支持的按钮类型是"selectButton", "commandButton", "graphicItem"。

例子:

MGSvgImport(elementTypeMap=[(ementId1, "selectButton"), (ementId1, "commandButton"), ], ...)

-fitMode(-fm)v2_transparent

UnsignedInt

createedit

 

导入的按钮的图片缩放模式,0是指原图大小不缩放,1是指缩放到父组或面板的大小但不保持长宽比,2 是指缩放适配父组或面板的大小并且保持长宽比。

默认情况下这个值是0。

-highlightImage(-hi)v2_transparent

string

createedit

 

导入的按钮的高亮显示图片路径。

-hoverImage(-hvi)v2_transparent

string

createedit

 

导入的按钮的鼠标经过图片路径。

-image(-i)v2_transparent

string

createedit

 

导入的按钮的图片路径。这个标签是必须的。

-idAsMember(-iam)v2_transparent

boolean

createedit

 

如果导入为选择按钮,是否将元素ID作为选择按钮的成员。默认情况下这个值是True。

-newGroup(-ng)v2_transparent

boolean

createedit

 

是否创建一个新的组来包含所有其它创建的按钮。默认情况下这个值是False。

-parentGroup(-pg)v2_transparent

string

createedit

 

指定一个组或面板来包含所有创建的按钮,包括由-newGroup创建的新组。

-pressedImage(-pi)v2_transparent

string

createedit

 

导入的按钮的鼠标按下图片路径。

-setNewGroupBG(-snb)v2_transparent

boolean string

createedit

 

如果选择创建新组,则这个标签的第一个布尔值决定是否设置这个新组的背景图片,第二个字符窜指定使用的元素ID。空元素ID意味整个SVG图片。

-setParentBG(-spb)v2_transparent

boolean string

createedit

 

这个标签的第一个布尔值决定是否设置父组或父面板的背景图片,第二个字符窜指定使用的元素ID。空元素ID意味整个SVG图片。

-size(-sz)v2_transparent

boolean

query

 

仅用于查询,需要与-image标签一直使用,来查询SVG图片长宽大小

-view(-v)

string

createedit

 

在哪个视图进行批量导入,如果不指定,则是在当前激活的视图。



create Flag can appear in Create mode of command

edit Flag can appear in Edit mode of command

query Flag can appear in Query mode of command

multiuse Flag can be used more than once in a command.

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"),
)

Home Previous Next