Creating a Graphic via a Plugin

Are you developing tools to extend the LiveCode environment? This is the place to talk about the nuts and bolts of extending our nuts and bolts. If you want to use a LiveCode or third party Environment extension, visit the Using Evironment Extensions forum.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
hrcap
Posts: 76
Joined: Mon Jan 14, 2019 5:20 pm

Creating a Graphic via a Plugin

Post by hrcap » Tue May 12, 2020 1:40 pm

Hi All

I hope that everyone is well.

I have recently started to make plugins to speed up development. Ive come across a bit of a sticking point in that I can't get the plugin to create a graphic in the 'target card'.

Any tips as to where I am going wrong would be much appreciated (Code Below):


Many Thanks


Code: Select all


Created: 2020 05 12
Created By: HP
Modified: 2020 05 12
Modified By: HP
----------------------------------
--This is trying to create a line
----------------------------------

on mouseup
   
   -----
   put the loc of the selectedobject into t_loc
   put the width of the selectedobject into t_width
   -----
   
   put the name of the topstack into t_stack
   
   put the cardids of t_stack into t_card
   
   answer the name of card t_card of stack t_stack
   
   -----
   create Graphic "rt_div_line" in t_card of t_stack
   -----
   
   
   set the width of it to t_width
   set the height of it to "2"
   
   set the loc of it to t_loc
   
   put the left of it into t_left
   put the right of it into t_right
   
   -----
   --sets the style of it
   set the style of it to "line"
   -----
   
   -----
   --sets the line points
   put t_left & "," & item "2" of t_loc into t_points_line_1
   put t_right & "," & item "2" of t_loc into t_points_line_2
   
   put t_points_line_1 & \
         return & \
         t_points_line_2 & \
         "" into t_points
   
   
   set the points of it to t_points
   -----
   
end mouseup




PaulDaMacMan
Posts: 259
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Creating a Graphic via a Plugin

Post by PaulDaMacMan » Tue May 19, 2020 3:49 am

I use message box a lot to help me debug, and then comment them out later once things are working, like this:

Code: Select all

   put the long name of the topstack into t_stack  --<-- the long name could do the trick
   put t_stack & cr --- <-- comment out later
   put the cardids of t_stack into t_cards -- <-- notice that I changed this variable name to plural
   put t_cards & cr after msg  --- <-- comment out later
   create Graphic "rt_div_line" in card id (line 1 of t_cards) of t_stack
 
Note that 'the CardIDs' will return a line delimited list of card ID numbers of cards in the target stack, so you probably want to use ..."in card ID (line x of t_cards) of stack t_stack"... and iterate through the cards in a repeat loop (I don't know what your goal is)
Last edited by PaulDaMacMan on Wed May 20, 2020 3:51 am, edited 2 times in total.
https://github.com/PaulMcClernan

kdjanz
Posts: 181
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Creating a Graphic via a Plugin

Post by kdjanz » Tue May 19, 2020 7:24 am

When I have been creating graphic lines, I also have to pay attention to the layer. The line was drawing and my points were there, but it was underneath other objects with a layer or 3 or 4, so I ended up putting an arbitrary 1000 into the layer property to pop it up to the top.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5356
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Creating a Graphic via a Plugin

Post by jacque » Tue May 19, 2020 3:46 pm

The layer syntax includes this handy shortcut: set the layer of <object> to top
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

hrcap
Posts: 76
Joined: Mon Jan 14, 2019 5:20 pm

Re: Creating a Graphic via a Plugin

Post by hrcap » Fri May 22, 2020 12:05 am

Thats wonderful, thank you very much all for your input, I have just had a play around with your suggestions... It has however lead me to another sticking point, is there a way to return the card of the selected object?


Many Thanks

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2464
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Creating a Graphic via a Plugin

Post by jmburnod » Fri May 22, 2020 10:41 am

Hi,
is there a way to return the card of the selected object?

Code: Select all

put long name of the selectedobject
should do the job
Best regards
Jean-Marc

hrcap
Posts: 76
Joined: Mon Jan 14, 2019 5:20 pm

Re: Creating a Graphic via a Plugin

Post by hrcap » Fri May 22, 2020 11:04 am

Hi Jean-Marc

thanks for the swift reply, that is the method that I had been playing around with, with the aim of getting the card name of the selected object so that I can rename the card but I am getting an error saying:

error: execution error at line 38 (Chunk: can't find card), char 1

Code: Select all


--renames the card
   put the long name of the selectedobject into t_card
   put offset("card id",t_card) into t_a
   delete char "1" to (t_a - "1") of t_card
   delete char "13" to "-1" of t_card
   -- we now have the name of the card
   put the long id of the topstack into t_stack
   --put the long name of card t_card of t_stack
   
   
   --** The following line is line 38 producing the ERROR **--
   set the name of card t_card of t_stack to t_name
   breakpoint



Again help shedding light on this would be greatly appreciated


Many Thanks

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2464
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Creating a Graphic via a Plugin

Post by jmburnod » Fri May 22, 2020 5:47 pm

Hi,
You can't use quote with integer and t_name seems empty.
Try this (no tested):

Code: Select all

--renames the card
   get word 5 of long name of the selectedobject 
   replace quote with empty in it
   put it into t_card
   -- we now have the name of the card
   put the long id of the topstack into t_stack
   --put the long name of card t_card of t_stack
   
   --** The following line is line 38 producing the ERROR **
   put "theNewNameOfCd" into t_name
   set the name of card t_card of t_stack to t_name
   breakpoint
Jean-Marc

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5356
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Creating a Graphic via a Plugin

Post by jacque » Fri May 22, 2020 6:12 pm

If the object is not in a group, try this:

Code: Select all

put the owner of the selectedobject into tCard
set the name of tCard to "newName"
If it is in a group you'd need "the owner of the owner".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7668
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Creating a Graphic via a Plugin

Post by FourthWorld » Fri May 22, 2020 6:15 pm

The selectedObject is usually on the current card. If you already know the stack, "this" will suffice as a card specifier, e.g.:

Code: Select all

get the long id of this cd of stack "TheOneImWorkingOn"
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

hrcap
Posts: 76
Joined: Mon Jan 14, 2019 5:20 pm

Re: Creating a Graphic via a Plugin

Post by hrcap » Fri May 22, 2020 8:35 pm

Evening Guys

Thank you very much for your suggestions, I have tried both

Code: Select all

put the owner of the selectedobject into tCard
set the name of tCard to "newName"

and

Code: Select all

get the long id of this cd of stack "TheOneImWorkingOn"
and unfortunately neither rename the card that the selectedobject belongs to.


Maybe it isn't possible to rename a card from a plugin

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7668
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Creating a Graphic via a Plugin

Post by FourthWorld » Fri May 22, 2020 10:20 pm

Plugins are just stacks with scripts. Any script can modify any object available in the session.

The second example only gets the card's long ID, which is then put into local variable "it". Add a statement to "set the name of it to NewName" and you should be good.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

hrcap
Posts: 76
Joined: Mon Jan 14, 2019 5:20 pm

Re: Creating a Graphic via a Plugin

Post by hrcap » Fri May 22, 2020 10:30 pm

Wonderful thank you Richard

That has done it, very much appreciated, this will help me to save some time when I am setting up data grids.

Many Thanks

Post Reply

Return to “Making IDE Plugins”