// create and add a line entity:
QSharedPointer<RLineEntity> lineEntity =
QSharedPointer<RLineEntity>(newRLineEntity(document,RLineData(RVector(0,0),RVector(100,0))));// set attributes:
lineEntity->setLayerId(layerId);
lineEntity->setColor(RColor(0,128,255));
lineEntity->setLinetypeId(document->getLinetypeId("dashed"));
lineEntity->setLineweight(RLineweight::Weight100);// set a custom property:
lineEntity->setCustomProperty("MyApp","MyIntProperty",77);
lineEntity->setCustomProperty("MyApp","MyStringProperty","Some text");
op =newRAddObjectOperation(
lineEntity,false// false: don't use current attributes but // custom attributes set above);// add the line entity to the drawing:
documentInterface->applyOperation(op);
var appWin=RMainWindowQt.getMainWindow();var dock=appWin.findChild("FilterEditorDock");var entityTypeCombo=dock.findChild("comboBoxEntityType");var value=entityTypeCombo.currentIndex;
var appWin = EAction.getMainWindow();var buttons =newQMessageBox.StandardButtons(QMessageBox.Yes, QMessageBox.No);var ret = QMessageBox.warning(app,qsTr("Delete layer?"),qsTr("Do you wish to delete \"%1\" layer?").arg(fileToSave),
buttons);if(ret!=QMessageBox.Yes){}
获取图层
var di = EAction.getDocumentInterface();var doc=di.getDocument();var layer=doc.queryLayer("0");
layer.isProtected();
导入导出文件和修改
var storage =newRMemoryStorage();var spatialIndex =newRSpatialIndexSimple();var doc =newRDocument(storage, spatialIndex);var di =newRDocumentInterface(doc);
di.importFile("in.dxf");var op =newRModifyObjectsOperation();var ids = doc.queryAllEntities();for(var i=0; i<ids.length; i++){var id = ids[i];var entity = doc.queryEntity(id);
entity.setColor(newRColor("blue"));
op.addObject(entity,false);}
di.applyOperation(op);
di.exportFile("out.dxf","R24 (2010) DXF");
监听导出事件
var adapter =newRExportListenerAdapter();// register export listener:var appWin = EAction.getMainWindow();
appWin.addExportListener(adapter);// connect postExport signal to function ExExportListener.fileExported:
adapter.postExport.connect(function(documentInterface){if(isNull(documentInterface)){return;}print("file saved: ",documentInterface.getDocument().getFileName());});
事务监听
// create a new transaction listener:var adapter =newRTransactionListenerAdapter();var appWin = EAction.getMainWindow();
appWin.addTransactionListener(adapter);// connect transactionUpdated signal to a function that prints// information about the transaction:
adapter.transactionUpdated.connect(function(document, transaction){if(isNull(document)||isNull(transaction)){return;}var objIds = transaction.getAffectedObjects();
EAction.handleUserMessage(qsTr("Transaction affected %n object(s).","", objIds.length));if(objIds.length<10){
EAction.handleUserMessage("Object IDs: "+ objIds.join(','));}var i, objId;// show property changes of first 10 entities:for(i=0; i<objIds.length && i<10; i++){
objId = objIds[i];
EAction.handleUserMessage("Changed object ID: "+ objId);var pre =" ";var changes = transaction.getPropertyChanges(objId);for(var k=0; k<changes.length; k++){var change = changes[k];var pid = change.getPropertyTypeId();if(pid.isCustom()){// custom property was changed:
EAction.handleUserMessage(pre +"custom property:"+ pid.getPropertyTitle(),false);}else{// other property:// see RObject::Property*, REntity::Property*, RLineEntity::Property*, etc:
EAction.handleUserMessage(pre +"property type:"+ pid,false);}
EAction.handleUserMessage(pre +"old value:"+ change.getOldValue(),false);
EAction.handleUserMessage(pre +"new value:"+ change.getNewValue(),false);}}// show objects that were created or deleted:
objIds = transaction.getStatusChanges();for(i=0; i<objIds.length && i<10; i++){
objId = objIds[i];var obj = document.queryObjectDirect(objId);//isUndone==deleteif(obj.isUndone()){
EAction.handleUserMessage("Deleted object with ID: "+ objId);}else{
EAction.handleUserMessage("Created object with ID: "+ objId);}if(isLayer(obj)){
EAction.handleUserMessage("Object is layer");}elseif(isBlock(obj)){
EAction.handleUserMessage("Object is block");}elseif(isEntity(obj)){
EAction.handleUserMessage("Object is entity");}}});
增加删除 Entity Object
var di =this.getDocumentInterface();var document =this.getDocument();var op, entity, id;// add line entity,// document takes ownership of entity:
op =newRAddObjectsOperation();
entity =newRLineEntity(document,newRLineData(newRVector(0,0),newRVector(100,100)));
op.addObject(entity);
di.applyOperation(op);// after applying the operation, the ID of the newly added entity is known// and can be stored as reference for the added entity:
id = entity.getId();
EAction.handleUserMessage(qsTr("Added line with ID %1".arg(id)));// query a copy of the stored entity from the document// and use it to delete the entity:
entity = document.queryEntity(id);
op =newRDeleteObjectsOperation();
op.deleteObject(entity);
di.applyOperation(op);
EAction.handleUserMessage(qsTr("Deleted line with ID %1").arg(id));
EAction.handleUserMessage(qsTr("You can use <i>Edit > Undo</i> to restore the line entity."),false);
Draw 绘制 var di = this.getDocumentInterface(); var document = this.getDocument(); var op = new RAddObjectsOperation(); for (var h=0; h<=255; h+=16) { for (var v=0; v<=255; v+=16) { for (var s=0; s<=255; s+=16) {