Skip to content

Instantly share code, notes, and snippets.

@NiklasRosenstein
Last active November 14, 2017 19:07
Show Gist options
  • Save NiklasRosenstein/6462786 to your computer and use it in GitHub Desktop.
Save NiklasRosenstein/6462786 to your computer and use it in GitHub Desktop.
Script to insert points at the start or end of a mesh. Press enter to apply, escape to cancel.
# Copyright (c) 2013, Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import c4d
class Dialog(c4d.gui.GeDialog):
EDT_NPOINTS = 1000
EDT_MODE = 1001
def __init__(self, op):
super(Dialog, self).__init__()
self.op = op
def DoTheWork(self):
count = self.GetLong(self.EDT_NPOINTS)
mode = self.GetLong(self.EDT_MODE)
if count <= 0 or mode not in [0, 1]:
return
op = self.op
points = op.GetAllPoints()
fillups = [c4d.Vector()] * count
op.ResizeObject(len(points) + count, op.GetPolygonCount())
if mode == 0:
points = fillups + points
for i, p in enumerate(op.GetAllPolygons()):
p.a += count
p.b += count
p.c += count
p.d += count
op.SetPolygon(i, p)
elif mode == 1:
points.extend(fillups)
doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
op.SetAllPoints(points)
c4d.EventAdd()
def CreateLayout(self):
if self.GroupBegin(0, c4d.BFH_SCALEFIT, 0, 1):
self.GroupBorderSpace(4, 4, 4, 4)
self.AddStaticText(0, 0, name="Add")
self.AddEditNumberArrows(self.EDT_NPOINTS, 0)
self.AddStaticText(0, 0, name="Points at the")
self.AddComboBox(self.EDT_MODE, 0)
self.AddChild(self.EDT_MODE, 0, "start")
self.AddChild(self.EDT_MODE, 1, "end")
self.AddStaticText(0,0, name="of the Mesh.")
self.AddButton(c4d.DLG_OK, 0, name="Ok.")
self.AddButton(c4d.DLG_CANCEL, 0, name="Cancel")
self.GroupEnd()
return True
def InitValues(self):
self.SetReal(self.EDT_NPOINTS, 0)
return True
def Command(self, id, msg):
if id == c4d.DLG_OK:
self.DoTheWork()
self.Close()
elif id == c4d.DLG_CANCEL:
self.Close()
return True
def main():
if not op or not isinstance(op, c4d.PointObject):
return
dlg = Dialog(op)
dlg.Open(c4d.DLG_TYPE_MODAL)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment