I am currently writing 2 gadgets for Aspire 8 that are very near completion.
The goal of my gadgets is to read in a DXF file, as well as a custom config file - the custom config file contains tool information relating to the layer names in the DXF file - with the first gadget, then have the user apply nesting (as it looks like I cannot nest through the LUA API), and finally, with the second gadget apply the relevant tool paths to generate the GCode.
So far everything works. BUT, in my config file, I can also specify a quantity for each group of shapes/vectors.
My idea here is, once the DXF file has been read, to go through every shape on every non-system layer (every shape that has a different tool gets placed on a different layer), and if the corresponding config file says that it has a quantity, n, of more than one, I call object:Clone() to that layer n times. This will place the duplicate shapes on top of the original shape.
My issue: NOT all duplicate shapes are nested.
Here is an example:
This is the original layout after the first gadget has opened the DXF:
You can clearly (I apologize if the picture quality is lacking) see that there is a copy of each vector underneath the original layers.
After selecting all the vectors and nesting I get the following result:
As you can see, only one of the vectors/layers separated the duplicate from the original, while the other 2 triangle vectors still have their duplicates underneath the original (I have purposefully re-selected the vectors so that you can see the duplicate vectors are still present). This kind of inconsistency makes me think that this is an Aspire issue, and not a gadget issue.
Also, after running my second gadget, the tool paths get applied to the original and the duplicate vectors, which means that I am cutting the same vector in the same place twice for the vectors where the duplicates didn't move.
I have also tried grouping the objects together before nesting, and this creates an even larger problem, as rectangular shapes get generated out of no where around the triangles that don't separate.
This is how I do it in the code:
- Code: Select all
local layer_manager = job.LayerManager
local pos = layer_manager:GetHeadPosition()
while pos ~= nil do
layer, pos = layer_manager:GetNext(pos)
if not layer.IsSystemLayer then
local layer_pos = layer:GetHeadPosition()
while layer_pos ~= nil do
object, layer_pos = layer:GetNext(layer_pos)
local cadOb = job.LayerManager:GetLayerWithId(object.RawLayerId)
for i=1, layerCount, 1 do --layerCount and layers relate to an array of objects storing cfg file info.
curL = layers[i]
if ((curL.layerName == cadOb.Name) and (curL.dupIndicator == "True")) then --dupIndicator is used to tell if this layer should be used for duplication
for k = 1, curL.quantity, 1 do
if (k > 1) then
local tmpDuLayerInfo = duplicateQuantities(layer, object:Clone())
duplicateLayerInfoCounter = duplicateLayerInfoCounter + 1
duplicateLayerInfo[duplicateLayerInfoCounter] = tmpDuLayerInfo
curL.addedDups = 1 --flag indicating that the duplicates have been added.
end -- end of for each object on layer
end -- end of for each layer
--go through duplicateLayerInfo array and add the objects to the correct layers.
if (duplicateLayerInfoCounter > 0) then
local i = 0
local curDup = duplicateLayerInfo
for i = 1, duplicateLayerInfoCounter, 1 do
curDup = duplicateLayerInfo[i]
local pos1 = layer_manager:GetHeadPosition()
while pos1 ~= nil do
layer1, pos1 = layer_manager:GetNext(pos1)
if (layer1.Name == curDup.associatedLayer.Name) then