AndrewOriani / PyInventor

A Python based Autodesk Inventor API module!
MIT License
27 stars 7 forks source link

Some Examples #2

Open minssing97 opened 4 months ago

minssing97 commented 4 months ago

Hello I got to know Pyinventor from Github.

Please give me an example using the library.

For example,

Thank you.

AndrewOriani commented 4 months ago

Hi Minssing97,

I no longer maintain this project, but if you would like to get started you can find examples of tutorial notebooks in:

https://github.com/AndrewOriani/PyInventor/blob/main/_Tutorial_Notebooks/PyInventor%20Demo.ipynb

You will need to install PyInvent by running setup.py upon startup.

PyInventor never had much support for 3d sketchpoints, however it can do 2D splines. All of the underlying code is in VBA, and all of the objects for accessing functionality can be found at:

https://help.autodesk.com/view/INVNTOR/2023/ENU/

Click the left tab under ->Programming Interface->Inventor API Reference Manual->Objects.

The method you want is SketchControlPointSplines3D.Add, which can be found here:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-CFF63FD6-05FD-41FC-9E6F-CBB2A7E85B07

To make this work you will have to use _PyInvent.create_objcollection, where the collection is of 3D sketch points, which can be created using the object:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-C9A02DD8-8CA7-4F89-81CB-C3FCDFD14E17

The method for creating this should be similar to how the 2D spline creation works:

    def sketch_spline(self, sketch, points):
        sketch=sketch.sketch_obj
        pt_coll=self.new_obj_collection()
        pts=[self.point(pt) for pt in points]
        for pt in pts:
            pt_coll.Add(pt)
        spline=sketch.SketchSplines.Add(pt_coll)
        return spline

You will have to try it yourself, and will need to replace point with 3D point, and the 3D sketchspline for Spline, etc. Should be trivial otherwise. All of the source code can be found at, with the above at line 990:

https://github.com/AndrewOriani/PyInventor/blob/main/PyInventor/pyinvent.py

I would just make a fork and follow along the structure to add the above feature. You can largely use the existing example code for the setup.

Happy coding,

~Andrew