ShapeType.Name and Template.Name

Feb 5, 2013 at 5:20 PM
Hi,

Do I understand correctly that if NShapeLibraryInitializer.Initialize() contains code
registrar.RegisterShapeType(new ShapeType("abc", .....));
-- then I should write
Template template = prj.Repository.GetTemplate("abc");
when I need to get template for this type of shapes?

Argument of the IRepository.GetTemplate() method is called "name", and the first argument of the ShapeType's constructor is also called "name". In fact it's "templateName" and "typeName" correspondingly. So I wonder if the 2nd one can be also interpreted as "templateName".

I couldn't find any statement (in Help) like "shape template obtains the name of the corresponding shape type" (or smth. like that). But I suspect that it is true...
Coordinator
Feb 7, 2013 at 8:28 AM
The ShapeType's name is used for addressing the shape's type in the ptojects collection of registered shape types:
Project.ShapeTypes["abc"]
When adding a shape library to the project, a Template is automatically created for each shape type (at least if Project.AutoGenerateTemplates is set to true).
The automatically created shapes use the ShapeTye's name as Template name, that's true.
But you can also add your own additional templates to the repository or delete all existing templates and replace them with templates that have a different naming scheme. You can even rename existing templates.

Example:
  • Start the "NShape Designer" and place an Ellipse on the diagram.
  • Assign a red fill style and right-click this shape
  • Select "Create Template" from the context menu. A new template will be inserted in the tool box.
    As you can see, the created template has the (not very meaningful) name "Ellipse xxxxx". You can now address this template in the repository with
Template template = prj.Repository.GetTemplate("Ellipse xxxxx");
  • Now, right-click the new tool box item and select "Edit Template..." from the context menu
  • Change the name of the template to a more meaningful name (e.g. "Red Ellipse") and click "OK"
  • You can now address the template with
Template template = prj.Repository.GetTemplate("Red Ellipse");
Feb 7, 2013 at 8:37 AM
So if my application does not allow any template manipulations and Project.AutoGenerateTemplates is set to "true" - I can say for sure that ShapeType.Name == Template.Name, right?