My first Formit Plugin Help

My first Formit Plugin Help

pieter7
Advisor Advisor
1,187 Views
12 Replies
Message 1 of 13

My first Formit Plugin Help

pieter7
Advisor
Advisor

I'm trying to create my first plugin.

 

I'm following the steps described here: https://formit3d.github.io/FormItExamplePlugins/docs/HowTo.html

 

General questions

- In the instructions is says "NOTE:  Python will need to be in the path for the batch file to run. " Could you provide some more instructions on this

- Is there any way to verify whether the python server is running?

- Is there a command to uninstall/reinstall the plugin?

 

Specific API questions

 

I would like to create a plugin that allows you do make a selection and rotate it 90degrees clockwise. UX requirements: a toolbar with one button + a shortcut

 

I'm thinking of using WSM.Geom.MakeRotationTransform for this but I need a way to find the center point of the entire selection and run a Z vector through that.

 

- Is there API in place to get the bounding box of the selection?

- Any API I can use to get the center (X/Y) of the bounding box?

 

I'm sure more questions are going to show up while creating this plugin.

0 Likes
Accepted solutions (1)
1,188 Views
12 Replies
Replies (12)
Message 2 of 13

pieter7
Advisor
Advisor

So I read in the other topic that you've moved to an npm server . Is running the server a necessary step or can we just load plugins from a local directory (C drive)?

What happens when we change the code of a plugin after we've installed it? Do we need to uninstall/reinstall or do you recommand using LoadPlugin and reopen Formit?

0 Likes
Message 3 of 13

jeff_hauswirth
Autodesk
Autodesk

@pieter7 wrote:

So I read in the other topic that you've moved to an npm server . Is running the server a necessary step or can we just load plugins from a local directory (C drive)?

What happens when we change the code of a plugin after we've installed it? Do we need to uninstall/reinstall or do you recommand using LoadPlugin and reopen Formit?


 

It is required to run an http server to load a plugin. This is because the plugins were designed to work on both desktop and web.

To test that you have a server running correctly, open a browser and go to the plugin URL and add `/manifest.json` to the end of the URL.

For example, the URL for installing the HelloBlock is-

https://formit3d.github.io/FormItExamplePlugins/HelloBlock

And to test using the browser you do-

https://formit3d.github.io/FormItExamplePlugins/HelloBlock/manifest.json (This URL should work to see what it looks like)

So to test on your machine, run the server and open the URL in your browser-

http://localhost:8000/HelloBlock/manifest.json  (http://localhost:8000 may not be your localhost)

I would clone the https://github.com/FormIt3D/FormItExamplePlugins or https://github.com/FormIt3D/FormItWorkflowPlugins repos to your machine and practice with that.  The path you put after http://localhost:8000 is relative to the directory that you start the server in.   The server will be serving the files on your machine.

In your case, I'd clone FormItWorkflowPlugins and then make a copy of FlipAlong and start changing that.

 

I would just run FormIt.InstallPlugin("YOUR_URL"); so that all you have to do is restart FormIt to reload your script changes.

 

I can go into more details if you don't get this working.  The most important thing is to be able to view your local 

 

0 Likes
Message 4 of 13

pieter7
Advisor
Advisor

Hey Jeff,

 

I appreciate you helping me out. I've never run an NPM http-server and an getting a bit lost. 

 

