Re: execute lua code for a currently open ipe file?

Otfried Cheong <[email protected]>
Newsgroups gmane.comp.graphics.ipe.general
Message-ID <[email protected]>
On 11/25/2011 10:57 PM, elwood151 wrote:
> So: is it possible to execute Lua code which reads and changes the currently
> open ipe file?
> (To load a changed ipelet, I have to relaunch ipe and with ipescript I can
> not see the selection instantly)

Yes - it's called an ipelet :-)  There is an ipelet around that allows 
you to reload all ipelets without quitting Ipe.

Attached is another ipelet that might be helpful.  You don't need to 
mess around with XML:  To select all objects with a certain stroke 
color, just select one of them, and then call "Select same -> stroke", 
and it will select all objects with the same stroke color.

Cheers,
  Otfried

_______________________________________________
Ipe-discuss mailing list
Ipe-discuss-rGrgPyRx506NN8uzcEdRPYRWq/[email protected]
http://lists.science.uu.nl/mailman/listinfo/ipe-discuss
selectsame.lua (text/x-lua, 1.2 KB)
----------------------------------------------------------------------
-- Select objects with same attribute as primary selection
----------------------------------------------------------------------

-- To assign a shortcut to first method (stroke), uncomment this:
-- shortcuts.ipelet_1_selectsame = "Alt+E"

label = "Select same"

about = [[
Select objects that have the same attribute value as the primary selection. 

This ipelet is part of Ipe.
]]

methods = {
  { label = "stroke" },
  { label = "fill" },
  { label = "pen" },
  { label = "dash" },
}

type = _G.type

function equal(a, b) 
  if type(a) == "table" and type(b) == "table" then
    -- must be colors
    return a.r == b.r and a.g == b.g and a.b == b.b
  else
    return a == b
  end
end

function run(model, num)
  local p = model:page()
  if not p:hasSelection() then
    model.ui:explain("no selection")
    return
  end
  local att = methods[num].label
  local prim = p:primarySelection()
  local val = p[prim]:get(att)

  p:deselectAll()

  for i = 1,#p do
    if equal(p[i]:get(att), val) then p:setSelect(i, 2) end
  end

  p:setSelect(prim, 1) -- select primary again
end

----------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.