0
$\begingroup$

Introductions Hello, I'm a brand new blender user... I'm working on a little project that's entirely made up of Python scripts. But I'm having trouble turning an octagon into a circle right now ( I do know that adding vertices would make it better, but is there another way, perhaps something like a code that resembles a subdivision modifier?)... Please help me with my problem...

My Question Is scripting subdivision modifier applicable? Can you show me how to do it with my code if it is possible?

Here is my code

import bpy

verts = [(0,1,0), (0.29,1.70,0), (1,2,0), (1.70,1.70,0), (2,1,0), (1.70,0.29,0), (1,0,0), (0.29,0.29,0)]

faces = [(0,1,2,3,4,5,6,7)]

mesh = bpy.data.meshes.new("octagon")

object = bpy.data.objects.new("octagon", mesh)

bpy.context.collection.objects.link(object)

mesh.from_pydata(verts,[],faces)
$\endgroup$
7
  • $\begingroup$ Hi, and welcome! 1. That's an octagon. 2. It 'is' a circle. as far as polygonal modelling is concerned.. just a low-resolution one. Do you just want to make that into a higher-resolution circle? Or, say, make a curve out of it? $\endgroup$
    – Robin Betts
    Commented Sep 30, 2021 at 9:22
  • $\begingroup$ Oh, I meant octagon... and yes, I do intend to turn it into a higher resolution circle. $\endgroup$ Commented Sep 30, 2021 at 9:29
  • 2
    $\begingroup$ Welcome to BSE. For the interests of your education, feel we should balk at answering your assignment for you, esp. before October 11, lol. Please consider using more subterfuge in future. Does an answer have to involve using the code (or product of) from above, which instead could be the add circle operator with 8 verts. . The more verts the more circular the result. $\endgroup$
    – batFINGER
    Commented Sep 30, 2021 at 10:46
  • $\begingroup$ Sorry, I will next time... But back to the topic at hand. I understand that adding more vertices will make it more circular, but I'm curious whether there is an easier way to do so (?)... Is scripting subdivision modifier an option ? Can you show me how to do it with my code if it is possible? ​please... $\endgroup$ Commented Sep 30, 2021 at 11:25
  • 1
    $\begingroup$ You should never rely on forums or Q/A web sites for fast responses. It can be hours, sometimes days, before the person who knows and has time sees your question. On the other hand, in this case, the answer is "yes, you can script adding modifiers". Now if you go web search for an example of how to do that, it is a better way of learning than simply asking how. $\endgroup$ Commented Sep 30, 2021 at 14:15

1 Answer 1

0
$\begingroup$
for ob in bpy.data.objects:
 if ob.type == 'MESH':
     ob.modifiers.new('My SubDiv', 'SUBSURF')
$\endgroup$
1
  • $\begingroup$ Hi, thanks for the post. This site is not a regular forum, answers should be substantial and thoroughly explain the solution and required workflow. One liners, short tips and code only posts rarely make for a good answer. If you can edit your post and provide some more details about the code and why it works feel free to restore it, otherwise it may be converted into a comment. Perhaps add a short explanation of what the code does. See How do I write a good answer? $\endgroup$ Commented Oct 1, 2021 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .