Skip to content

Instantly share code, notes, and snippets.

@svvitale
Created January 23, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svvitale/b6cdc5913a82ff74efebcbd432e9979c to your computer and use it in GitHub Desktop.
Save svvitale/b6cdc5913a82ff74efebcbd432e9979c to your computer and use it in GitHub Desktop.
Dymo SDK Concurrency Issues
using DYMO.Label.Framework;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Printers printers = new Printers();
ILabel _label = Framework.Open("Test.label");
for (int x = 0; x < 3; x++)
{
foreach (IPrinter printer in printers)
{
_label.SetObjectText("name", "Scott " + x.ToString());
_label.Print(printer);
}
}
}
}
}
<html>
<head>
<script src="DYMO.Label.Framework.2.0.2.js"></script>
<script>
// Busy wait sleep function.
function sleep(seconds){
var waitUntil = new Date().getTime() + seconds*1000;
while(new Date().getTime() < waitUntil) true;
}
dymo.label.framework.init(function() {
try
{
// open label
var labelXml = '<?xml version="1.0" encoding="utf-8"?>\n' +
'<DieCutLabel Version="8.0" Units="twips" MediaType="Default">\n' +
'\t<PaperOrientation>Landscape</PaperOrientation>\n' +
'\t<Id>LargeShipping</Id>\n' +
'\t<IsOutlined>false</IsOutlined>\n' +
'\t<PaperName>30256 Shipping</PaperName>\n' +
'\t<DrawCommands>\n' +
'\t\t<RoundRectangle X="0" Y="0" Width="3331" Height="5715" Rx="270" Ry="270" />\n' +
'\t</DrawCommands>\n' +
'\t<ObjectInfo>\n' +
'\t\t<TextObject>\n' +
'\t\t\t<Name>name</Name>\n' +
'\t\t\t<ForeColor Alpha="255" Red="0" Green="0" Blue="0" />\n' +
'\t\t\t<BackColor Alpha="0" Red="255" Green="255" Blue="255" />\n' +
'\t\t\t<LinkedObjectName />\n' +
'\t\t\t<Rotation>Rotation0</Rotation>\n' +
'\t\t\t<IsMirrored>False</IsMirrored>\n' +
'\t\t\t<IsVariable>False</IsVariable>\n' +
'\t\t\t<GroupID>-1</GroupID>\n' +
'\t\t\t<IsOutlined>False</IsOutlined>\n' +
'\t\t\t<HorizontalAlignment>Center</HorizontalAlignment>\n' +
'\t\t\t<VerticalAlignment>Middle</VerticalAlignment>\n' +
'\t\t\t<TextFitMode>AlwaysFit</TextFitMode>\n' +
'\t\t\t<UseFullFontHeight>True</UseFullFontHeight>\n' +
'\t\t\t<Verticalized>False</Verticalized>\n' +
'\t\t\t<StyledText>\n' +
'\t\t\t\t<Element>\n' +
'\t\t\t\t\t<String xml:space="preserve">Name</String>\n' +
'\t\t\t\t\t<Attributes>\n' +
'\t\t\t\t\t\t<Font Family="Arial" Size="24" Bold="True" Italic="False" Underline="False" Strikeout="False" />\n' +
'\t\t\t\t\t\t<ForeColor Alpha="255" Red="0" Green="0" Blue="0" HueScale="100" />\n' +
'\t\t\t\t\t</Attributes>\n' +
'\t\t\t\t</Element>\n' +
'\t\t\t</StyledText>\n' +
'\t\t</TextObject>\n' +
'\t\t<Bounds X="336" Y="1080" Width="5010" Height="1020" />\n' +
'\t</ObjectInfo>\n' +
'</DieCutLabel>';
var label = dymo.label.framework.openLabelXml(labelXml);
// set label text
label.setObjectText("name", "Scott Vitale");
// select printer to print on
// for simplicity sake just use the first LabelWriter printer
var printers = dymo.label.framework.getPrinters();
if (printers.length === 0) {
throw "No DYMO printers are installed. Install DYMO printers.";
}
// Build a LabelSetBuilder object and update the dynamic record.
var labelSetBuilder = new dymo.label.framework.LabelSetBuilder();
var record = labelSetBuilder.addRecord();
for (var i = 0; i < printers.length; ++i)
{
if (printers[i].printerType === "LabelWriterPrinter")
{
// Print a label on every printer
record.setTextMarkup("name", "Scott " + i.toString());
label.print(printers[i].name);
}
}
}
catch(e)
{
alert(e.message || e);
}
});
console.log('done.');
</script>
</head>
</html>
<?xml version="1.0" encoding="utf-8"?>
<DieCutLabel Version="8.0" Units="twips" MediaType="Default">
<PaperOrientation>Landscape</PaperOrientation>
<Id>LargeShipping</Id>
<IsOutlined>false</IsOutlined>
<PaperName>30256 Shipping</PaperName>
<DrawCommands>
<RoundRectangle X="0" Y="0" Width="3331" Height="5715" Rx="270" Ry="270" />
</DrawCommands>
<ObjectInfo>
<TextObject>
<Name>name</Name>
<ForeColor Alpha="255" Red="0" Green="0" Blue="0" />
<BackColor Alpha="0" Red="255" Green="255" Blue="255" />
<LinkedObjectName />
<Rotation>Rotation0</Rotation>
<IsMirrored>False</IsMirrored>
<IsVariable>False</IsVariable>
<GroupID>-1</GroupID>
<IsOutlined>False</IsOutlined>
<HorizontalAlignment>Center</HorizontalAlignment>
<VerticalAlignment>Middle</VerticalAlignment>
<TextFitMode>AlwaysFit</TextFitMode>
<UseFullFontHeight>True</UseFullFontHeight>
<Verticalized>False</Verticalized>
<StyledText>
<Element>
<String xml:space="preserve">Name</String>
<Attributes>
<Font Family="Arial" Size="24" Bold="True" Italic="False" Underline="False" Strikeout="False" />
<ForeColor Alpha="255" Red="0" Green="0" Blue="0" HueScale="100" />
</Attributes>
</Element>
</StyledText>
</TextObject>
<Bounds X="336" Y="1080" Width="5010" Height="1020" />
</ObjectInfo>
</DieCutLabel>
@svvitale
Copy link
Author

Both of these examples (Javascript and C#) complete successfully, but the printers do NOT print the labels. Sometimes a label gets sent to the wrong printer, sometimes they don't come out at all, sometimes Windows chokes and shows error/offline status for all printers.

2018-01-23 01_12_31-settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment