Jump to content
3DCoat Forums

Python scripting - API ( Addon development)


crudodev
 Share

Recommended Posts

  • Member

Hello, I'm just wondering—how can I skip the "Save As" dialog menu when saving a layer to .obj, .fbx, etc.? I just want to programmatically pass the path for the 3D model without dealing with dialog menus.

Also, is it necessary to switch to the Retopo room for model decimation, or can we avoid that as well and just set the decimation level as an argument?

Same goes for importing into the current level—how can I programmatically use an object path as an argument and avoid the dialog menu?

Thanks

Link to comment
Share on other sites

  • Member
Carlosan
This post was recognized by Carlosan!

crudodev was awarded the badge 'Great Content' and 1 points.

Okay, I found a solution in the documentation. To prevent the pop-up dialog menu and pass the file path, we can use the following method:

coat.ui.setFileForFileDialog(se.exportMesh)
  • Like 1
Link to comment
Share on other sites

  • Member

Just playing around with the Python API—Is it possible to create one Python add-on that has its own submenu with different buttons? Or do I have to create a separate "script" for each action?

Also, I found that only with C++ we can create custom sculpt tools integrated into the UI, similar to the tree generator C++ add-on from the examples. Correct me if I'm wrong.

Link to comment
Share on other sites

You mean this ?

image.png

Scripts Menu > CreatePythonScript > Basic... > Dialogs.py

image.png

  • Like 1
Link to comment
Share on other sites

  • Member

I meant more like this: I made a workaround where each button is an independent script (Python package) in the context of 3DCoat.

But ideally, it would be great to create a custom menu—one add-on with multiple modules and subpackages.

Edit: Ah, I see! There are examples showing how to insert into the Tools panel and menus. Thanks!


image.png.05bf0593ddd8e634f000e28cdb806246.png

  • Like 1
Link to comment
Share on other sites

On 3/22/2025 at 8:14 AM, crudodev said:

Hello, I'm just wondering—how can I skip the "Save As" dialog menu when saving a layer to .obj, .fbx, etc.? I just want to programmatically pass the path for the 3D model without dealing with dialog menus.

Also, is it necessary to switch to the Retopo room for model decimation, or can we avoid that as well and just set the decimation level as an argument?

Same goes for importing into the current level—how can I programmatically use an object path as an argument and avoid the dialog menu?

Thanks

You can use low-level APIs, as it is done in the Reality Capture module.
3DCoat_install_folder\UserPrefs\Scripts\Modules\RealityCapture\PhotosTo3DExt.py

https://pilgway.com/files/3dcoat/PythonAPI/classcoat_1_1_paint_room.html

if you need additional low-level API functionality - let me know

PLOw.png

  • Like 2
Link to comment
Share on other sites

  • Advanced Member
Posted (edited)

How can I import extra modules? For example PySide6?
My goal is to create an integration with ShotGrid (Flow Production Tracking) and the toolkit for Pipeline flows.
https://help.autodesk.com/view/SGSUB/ENU/?guid=SG_Automotive_am_getting_started_am_integrations_intro_html

Community Integrations: 
https://help.autodesk.com/view/SGDEV/ENU/?guid=SGD_si_integrations_community_shared_integrations_html

Edited by MJonathan
  • Like 1
Link to comment
Share on other sites

  • Member
16 hours ago, carrots said:

You can use low-level APIs, as it is done in the Reality Capture module.
3DCoat_install_folder\UserPrefs\Scripts\Modules\RealityCapture\PhotosTo3DExt.py

https://pilgway.com/files/3dcoat/PythonAPI/classcoat_1_1_paint_room.html

if you need additional low-level API functionality - let me know

PLOw.png

Thanks. This is useful.

I just found your add-on system quite similar to something I built for Autodesk Maya, which helps manage scripts in a more simplified way. If you're interested, I have an article about it link

Also, I’m wondering if it’s possible to create a custom context menu with submenus, separators, etc.? I saw that it's possible to insert menu items, but I couldn’t find how to manage submenus, separators etc.

  • Like 1
Link to comment
Share on other sites

Ok, I'll make some examples of custom extensions based on PySide6, custom menu and post them here.

  • Like 2
Link to comment
Share on other sites

  • Member
Posted (edited)
9 hours ago, carrots said:

Ok, I'll make some examples of custom extensions based on PySide6, custom menu and post them here.

Just quick question:

- I found that on macOS, the Addon context menu doesn't parse the standard Examples scripts, so they don't show up in the Addon menu.

- The command coat.ui.toRoom(f"{ROOM_NAME}") doesn't work on macOS — I have to use coat.ui.cmd("$SETPAGE_Sculpt") instead.

- I also noticed that in the examples, we use coat.ui.toRoom("Sculpt") for the SCULPT room, but it doesn't work — I have to use "Voxels" instead. What’s the difference between them? Is this an undocumented change?

3D Coat 2024.31

Edited by crudodev
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...
  • Advanced Member
Posted (edited)

Hey @carrots
I was searching a way to get the class of the paint objects! but I think there is no way to have this class!
My objective is to access to the instances of the PaintObjects to manipulate their options like hide and unhide.
I only can found this methods:
 

def PaintObjectsCount () -> int : ...
def RemovePaintObject (idx: int) : ...
def PaintObjectName (idx: int) -> str : ...

