Page 1 of 1
external editor
Posted: Fri May 28, 2010 7:46 pm
by hungerburg
Thank you for this nifty cad application. I want to create a script, that first pops up a dialogue asking some questions and then draws from the selections. From reading the web-pages I thought the following two possible:
- Have a button to start executing a script without going through the IDE,
- develop with another than the builtin editor (I am used to komodo-edit.)
The IDE can export and import, but can it also automatically sync the code with a file?
Regards
Peter
Code to explain my wish
Posted: Sat May 29, 2010 11:30 am
by hungerburg
Below my starting code, it makes me wish for an ecmascript interpreter that is more to the spec: especially introspection features are missing!
If you copy this to your IDE, then call the "layoutForm" function you may understand why I would like to have this a button in one of the application bars.
Will the upcoming 3.0 version help with my concerns? Please advise.
Peter
Code: Select all
/*
Die einzelnen Positionen im Formular mit Standardwerten:
G r u p p e n : M e r k m a l e : Ausprägungen
Array : Object : Array : Object : Array
Objekte wegen Namen in Arrays wegen der Reihenfolge.
*/
var Formular = [
{ name: "Hose", items: [
{ name: "Weite", value: 31 },
{ name: "Länge", value: 32 },
{ name: "Farbe", value: [ "weiß", "schwarz" ] }
]},
{ name: "Hemd", items: [
{ name: "Kragen", value: 15 },
{ name: "Ärmel", value: 32 },
{ name: "Farbe", value: [ "gelb", "rot" ] }
]},
{ name: "Jacke", items: [
{ name: "Kragen", value: 15 },
{ name: "Ärmel", value: 32 },
{ name: "Farbe", value: [ "braun", "blau" ] }
]},
{ name: "Schuhe", items: [
{ name: "Größe", value: 32 },
{ name: "Farbe", value: [ "braun", "schwarz" ] }
]},
{ name: "Datei", items: [
{ name: "Name", value: "Test" }
]}
]
// Kopie eines Objekts erstellen
function deepCopy(o) {
var copy = o,k;
if (o && typeof o === 'object') {
copy = (o instanceof Array) ? [] : {};
for (k in o) copy[k] = deepCopy(o[k]);
}
return copy;
}
// eine Gruppe erstellen
function addGroup(title) {
var gb = new GroupBox();
gb.title = title;
return gb;
}
// eine Texteingabe erstellen
function addLedit(label, text) {
var le = new LineEdit();
le.label = label;
le.text = text;
return le;
}
// eine Auswahlliste erstellen
function addNedit(label, value) {
var ne = new NumberEdit();
ne.label = label;
ne.value = value;
return ne;
}
// eine Auswahlliste erstellen
function addCombo(label, items) {
var cb = new ComboBox();
cb.label = label;
cb.itemList = items;
return cb;
}
// Das Formular auslegen: Gruppe : Merkmal : Ausprägung.
function layoutForm() {
var widgets = {};
var dialog = new Dialog();
dialog.title = "Mode Beispiel";
dialog.okButtonText = "Speichern"
dialog.cancelButtonText = "Abbrechen";
var F = deepCopy(Formular);
while (group = F.shift()) { // Gruppen
widgets[group.name] = addGroup(group.name);
widgets[group.name + "T"] = "Group";
dialog.add(widgets[group.name]);
while (param = group.items.shift()) { // Parameter
if (typeof param.value === "number") { // Wert: Zahl
widgets[group.name + param.name] = addNedit(param.name, param.value);
widgets[group.name + param.name + "T"] = "Nedit";
widgets[group.name].add(widgets[group.name + param.name]);
}
else if (typeof param.value === "string") { // Wert: Wort
widgets[group.name + param.name] = addLedit(param.name, param.value);
widgets[group.name + param.name + "T"] = "Ledit";
widgets[group.name].add(widgets[group.name + param.name]);
}
else if (param.value instanceof Array) { // Wert: Liste
var options = [];
while (value = param.value.shift())
options.push(value);
widgets[group.name + param.name] = addCombo(param.name, options);
widgets[group.name + param.name + "T"] = "Combo";
widgets[group.name].add(widgets[group.name + param.name]);
}
else {
var ans = MessageBox.warning("Unbekannter Datentyp im Formular!", MessageBox.Ignore);
}
}
}
// Fertig
if(dialog.exec()) {
fetchForm(widgets);
print ("OK");
} else {
print ("Cancel");
}
}
// Formulareingaben auslesen
function fetchForm(widgets) {
var F = deepCopy(Formular);
while (group = F.shift()) { // Gruppen
print(group.name);
while (param = group.items.shift()) { // Parameter
switch(widgets[group.name + param.name + "T"]) {
case "Nedit":
print ("+ " + param.name + ": " + widgets[group.name + param.name].value);
break;
case "Ledit":
print ("+ " + param.name + ": " + widgets[group.name + param.name].text);
break;
case "Combo":
print ("+ " + param.name + ": " + widgets[group.name + param.name].currentItem);
break;
}
}
}
}
Re: external editor
Posted: Sun May 30, 2010 2:35 pm
by hungerburg
So this is a real case of not RTFM. I looked through the gui, but its in the autostart.qs.
only minor nuisance now: the script is not reread, until after the whole program is restarted - this makes working with an external editor a little copious.
Thank You
peter
newbie questions
Posted: Mon May 31, 2010 10:12 am
by hungerburg
I should change the topic of all of this thread - newbie questions - now only this post.
I cannot get windows qcad-professional to auto-execute the autostart.qs, no matter where I put it.
The thing I miss the most at the moment is the ability to put my computed drawings in a block programmatically and to insert pre-existing blocks. and also the polyline scriptable entity to ease further hand-editing.
Anyways, I am making progress. qcad rocks!
peter
autostart.qs on windows
Posted: Mon May 31, 2010 6:16 pm
by hungerburg
Now I got that one: the correct location is
C:\Dokumente und Einstellungen\{username}\.qcad\autostart.qs
explorer will not let you create a directory that the name starts with a dot, but the dos-prompt cmd does: "mkdir .qcad".
Maybe was good to add to the documentation, this is an unusual config on windows.
peter