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

  • 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
  • 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.

  • 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
  • Advanced Member

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
  • 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
  • Member
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
  • 3 weeks later...
  • 3 months later...
  • Advanced Member

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
  • Advanced Member

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
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

 

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

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...