Thanks for your answer.
I tried with you suggestions, but it did not work. I realized know, that i also handled the code probably in a strange way, cause i am interacting the first time in the code with teh ui an i am sure its really not well done. Here is the full coden
include("scripts/EAction.js");
// todo ok Button übernehmen in Ausführen
function Rohrbezeichnung(guiAction) {
EAction.call(this, guiAction);
this.pos = undefined;
this.radius = undefined;
this.setUiOptions("Rohrbezeichnung.ui");
}
Rohrbezeichnung.prototype = new EAction();
Rohrbezeichnung.prototype.beginEvent = function() {
EAction.prototype.beginEvent.call(this);
var di = this.getDocumentInterface();
di.setClickMode(RAction.PickCoordinate);
};
Rohrbezeichnung.prototype.pickCoordinate = function(event, preview) {
this.pos = event.getModelPosition();
if (preview) {
this.updatePreview();
}
else {
this.applyOperation();
}
};
Rohrbezeichnung.prototype.getOperation = function(preview) {
};
Rohrbezeichnung.prototype.slotcb_durchmesserChanged = function(v) {
this.durchmesser = v;
this.updatePreview();
};
Rohrbezeichnung.prototype.slotcb_pnChanged = function(v) {
this.PN = v;
this.updatePreview();
};
Rohrbezeichnung.prototype.slotccb_werkstoffChanged = function(v) {
this.werkstoff = v;
this.updatePreview();
};
Rohrbezeichnung.prototype.slotcb_postfixChanged = function(v) {
this.postfix = v;
this.updatePreview();
};
Rohrbezeichnung.prototype.slotcb_praefixChanged = function(v) {
this.praefix = v;
this.updatePreview();
};
Rohrbezeichnung.prototype.slotbut_ok = function() {
var appWin = EAction.getMainWindow();
if (isNull(this.durchmesser) && this.ok == false) {
return undefined;
}
var appWin = EAction.getMainWindow();
appWin.handleUserMessage(isNull(this.ok).toString())
appWin.handleUserMessage("durchmesser und ok")
appWin.handleUserMessage("Rohrleitungen beschriften")
var doc = this.getDocument();
var di = this.getDocumentInterface();
var op = new RAddObjectsOperation();
var ids = doc.queryAllEntities();
appWin.handleUserMessage(ids.length.toString())
for (var i=0; i<ids.length; i++) {
var id = ids[i];
var entity = doc.queryEntity(id);
if (isPolylineEntity(entity) &&
( entity.getLayerName().indexOf("Räume") == -1 ) && // nicht auf Räumelayer
(entity.getLayerName().indexOf("Räume") == -1 ) && // nicht auf Messlinielayer
(entity.getLayerName().indexOf(" ... ") != -1 ) && // nur Sublayer
(entity.isVisible())
) {
var dn = entity.getCustomProperty("QCAD","DN","no") // no steht für Wert nicht vorhanden
if (dn == "no") entity.setCustomProperty("QCAD","DN","").setList("sdjfl,"); //wenn Property nicht vorhanden dann hinzufügen
if (dn =="no") dn = "";
var rohrbezHandle = entity.getCustomProperty("QCAD","rohrbezHandle","no") // no steht für Wert nicht vorhanden
if (rohrbezHandle == "no") entity.setCustomProperty("QCAD","rohrbezHandle",""); //wenn Property nicht vorhanden dann hinzufügen
if (rohrbezHandle =="no") rohrbezHandle = "";
var zoll = entity.getCustomProperty("QCAD","Zoll","no") // no steht für Wert nicht vorhanden
if (zoll == "no") entity.setCustomProperty("QCAD","Zoll",""); //wenn Property nicht vorhanden dann hinzufügen
if (zoll =="no") zoll = "";
var werkstoff = entity.getCustomProperty("QCAD","Werkstoff","no")
if (werkstoff == "no") entity.setCustomProperty("QCAD","Werkstoff",""); //wenn Property nicht vorhanden dann hinzufügen
if (werkstoff =="no") werkstoff = "";
var pn = entity.getCustomProperty("QCAD","PN","no")
if (pn == "no") entity.setCustomProperty("QCAD","PN",""); //wenn Property nicht vorhanden dann hinzufügen
if (pn =="no") pn = "";
var prefix = entity.getCustomProperty("QCAD","Prefix","no")
if (prefix == "no") entity.setCustomProperty("QCAD","Prefix",""); //wenn Property nicht vorhanden dann hinzufügen
if (prefix =="no") prefix = "";
var postfix = entity.getCustomProperty("QCAD","Postfix","no")
if (postfix == "no") entity.setCustomProperty("QCAD","Postfix",""); //wenn Property nicht vorhanden dann hinzufügen
if (postfix =="no") postfix = "";
op.addObject(entity,false);
var rohrbezeichnung = ((prefix!="") ? prefix +" ":"")+ ((dn!="") ? "DN"+dn +" ":"") + ((zoll!="") ? zoll +"\" ":"")+ ((pn!="") ?" PN"+pn +" ":" ") + werkstoff +((postfix!="") ?" "+ postfix :"")
// addSimpleText("standard", xBeschriftung, yBeschriftung); // string, font, center x, center y, height, bold, italic, V align, H align
if (rohrbezeichnung != " ") { // wenn rohbbez. nicht leer
// appWin.handleUserMessage(Math.floor(entity.countVertices()/2).toString());
var v1 = Math.floor(entity.countVertices()/2);
// appWin.handleUserMessage(v1.toString());
var v2 = v1-1;
// appWin.handleUserMessage(v2.toString());
var x1 = entity.getVertexAt(v1).x;
var x2 = entity.getVertexAt(v2).x;
var y1 = entity.getVertexAt(v1).y;
var y2 = entity.getVertexAt(v2).y;
// appWin.handleUserMessage(x1.toString());
// appWin.handleUserMessage(x2.toString());
// appWin.handleUserMessage(y1.toString());
// appWin.handleUserMessage(y2.toString());
var xBeschriftung = (x1+x2)/2;
var yBeschriftung = (y1+y2)/2;
// appWin.handleUserMessage("Beschriftung");
// appWin.handleUserMessage(xBeschriftung.toString());
// appWin.handleUserMessage(yBeschriftung.toString());
// appWin.handleUserMessage(rohrbezeichnung.toString());
// appWin.handleUserMessage(entity.getLayerName().toString());
appWin.handleUserMessage(entity.getLayerName())
doc.setCurrentLayer(entity.getLayerName().toString());//Rohbezeichnung auf den Rohrtextlayer
appWin.handleUserMessage("Layer angepasst")
var rohrbezHandle = entity.getCustomProperty("QCAD","rohrbezHandle","no")
appWin.handleUserMessage(rohrbezHandle.toString())
appWin.handleUserMessage((!isNull(doc.queryObjectByHandle(Number(rohrbezHandle)))).toString())
if ((rohrbezHandle == "no")||(rohrbezHandle == "")|| //Wenn Rohrbezeichnungsid bei Rohr noch nicht vorhanden Oder
// (doc.queryObjectByHandle(Number(rohrbezHandle)).isUndone())||
isNull(doc.queryObjectByHandle(Number(rohrbezHandle)))){//Wenn Rohrbezeichnungs geöscht wurde
appWin.handleUserMessage("Neue Bezeichnung setzen")
//Versuche Block einzufügen
// Block mit passender höhe
block = doc.queryBlock("Rohrbezeichnungen");
EAction.handleUserMessage(block.toString())
idBlock =block.getId()
var bd = new RBlockReferenceData( idBlock,
new RVector(xBeschriftung,yBeschriftung),// position
new RVector(1,1),
0, //angel
1, //columncont
1,//rowcount
1,//colunspacing
1)
var blockRef = new RBlockReferenceEntity(doc,bd)
op.addObject(blockRef);
// create attribute for each attribute definition in block:
var blockRefId = doc.getStorage().getMaxObjectId();
var idsBE = doc.queryBlockEntities(idBlock);
for (var k=0; k<idsBE.length; k++) {
var idBE = idsBE[k];
var attDef = doc.queryEntity(idBE);
if (!isAttributeDefinitionEntity(attDef)) {
EAction.handleUserMessage("nix")
continue;
}
EAction.handleUserMessage("schon")
var att = new RAttributeEntity(
doc,
new RAttributeData(attDef.getData(), blockRefId, attDef.getTag())
);
att.setBlockId(idBlock);
EAction.handleUserMessage(attDef.getTag().toString())
// att.setInvisible(attDef.isInvisible());
blockRef.applyTransformationTo(att);
att.setText("sdkfjsöl");
op.addObject(att, false);
// di.applyOperation(op);
}
EAction.handleUserMessage("dhsflkd")
//Text erstellen und id schreiben
//Beschriftung einfügen
di.selectEntity(Number(rohrbezHandle), false);
var textPos = new RVector(xBeschriftung,yBeschriftung);
var textData = new RTextData(
textPos, // position
textPos, // alignment point
1, // height
1.0, // text width (ignored for now)
RS.VAlignBottom, // alignments
RS.HAlignCenter,
RS.LeftToRight,
RS.Exact,
1.0, // line spacing factor
rohrbezeichnung, // the text
"Corble", // font
false, // bold
false, // italic
0.0, // angle
true // simple text without formatting
);
if (x1==x2) textData.setAngle(1.5707963268); //wenn senkrecht auf 90 grad drehen
var text = new RTextEntity(doc, textData);
op.addObject(text,false);
di.applyOperation(op);
op = new RAddObjectsOperation();
var rohrbezHandle = text.getHandle().toString()
entity.setCustomProperty("QCAD","rohrbezHandle",rohrbezHandle);
//custom property zu Rohr hinzufügen
op.addObject(entity,false);
}else{// nur text ändern wenn bei Rohr Verweis auf eine Bezeichnung
appWin.handleUserMessage("nur Text der Rohrbezeichnung anpassen")
// appWin.handleUserMessage(rohrbezHandle.toString())
obj = doc.queryObjectByHandle(Number(rohrbezHandle));
var text = doc.queryEntity(obj.getId());
text.setText(rohrbezeichnung); //text akutalisieren
// appWin.handleUserMessage(text.isUndone().toString())
op.addObject(text,false);
di.applyOperation(op);
}
}
// appWin.handleUserMessage("Rohrbezeichnung fertig")
}
}
di.applyOperation(op);
di.killAllActions() // um in den selectionsmode zurückzukommen
};
Rohrbezeichnung.init = function(basePath) {
var action = new RGuiAction(qsTr("&Rohrbezeichnung"), RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/Rohrbezeichnung.js");
action.setGroupSortOrder(16600000);
action.setSortOrder(3);
action.setWidgetNames(["H2OfficeMenu"]);
};