Skip to content

Instantly share code, notes, and snippets.

@rgm
Created October 31, 2011 19:17
Show Gist options
  • Save rgm/1328557 to your computer and use it in GitHub Desktop.
Save rgm/1328557 to your computer and use it in GitHub Desktop.
#include "Menu.h"
using namespace Menu;
namespace Menu
{
const char *universalName = "<%= universal_name %>";
const int resourceIndex = 11000;
static SMenuDef gMenuDef =
{
0x00, // needs flags
0x00, // needs not flags
{resourceIndex, 1}, // 'STR#' localized title
{resourceIndex, 2}, // 'STR#' category
{resourceIndex}, // 'TEXT' help
16, // version created
0, // version modified
0, // version retired
"" // contextual help ID
};
}
// UUID is <%= uuid %>
IMPLEMENT_VWExtension(
Definition, EventSink, universalName, 1,
<%= uuid.to_cpp %>);
Definition::Definition(CallBackPtr cbp) : VWExtensionMenu(cbp,gMenuDef,NULL)
{
}
Definition::~Definition()
{
}
EventSink::EventSink(IVWUnknown *parent) : VWMenu_EventSink(parent)
{
}
EventSink::~EventSink()
{
}
TXString EventSink::GetContextualHelpID() const
{
return "";
}
void EventSink::DoInterface()
{
gSDK->AlertInform("EventSink::DoInterface event called for <%= universal_name %>");
}
#pragma once
namespace Menu
{
using namespace VWFC::PluginSupport;
class EventSink : public VWMenu_EventSink
{
public:
EventSink(IVWUnknown *parent);
virtual ~EventSink();
public:
virtual TXString GetContextualHelpID() const;
virtual void DoInterface();
};
class Definition : public VWExtensionMenu
{
DEFINE_VWExtension;
public:
Definition(CallBackPtr cbp);
virtual ~Definition();
};
}
#include <Carbon/Carbon.r>
#include "GSRsrc.r"
resource 'STR#' (11000, "Menu_Definition") {
{
"<%= universal_name %>",
"<%= category %>",
}
};
resource 'TEXT' (11000, "Menu_Definition:help") {
"One-line-help\n\n"
"Detailed help about the tool, can be multi-line"
};
#include "Parametric.h"
#import "Cocoa/NNAString.h"
using namespace Parametric;
namespace Parametric
{
const char *universalName = "<%= universal_name %>";
const int resourceIndex = 13000;
static SParametricDef gParametricDef =
{
{resourceIndex, 1}, // 'STR#' localized name
kParametricSubType_Point, // parametric type
false, // reset on move
false, // reset on rotate
false, // wall insert on edge
false, // wall insert no break
false, // wall insert half-break
false // wall insert hide caps
};
static SParametricParamChc gArrChoices[] = {
{128, "ArchE", {13001,2}},
{128, "ArchD", {13001,3}},
{128, "42x30", {13001,4}},
{128, "AsmeD", {13001,5}},
{128, "Tabloid", {13001,6}},
{128, "Custom", {13001,7}},
{129, "Standard", {13006,2}},
{129, "Record", {13006,3}},
{NULL, NULL, {0,0}} // terminator
};
static SParametricParamDef gArrParameters[] = {
{"sheet_size", {13001,1}, "ASME D (34x22)", "ASME D (34x22)", kFieldPopUp, 128},
{"width", {13005,1}, "34\"", "34\"", kFieldCoordDisp, 0},
{"height", {13005,2}, "22\"", "22\"", kFieldCoordDisp, 0},
{"show_edge", {13003,1}, "True", "True", kFieldBoolean, 0},
{"show_divider", {13003,2}, "True", "True", kFieldBoolean, 0},
{"show_guides", {13003,3}, "False", "False", kFieldBoolean, 0},
{"show_legend_strip", {13003,4}, "True", "True", kFieldBoolean, 0},
{"divs_across", {13004,1}, "1", "1", kFieldLongInt, 0},
{"divs_down", {13004,2}, "1", "1", kFieldLongInt, 0},
{"pull_data", {13003,5}, "False", "False", kFieldBoolean, 0},
{"register_filename", {13002,12}, "Register.json", "Register.json", kFieldText, 0},
{"drawing_number", {13002,1}, "A#.##", "A#.##", kFieldText, 0},
{"drawing_title", {13002,2}, "", "", kFieldText, 0},
{"date", {13002,3}, "", "", kFieldText, 0},
{"drawing_revision", {13002,4}, "", "", kFieldText, 0},
{"scale", {13002,5}, "", "", kFieldText, 0},
{"drawn", {13002,6}, "", "", kFieldText, 0},
{"checked", {13002,7}, "", "", kFieldText, 0},
{"status", {13002,8}, "", "", kFieldText, 0},
{"project_code", {13002,9}, "", "", kFieldText, 0},
{"project_title", {13002,10}, "", "", kFieldText, 0},
{"project_client", {13002,10}, "", "", kFieldText, 0},
{"project_address", {13002,11}, "", "", kFieldText, 0},
{"show_north", {13003,6}, "False", "False", kFieldBoolean, 0},
{"show_true_north", {13003,7}, "False", "False", kFieldBoolean, 0},
{"project_north", {13004,3}, "0", "0", kFieldLongInt, 0},
{"true_north", {13004,4}, "0", "0", kFieldLongInt, 0},
{"disclaimer", {13006,1}, "Standard", "Standard", kFieldPopUp, 129},
{"use_lscale", {13003,8}, "True", "True", kFieldBoolean, 0},
{"scale_factor", {13004,5}, "1", "1", kFieldLongInt, 0},
{NULL, {0,0}, NULL, NULL, EFieldStyle(0), 0 } // terminator
};
}
// UUID is <%= uuid %>
IMPLEMENT_VWExtension(
Definition, EventSink, universalName, 1,
<%= uuid.to_cpp %>);
Definition::Definition(CallBackPtr cbp) : VWExtensionParametric(cbp,gParametricDef,gArrParameters,gArrChoices)
{
}
Definition::~Definition()
{
}
EventSink::EventSink(IVWUnknown *parent) : VWParametric_EventSink(parent)
{
}
EventSink::~EventSink()
{
}
EObjectEvent EventSink::OnInitXProperties(CodeRefID objectID)
{
using namespace VectorWorks::Extension;
VCOMPtr<IExtendedProps> extProps(IID_ExtendedProps);
//
// define extended properties here
//
return kObjectEventNoErr;
}
EObjectEvent EventSink::Recalculate()
{
VWPoint2D myOrigin(0.0,0.0);
using namespace VectorWorks::Filing;
bool saved;
IFileIdentifierPtr currentFile;
IFolderIdentifierPtr currentFolder;
gSDK->GetActiveDocument(&currentFile,saved);
if (saved) {
currentFile->GetFolder(&currentFolder);
TXString folderName;
currentFolder->GetFullPath(folderName);
// VWTextBlockObj(folderName,myOrigin);
}
VCOMPtr<IFileIdentifier> myFile(IID_FileIdentifier);
if (myFile && VCOM_SUCCEEDED(myFile->Set(currentFolder,"Register.json"))) {
bool exists;
myFile->ExistsOnDisk(exists);
if (exists) {
IStdFilePtr myFilePtr(IID_StdFile);
if (VCOM_SUCCEEDED(myFilePtr->OpenRead(myFile,false))) {
TXString fileContents;
UInt64 fileSize;
myFilePtr->GetFileSize(fileSize);
myFilePtr->Read(fileContents,fileSize);
VWTextBlockObj(fileContents,myOrigin);
NSString *myJSON = [NSString stringWithTXString:fileContents];
myFilePtr->Close();
}
}
}
return kObjectEventNoErr;
}
#pragma once
namespace Parametric
{
using namespace VWFC::PluginSupport;
class EventSink : public VWParametric_EventSink
{
public:
EventSink(IVWUnknown *parent);
virtual ~EventSink();
public:
virtual EObjectEvent OnInitXProperties(CodeRefID objectID);
virtual EObjectEvent Recalculate();
};
class Definition : public VWExtensionParametric
{
DEFINE_VWExtension;
public:
Definition(CallBackPtr cbp);
virtual ~Definition();
};
}
#include <Carbon/Carbon.r>
#include "GSRsrc.r"
resource 'STR#' (13000, "Parametric_Definition") {
{
"aoTitleblock2",
}
};
resource 'STR#' (13001, "Sheet size popup") {
{
"Paper Size",
"US Arch E (48x36)",
"(42x30)",
"US Arch D (36x24)",
"ASME D (34x22)",
"Tabloid (17x11)",
"Custom",
}
};
resource 'STR#' (13002, "String field localizations") {
{
"Drawing Number",
"Drawing Title",
"Date",
"Drawing Revision",
"Scale",
"Drawn",
"Checked",
"Status",
"Project Code",
"Project Title",
"Project Client",
"Project Address",
"Register Filename",
}
};
resource 'STR#' (13003, "Boolean field localizations") {
{
"Show sheet edge?",
"Show vertical divider?",
"Show viewport divisions?",
"Leave strip for legend and notes?",
"Retrieve data automatically?",
"Show north arrow?",
"Show true north?",
"Use layer scale?",
}
};
resource 'STR#' (13004, "Integer field localizations") {
{
"Divisions across",
"Divisions down",
"Project North (Bearing)",
"True North (Bearing)",
"Show at scale 1 to",
}
};
resource 'STR#' (13005, "Dimension field localizations") {
{
"Custom page width",
"Custom page height",
}
};
resource 'STR#' (13006, "Disclaimer popup") {
{
"Disclaimer",
"Standard",
"Record Drawing",
}
};
#include "Tool.h"
using namespace Tool;
namespace Tool
{
const char *universalName = "<%= universal_name %>";
const int resourceIndex = 12000;
static SToolDef gToolDef =
{
eExtensionToolType_Normal, // tool type
"", // parametric name, blank for normal
ToolDef::pickAndUpdate, // pick and update
ToolDef::doesntNeedScreenPlane, // needs screen plane?
ToolDef::doesntNeed3DView, // needs 3d view?
ToolDef::use2DCursor, // use 2d cursor?
ToolDef::constrainCursor, // constrain cursor
ToolDef::doesntNeedPerspective, // needs perspective?
ToolDef::showScreenHints, // show screen hints?
ToolDef::needsPlanarContext, // needs planar context?
false, // reserved
0, // reserved
resourceIndex, // 'PNG ' icon id
0, // default cursor id
{resourceIndex, 3}, // message
0, // wait-move distance
0, // constraint flags
kToolBarDisplay_XYClLaZo, // bar display
900, // minimum compatible version
{resourceIndex, 1}, // 'STR#' title
{resourceIndex, 2}, // 'STR#' category
{resourceIndex}, // 'TEXT' help
16, // version created
0, // version modified
0, // version retired
"" // contextual help ID
};
}
// UUID is <%= uuid %>
IMPLEMENT_VWExtension(
Definition, EventSink, universalName, 1,
<%= uuid.to_cpp %>);
Definition::Definition(CallBackPtr cbp) : VWExtensionTool(cbp,gToolDef)
{
}
Definition::~Definition()
{
}
EventSink::EventSink(IVWUnknown *parent) : VWTool_EventSink(parent)
{
}
EventSink::~EventSink()
{
}
void EventSink::Draw(IToolDrawProvider *pDrawProvider)
{
}
void EventSink::HandleComplete()
{
VWPoint2D pt = this->GetToolPt2D(0);
VWParametricObj obj("<%= universal_name %>",VWPoint2D(pt.x,pt.y));
VWTransformMatrix matrix;
obj.GetObjectMatrix(matrix);
matrix.SetOffset(pt);
obj.SetObjectMatrix(matrix);
}
#pragma once
namespace Tool
{
using namespace VWFC::PluginSupport;
class EventSink : public VWTool_EventSink
{
public:
EventSink(IVWUnknown *parent);
virtual ~EventSink();
public:
virtual void Draw(IToolDrawProvider *pDrawProvider);
virtual void HandleComplete();
};
class Definition : public VWExtensionTool
{
DEFINE_VWExtension;
public:
Definition(CallBackPtr cbp);
virtual ~Definition();
};
}
#include <Carbon/Carbon.r>
#include "GSRsrc.r"
resource 'STR#' (12000, "Tool_Definition") {
{
"<%= universal_name %>",
"<%= category %>",
"toolbar message",
}
};
resource 'TEXT' (12000, "Tool_Definition:help") {
"One line help\n\n"
"Detailed help, can be multiline"
};
read 'PNG ' (12000, "Tool Icon") "Icon.png";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment