Cloning a Layer Object

This section is for general discussion about Gadgets

Cloning a Layer Object

Postby adriaan_w » Fri Jul 01, 2016 8:51 am

Hi,
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:

img1.JPG
test1_after_DXF_Import


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:

img2.JPG
test1_after_Nesting


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
    local layer
    layer, pos = layer_manager:GetNext(pos)
    if not layer.IsSystemLayer then
      local layer_pos = layer:GetHeadPosition()
      while layer_pos ~= nil do
        local object
        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
              end
            end
            curL.addedDups = 1 --flag indicating that the duplicates have been added.           
          end         
        end                     
      end
    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[1]
    for i = 1, duplicateLayerInfoCounter, 1 do
      curDup = duplicateLayerInfo[i]
      local pos1 = layer_manager:GetHeadPosition()
      while pos1 ~= nil do
        local layer1
        layer1, pos1 = layer_manager:GetNext(pos1)
        if (layer1.Name == curDup.associatedLayer.Name) then
          layer1:AddObject(curDup.CObjectForLayer, true)
        end
      end     
    end   
  end


Thanks,
Adriaan
adriaan_w
Vectric Apprentice
 
Posts: 2
Joined: Thu Jun 23, 2016 1:35 pm
Model of CNC Machine: Woodtech CNC

Re: Cloning a Layer Object

Postby BrianM » Fri Jul 01, 2016 2:13 pm

Hi Adriaan
You can't nest shapes with overlapping closed vectors as the nesting engine will try to make 'sensible' shapes out of overlapping vectors to keep them together when nesting. A simple example is letters a,e,o,b etc, the nesting will automatically keep this shapes together. After cloning, you need to move the shapes apart.
Brian
Brian Moran
Managing Director / CEO
Vectric Ltd.
User avatar
BrianM
Vectric Staff
 
Posts: 1937
Joined: Mon May 16, 2005 10:15 am
Location: Redditch U.K

Re: Cloning a Layer Object

Postby adriaan_w » Mon Jul 04, 2016 12:53 pm

Hi Brian,
Thank you very much for the reply and suggestion. I will shift the cloned shapes.

Thanks,
Adriaan
adriaan_w
Vectric Apprentice
 
Posts: 2
Joined: Thu Jun 23, 2016 1:35 pm
Model of CNC Machine: Woodtech CNC


Return to Gadgets - General

Who is online

Users browsing this forum: No registered users and 1 guest