Home  Previous Next

command (MEL/Python)

MGSvgImport v2_transparent

Go to: Synopsis. MEL examples. Python examples.

Synopsis

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 is NOT undoable, queryable, and editable.

This command batch imports SVG items into the picker scene, or query SVG basic information.

 

 

Long name (short name)

Argument types

Properties

-conformed(-cfd) v2_transparent

boolean

query

 

A query-only flag is only used with -elements flag to query the SVG element IDs and return conformed result.

Some vector programs escape special characters that SVG standard does not allow to be used in ID, MGPicker conforms them back to its original ID for UI display purposes.

The user can use this flag for mapping purpose, for the actual map used to batch import, you still need to use the unconfomed IDs.

It is False if this flag is not specified.

-elements(-ems)v2_transparent

boolean

query

 

A query-only flag to query a SVG file's element IDs, you need to use it with -image flag to specify what SVG file to read.

Use the flag with conformed to return a reader-friendly IDs.

-elementTypeMap(-etm)v2_transparent

string string

createeditmultiuse

 

A list of (elementID, pickerButtonType) for the batch import. Unincluded elements will be ignored during the import.

The element ID must to be the actual SVG element ID, not the confomed ones.

The picker button type needs to be any of these three: "selectButton", "commandButton", "graphicItem" as they support image shapes.

e.g.:

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

-fitMode(-fm)v2_transparent

UnsignedInt

createedit

 

The fit mode of the created button's image shape. 0 means to keep the original size, 1 means to scale to fit the parent group but not keep the width/height ratio, and 2 means to scale to fit the parent group and keep the image ratio. By default it is 0.

-highlightImage(-hi)v2_transparent

string

createedit

 

The image path used as highlight image.

-hoverImage(-hvi)v2_transparent

string

createedit

 

The image path used as mouse hovered image.

-image(-i)v2_transparent

string

createedit

 

The image path used as normal image. This is a required flag.

-idAsMember(-iam)v2_transparent

boolean

createedit

 

Whether we used the conformed element ID as the member of the selectButton with possible button name excluded. By default it is True.

-newGroup(-ng)v2_transparent

boolean

createedit

 

Whether we create a new group to hold all the picker buttons created. By default it is False.

-parentGroup(-pg)v2_transparent

string

createedit

 

Whether we create every button under this parent group/panel. This flag does not conflict with -newGroup, with newGroup being True, there will be a new group right under this parent group.

-pressedImage(-pi)v2_transparent

string

createedit

 

The image path used as mouse pressed image.

-setNewGroupBG(-snb)v2_transparent

boolean string

createedit

 

If we choose to create a new group, the first boolean value tells whether we set the background image of this new group, the second string value tells which element we use as that background, empty element ID means the whole SVG image.

-setParentBG(-spb)v2_transparent

boolean string

createedit

 

If we choose to parent all the new items under an existing group/panel, the first boolean value tells whether we set the background image of this parent group/panel, the second string value tells which element we use as that background, an empty element ID means the whole SVG image.

-size(-sz)v2_transparent

boolean

query

 

A query-only flag to query a SVG file's default size, you need to use it with -image flag to specify what SVG file to read.

-view(-v)

string

createedit

 

The view of this batch import should happen in.



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 examples

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 examples

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