Page 1 of 1

Creating a Graphic via a Plugin

Posted: Tue May 12, 2020 1:40 pm
by hrcap
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




Re: Creating a Graphic via a Plugin

Posted: Tue May 19, 2020 3:49 am
by PaulDaMacMan
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)

Re: Creating a Graphic via a Plugin

Posted: Tue May 19, 2020 7:24 am
by kdjanz
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.

Re: Creating a Graphic via a Plugin

Posted: Tue May 19, 2020 3:46 pm
by jacque
The layer syntax includes this handy shortcut: set the layer of <object> to top

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 12:05 am
by hrcap
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

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 10:41 am
by jmburnod
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

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 11:04 am
by hrcap
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

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 5:47 pm
by jmburnod
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

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 6:12 pm
by jacque
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".

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 6:15 pm
by FourthWorld
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"

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 8:35 pm
by hrcap
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

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 10:20 pm
by FourthWorld
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.

Re: Creating a Graphic via a Plugin

Posted: Fri May 22, 2020 10:30 pm
by hrcap
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