- In installed Node.js  (https://nodejs.org/en/download/)

- Using the windows command line I then ran "npm install http-server -g" (I got "added 25 packages from 28 contributors")

- But now I'm lost on how to actually launch the server. I tried "http-server" in the Node.js commandline but I'm getting "ReferenceError: server is not defined". I also tried running http-server in the windows command line but I am getting "http-server is not recognized as an internal or external command, operable program or batch file"

0 Likes
Message 5 of 13

jeff_hauswirth
Autodesk
Autodesk
Accepted solution

@pieter7 wrote:

- But now I'm lost on how to actually launch the server. I tried "http-server" in the Node.js commandline but I'm getting "ReferenceError: server is not defined". I also tried running http-server in the windows command line but I am getting "http-server is not recognized as an internal or external command, operable program or batch file"


Here's a good tutorial- http://jasonwatmore.com/post/2016/06/22/nodejs-setup-simple-http-server-local-web-server

 

Sounds like you ran node from the command prompt.

You need to run http-server from the command prompt.

 

 

0 Likes
Message 6 of 13

pieter7
Advisor
Advisor

I think maybe the http-server package wasn't installed globally (although I used the -g flag). Any idea on how to do this?

0 Likes
Message 7 of 13

pieter7
Advisor
Advisor

Ok got it working now! apparently there are two Node.js command prompts and I was running it in the wrong one.

 

Next step is getting my clone of the 'flip along axis plugin' to work in formit.

 

 

0 Likes
Message 8 of 13

pieter7
Advisor
Advisor

Ok I got the plugin window showing up in Formit! Awesome.

 

Now next step: Jeff, could you perhaps point me in the right direction for this:

 

I would like to create a plugin that allows you do rotate the selection 90degrees clockwise (around the Z axis).

 

I'm thinking of using WSM.Geom.MakeRotationTransform for this but first I need a way to find the center point of the entire selection and run a Z vector through that.

 

- Is there API in place to get the bounding box of the selection?

- Any API I can use to get the center (X/Y) of the bounding box?

0 Likes
Message 9 of 13

jeff_hauswirth
Autodesk
Autodesk

- Is there API in place to get the bounding box of the selection?

- Any API I can use to get the center (X/Y) of the bounding box?


 

All the docs are reached from here- https://formit3d.github.io/FormItExamplePlugins/

These are old docs, but will work for v16.

WSM API docs are found here also- https://formit3d.github.io/FormItExamplePlugins/docs/FormItJSAPI/index.html

You can dig down from there to find FormIt and WSM APIs.

The selection API docs- https://formit3d.github.io/FormItExamplePlugins/docs/FormItJSAPI/group__mod__jsapi__formit__selectio...

You can see how to get the BB in this code- https://github.com/FormIt3D/FormItWorkflowPlugins/blob/master/FlipAlong/flipalong.js#L9

And documented here- https://formit3d.github.io/FormItExamplePlugins/docs/FormItJSAPI/group__mod__jsapi__wsm__utils.html#...

 

0 Likes
Message 10 of 13

pieter7
Advisor
Advisor

Ok I'm halfway there.

 

Plugin is loading as expected

Toolbar is appearing

I've determined the midpoint of selection

I've got the Z vector through that midpoint

 

But I'm stuck at this point:

 

angle = 90;
var rotation = WSM.Geom.MakeRotationTransform(rotationcenter,angle) // make a copy of geometry using the given translation for testing purposes WSM.APICopyOrSketchAndTransformObjects(nHistoryID, nHistoryID, nObjectID, rotation, 1 /*one copy */, false /*bGroupBodies*/);

My rotation does not seem to be 90degrees. Is is expecting another input then degrees for the rotation angle?

0 Likes
Message 11 of 13

pieter7
Advisor
Advisor

Figured it out, was expecting Radians!

 

So next step is finding an API call to change the rotation of an existing element rather then copying a new one by rotation.

0 Likes
Message 12 of 13

pieter7
Advisor
Advisor

Got it! All done

 

I used  WSM.APITransformObjects(nHistoryID,nObjectID,rotation) 

0 Likes
Message 13 of 13

josh.goldstein
Community Manager
Community Manager

Awesome Pieter, great work! We appreciate you keeping us updated on your progress. It's exciting to see customers trying out FormIt Plugins.

 

We overhauled our plugin documentation for anyone else who is looking for assistance. These will also be updated in the near future to reflect API and UI improvements coming in the next version of FormIt. 

Using FormIt Plugins
Building FormIt Plugins




Josh Goldstein
Senior Product Manager
0 Likes