OK I see
Here is everything:
In scripts>Mofidy>DiscretizeArc:
DiscretizeArcInit.js:
function init(basePath) {
var action = new RGuiAction(qsTranslate("DiscretizeArc", "&DiscretizeArc"),
RMainWindowQt.getMainWindow());
action.setRequiresDocument(true);
action.setScriptFile(basePath + "/DiscretizeArc.js");
action.setIcon(basePath + "/DiscretizeArc.svg");
action.setDefaultShortcut(new QKeySequence("l,e"));
action.setDefaultCommands(["DiscretizeArc", "discretizearc", "discretize", "dis"]);
action.setGroupSortOrder(13200);
action.setSortOrder(300);
action.setWidgetNames(["ModifyMenu", "ModifyToolBar", "ModifyToolsPanel", "ModifyMatrixPanel"]);
}
current DiscretizeArc.js:
include("scripts/Modify/Modify.js");
/**
* \class DiscretizeArc
* \brief Discretizes an arc by a number of points.
* \ingroup ecma_modify
*/
function DiscretizeArc(guiAction) {
Modify.call(this, guiAction);
this.points = undefined;
this.entity = undefined;
this.pos = undefined;
this.setUiOptions("DiscretizeArc.ui");
}
DiscretizeArc.prototype = new Modify();
DiscretizeArc.State = {
ChoosingEntity : 0
};
DiscretizeArc.prototype.beginEvent = function() {
Modify.prototype.beginEvent.call(this);
this.setState(DiscretizeArc.State.ChoosingEntity);
};
DiscretizeArc.prototype.setState = function(state) {
Modify.prototype.setState.call(this, state);
this.getDocumentInterface().setClickMode(RAction.PickEntity);
this.setCrosshairCursor();
var appWin = RMainWindowQt.getMainWindow();
switch (this.state) {
case DiscretizeArc.State.ChoosingEntity:
var tr = qsTr("Choose an arc");
this.setLeftMouseTip(tr);
this.setCommandPrompt(tr);
break;
}
this.setRightMouseTip(EAction.trCancel);
};
DiscretizeArc.prototype.escapeEvent = function() {
switch (this.state) {
case DiscretizeArc.State.ChoosingEntity:
EAction.prototype.escapeEvent.call(this);
break;
}
};
DiscretizeArc.prototype.pickEntity = function(event, preview) {
this.error = "";
this.di = this.getDocumentInterface();
this.doc = this.getDocument();
var entityId = this.getEntityId(event, preview);
var entity = this.doc.queryEntity(entityId);
var pos = event.getModelPosition();
if (isNull(entity)) {
this.entity = undefined;
return;
}
switch (this.state) {
case DiscretizeArc.State.ChoosingEntity:
if (!this.isSupportedEntity(entity)) {
if (!preview) {
this.warnUnsupportedEntity();
}
break;
}
if (!EAction.assertEditable(entity, preview)) {
break;
}
this.entity = entity;
this.pos = pos;
if (preview) {
this.updatePreview();
}
else {
var op = this.getOperation(false);
if (!isNull(op)) {
this.di.applyOperation(op);
if (this.error.length!==0) {
EAction.handleUserWarning(this.error);
}
}
}
break;
}
};
DiscretizeArc.prototype.isSupportedEntity = function(entity) {
return isArcEntity(entity) ||
(RPolyline.hasProxy() && isPolylineEntity(entity));
};
DiscretizeArc.prototype.warnUnsupportedEntity = function() {
//if (RPolyline.hasProxy()) {
/* */EAction.warnNotArc();
// }
// else {
// EAction.warnNotLineArc();
// }
};
DiscretizeArc.prototype.getOperation = function(preview) {
if (isNull(this.pos) || isNull(this.entity) || !isNumber(this.points)) {
return undefined;
}
this.newEntity = DiscretizeArc.discretizeArc(this.entity, this.pos, this.points);
if (!this.newEntity) {
return undefined;
}
return new RAddObjectOperation(this.newEntity, this.getToolTitle(), false);
};
DiscretizeArc.prototype.getHighlightedEntities = function() {
var ret = [];
if (isEntity(this.newEntity)) {
ret.push(this.newEntity.getId());
}
return ret;
};
DiscretizeArc.prototype.slotPointsChanged = function(points) {
this.points = points;
};
/**
* Discretizes the given entity by the given number of points.
*
* \param entity Entity to discretize
* \param position Position clicked by the user
* \param points Number of points used to discretize the arc
*/
DiscretizeArc.discretizeArc = function(entity, position, points) {
//var di = this.getDocumentInterface(); -> stop because of this, trying to work with this.di
//var document = this.getDocument(); -> stop because of this, trying to work with this.doc
var op = new RAddObjectsOperation();
arcShape = entity.castToShape();
polylineShape = arcShape.approximateWithLines(10);
EAction.handleUserMessage("working 1");
var newEntity = new RPolylineEntity(this.doc, new RPolylineData(polylineShape));
EAction.handleUserMessage("working 2");
newEntity.setSelected(true);
EAction.handleUserMessage("working 3");
newEntity.copyAttributesFrom(entity.data());
EAction.handleUserMessage("working 4");
// Add new entity: (in getOperation)
// Delete original entity:
op.deleteObject(entity);
EAction.handleUserMessage("working 5");
this.di.applyOperation(op);
EAction.handleUserMessage("working 6");
return newEntity;
}
DiscretizeArc.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DiscretizeArc</class>
<widget class="QWidget" name="DiscretizeArc">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>177</width>
<height>46</height>
</rect>
</property>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="PointsLabel">
<property name="text">
<string>Points:</string>
</property>
<property name="buddy">
<cstring>Points</cstring>
</property>
</widget>
</item>
<item>
<widget class="RMathLineEdit" name="Points">
<property name="toolTip">
<string>Number of points to use for discretization</string>
</property>
<property name="text">
<string notr="true">10</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>RMathLineEdit</class>
<extends>QLineEdit</extends>
<header>RMathLineEdit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
DiscretizeArc.svg:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g transform="translate(0 492)"><g style="fill:none;stroke-linecap:square;stroke-width:16"><path d="m184-196l160-240" style="stroke:#000"/><path d="m184-196-96,144" style="stroke:#f00"/></g><path d="m355.79-288.46l26.709 17.625-70.5 106.84 26.709 17.625-92.94 53.689 12.812-106.56 26.709 17.625z" style="fill:#fff;stroke:#00f;color:#000;stroke-width:10"/><path d="m456.14-195.86l-28.877 38.859 30.375 40.998h-15.472l-23.24-31.373-23.24 31.373h-15.472l31.02-41.783-28.378-38.08h15.472l21.18 28.449 21.18-28.449h15.472"/></g></svg>
DiscretizeArc.pro:
NAME = $${TARGET}
SOURCES = $${TARGET}.js $${TARGET}Init.js
FORMS = $${TARGET}.ui
DiscretizeArc-inverse.svg:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g transform="translate(0 492)"><g fill="none" stroke-linecap="square" stroke-width="16"><path d="m184-196l160-240" stroke="#fff"/><path d="m184-196-96,144" stroke="#f00"/></g><g fill="#fff"><path d="m355.79-288.46l26.709 17.625-70.5 106.84 26.709 17.625-92.94 53.689 12.812-106.56 26.709 17.625z" stroke="#0cf" color="#000" stroke-width="10"/><path d="m456.14-195.86l-28.877 38.859 30.375 40.998h-15.472l-23.24-31.373-23.24 31.373h-15.472l31.02-41.783-28.378-38.08h15.472l21.18 28.449 21.18-28.449h15.472"/></g></g></svg>
We then store the .dxf and reuse it later into Blender. And Blender likes points.
As you can see, the Lengthen.js file really helped me, but I’m stuck at “EAction.handleUserMessage(“working 1”);” while running the script.
I cannot also run:
//var di = this.getDocumentInterface(); -> stop because of this, trying to work with this.di
//var document = this.getDocument(); -> stop because of this, trying to work with this.doc
but I don’t know why.
I have also touched some things in advance like with “this.newEntity” in getOperation or getHighlightedEntities and I still don’t know if it’s correct or if it will make this not working lol