Jump to content


Photo

Accessing Autoshapes through javascript API


  • Please log in to reply
3 replies to this topic

#1 mitya777

mitya777

    FireStarter

  • Members
  • PipPip
  • 28 posts

Posted 21 January 2011 - 03:59 PM

Hi guys, newbie/first time poster here. I am trying to create an extension and would like to use the measuring tool autoshape that is on the vector panel. Is there a way I could call it like I would dom.addLine() and manipulate it through javascript? I am working in CS5. Is there a function for this or do I have to include and possibly modify the autoshape script inside my extension script? Or am I totally missing something?

Thank you all for your help.

#2 mitya777

mitya777

    FireStarter

  • Members
  • PipPip
  • 28 posts

Posted 22 January 2011 - 06:24 PM

So I figured out how to insert the AutoShape onto the canvas. dom.insertSmartShape(). However, I am still trying to figure out how to manipulate the autoShape through the API. Is there a way I can move control points and set other properties programatically through javascript? The only ways that I can figure out right now are through the autoshape properties panel and through user input. It seems like I should be able to do something like fw.selection[0].controlPoints[0].x = 300; but I haven't been able to figure out the exact calls to do this. Do they exist? If so, where/how?

Thanks!

#3 jdunning

jdunning

    Fireworks Ninja

  • Members
  • PipPipPipPipPip
  • 173 posts

Posted 25 January 2011 - 09:33 PM

It seems like I should be able to do something like fw.selection[0].controlPoints[0].x = 300; but I haven't been able to figure out the exact calls to do this. Do they exist? If so, where/how?

I think what you're looking for is the dom.redrawSmartShape() method. Calling that should trigger your shape's RedrawSmartShape handler, which doesn't seem to be documented in the Extending FW doc. Take a look at the .jsf files in C:\Program Files\Adobe\Adobe Fireworks CS5\Configuration\Auto Shape Tools for examples of shapes that listen for this event.

You can also take a look at the KeyboardResize.js file in my extension: http://johndunning.c.../KeyboardResize

When resizing the selection via the keyboard, this extension checks whether an element in the selection is an auto shape. If it is, it sets a new width and height on the shape's customData and then calls dom.redrawSmartShape(). Most of the built-in shapes seems to look for width and height values on customData to determine their size. So setting the size values on customData and then calling the redrawSmartShape() method should cause the shapes to redraw at the new size.

#4 mitya777

mitya777

    FireStarter

  • Members
  • PipPip
  • 28 posts

Posted 26 January 2011 - 01:44 PM

Thank you very much for your help! I was moving the control points and then trying to redraw but it would just go back to the same shape. It looks like it is the customData points it was looking for so I think I can start to make some progress on this.

Thank you again, always nice to have someone with experience chime in, makes things that much easier.