There are not a PaintObject Class (I'm not sure if PaintObjecs are part of Mesh Class) and these are the only methods that I found. Ideally should be more appropiated to have something like this:
 

class PaintObject:
	def __init__(self): ...
	@staticmethod
	def getName(self): ...
	@staticmethod
	def hide(self): ...
	@staticmethod
	def unhide(self): ...
	@staticmethod
	def delete(self): ...
	@staticmethod
	def lock(self): ...
	@staticmethod
	def getMesh(self): ...

If you know a way to manipulate these can you point me in the right direction please?
Or if there is no an option, Can you implement these please? the same as Model class.
 

Edited by MJonathan
  • Like 2
Link to comment
Share on other sites

  • Advanced Member
Posted (edited)

2025-08-03 20-22-50.mkv
Still need help with this!

I've atached a video showing this wrong behavior with the model class methods.

For PolyGroups, I'm using the Model class to access the methods.
In this script, I'm hiding elements using multi-selection, and everything seems to be working, the changes are reflected in the native PolyGroup interface.

But the viewport isn't updating to reflect those changes! as you can see in the video
 

#Documentation in the Model Class say that we can use this to manage the visibility of the groups
setObjectVisibility(self, int index, bool visible)

#Example of a peace of my code:
self.model = coat.Model.fromModeling()
is_checked = changed_item.checkState() == Qt.Checked
self.model.setObjectVisibility(index, is_checked)

 

Edited by MJonathan
Link to comment
Share on other sites

On 8/3/2025 at 12:00 AM, MJonathan said:

Hey @carrots
I was searching a way to get the class of the paint objects! but I think there is no way to have this class!
My objective is to access to the instances of the PaintObjects to manipulate their options like hide and unhide.
I only can found this methods:
 

def PaintObjectsCount () -> int : ...
def RemovePaintObject (idx: int) : ...
def PaintObjectName (idx: int) -> str : ...

There are not a PaintObject Class (I'm not sure if PaintObjecs are part of Mesh Class) and these are the only methods that I found. Ideally should be more appropiated to have something like this:
 

class PaintObject:
	def __init__(self): ...
	@staticmethod
	def getName(self): ...
	@staticmethod
	def hide(self): ...
	@staticmethod
	def unhide(self): ...
	@staticmethod
	def delete(self): ...
	@staticmethod
	def lock(self): ...
	@staticmethod
	def getMesh(self): ...

If you know a way to manipulate these can you point me in the right direction please?
Or if there is no an option, Can you implement these please? the same as Model class.
 

Thanks, Ok, I'll add this to the Python API

  • Thanks 2
Link to comment
Share on other sites

 

Hi @MJonathan , please try this version https://drive.google.com/file/d/1_wyvaT-A0OGOrcPffSew3vkEJRc7qemu/view?usp=sharing

To access the Paint object model, you can use the coat.Model.fromUv() function

To access the Paint object properties, you can use the coat.PaintRoom.GetPPPObject(idx) function

Also fixed an issue with changing the visibility of retopo groups


image.png

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • Advanced Member
Posted (edited)

EDIT: SetLocked is not working

Hey Carrots! Thank you very much for this update — it’s working as expected for both PPPObjects and Retopo Objects!

I have another question: PPPObjects have the GetLocked and SetLocked methods. Is it possible to use SetLocked and GetLocked with Retopo Objects as well, or would that logic need to be implemented by the Retopo developer first?

Edited by MJonathan
  • Like 1
Link to comment
Share on other sites

  • Advanced Member

Sorry Carrots! the SetLocked method is not working in PaintObjects, it has a bug! this unchecked and checked the lock icon in the interface, but if it is SetLocked(True), you can continue drawing in the object, that's wrong, if I manually click in that icon it works correctly, but no with coding.

  • Like 1
Link to comment
Share on other sites

On 8/14/2025 at 7:33 PM, MJonathan said:

Sorry Carrots! the SetLocked method is not working in PaintObjects, it has a bug! this unchecked and checked the lock icon in the interface, but if it is SetLocked(True), you can continue drawing in the object, that's wrong, if I manually click in that icon it works correctly, but no with coding.

Thanks for the message, I will fix it soon.

  • Thanks 1
Link to comment
Share on other sites

On 8/14/2025 at 7:33 PM, MJonathan said:

Sorry Carrots! the SetLocked method is not working in PaintObjects, it has a bug! this unchecked and checked the lock icon in the interface, but if it is SetLocked(True), you can continue drawing in the object, that's wrong, if I manually click in that icon it works correctly, but no with coding.

Now  Alexander @Gorbatovsky is working on the hierarchy for retepo, you can ask him about the functionality you need. I'll give him a link to this forum.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

On 8/14/2025 at 7:33 PM, MJonathan said:

Sorry Carrots! the SetLocked method is not working in PaintObjects, it has a bug! this unchecked and checked the lock icon in the interface, but if it is SetLocked(True), you can continue drawing in the object, that's wrong, if I manually click in that icon it works correctly, but no with coding.

https://drive.google.com/file/d/1AwVX89QIhWH4poWDYlrYuW7ZVks1Upms/view?usp=sharing

Please try this version, this error should be fixed in it.

  • Like 1
Link to comment
Share on other sites

  • Advanced Member

SetLocked is working as expected in this 3dcoat version! thank you very much carrots! it will be very helpful :yahoo:

 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...