Plugin Problem

On 07/02/2013 at 08:42, xxxxxxxx wrote:

I like to write a code for a procedural rock generator plugin and i don´t know what i am doing wrong.
Im new in python programming, so im confused about how to make my plugin work.

Here´s my problem:

The code for the object creation is working fine, but the sliders and the last button don´t come in to effect.

Here´s my code so far:

import os
import sys
import c4d
from c4d import plugins, utils, gui,documents
from c4d.modules import mograph

PLUGIN_ID = 1029753

global doc
doc = c4d.documents.GetActiveDocument()

UI Daten

UI_Initial_Mesh_Subdivisions = 10000
UI_HyperNURBS_Subdivisions = 10001
UI_Rock_SIZE = 10002
UI_Displacement1_Height = 10003
UI_Noise1_Type = 10004
UI_Noise1_Size = 10005
UI_Random_Seed1 = 10006
UI_Formula_x = 10007
UI_Formula_y = 10008
UI_Formula_z = 10009
UI_Displacement2_Height = 10010
UI_Noise2_Type = 10011
UI_Noise2_Size = 10012
UI_Random_Seed2 = 10013
UI_Generate_Mesh = 10014
UI_Generate_Initial_Rock = 10015

Groups

Group1 = 20001
Group2 = 20002
Group3 = 20003
Group4 = 20004

Combo Box Daten

Combo_1 = 20005
Combo_1_ch_0 = 31000
Combo_1_ch_1 = 31001
Combo_1_ch_2 = 31002
Combo_1_ch_3 = 31003
Combo_1_ch_4 = 31004
Combo_1_ch_5 = 31005
Combo_1_ch_6 = 31006
Combo_1_ch_7 = 31007
Combo_1_ch_8 = 31008
Combo_1_ch_9 = 31009
Combo_1_ch_10 = 31010
Combo_1_ch_11 = 31011
Combo_1_ch_12 = 31012
Combo_1_ch_13 = 31013
Combo_1_ch_14 = 31014
Combo_1_ch_15 = 31015
Combo_1_ch_16 = 31016
Combo_1_ch_17 = 31017
Combo_1_ch_18 = 31018
Combo_1_ch_19 = 31019
Combo_1_ch_20 = 31020
Combo_1_ch_21 = 31021
Combo_1_ch_22 = 31022
Combo_1_ch_23 = 31023
Combo_1_ch_24 = 31024
Combo_1_ch_25 = 31025
Combo_1_ch_26 = 31026
Combo_1_ch_27 = 31027
Combo_1_ch_28 = 31028
Combo_1_ch_29 = 31029
Combo_1_ch_30 = 31030
Combo_1_ch_31 = 31031

Combo_2 = 20006
Combo_2_ch_0 = 32000
Combo_2_ch_1 = 32001
Combo_2_ch_2 = 32002
Combo_2_ch_3 = 32003
Combo_2_ch_4 = 32004
Combo_2_ch_5 = 32005
Combo_2_ch_6 = 32006
Combo_2_ch_7 = 32007
Combo_2_ch_8 = 32008
Combo_2_ch_9 = 32009
Combo_2_ch_10 = 32010
Combo_2_ch_11 = 32011
Combo_2_ch_12 = 32012
Combo_2_ch_13 = 32013
Combo_2_ch_14 = 32014
Combo_2_ch_15 = 32015
Combo_2_ch_16 = 32016
Combo_2_ch_17 = 32017
Combo_2_ch_18 = 32018
Combo_2_ch_19 = 32019
Combo_2_ch_20 = 32020
Combo_2_ch_21 = 32021
Combo_2_ch_22 = 32022
Combo_2_ch_23 = 32023
Combo_2_ch_24 = 32024
Combo_2_ch_25 = 32025
Combo_2_ch_26 = 32026
Combo_2_ch_27 = 32027
Combo_2_ch_28 = 32028
Combo_2_ch_29 = 32029
Combo_2_ch_30 = 32030
Combo_2_ch_31 = 32031

class ProceduralRockGeneratorDialog(c4d.gui.GeDialog) :

def CreateLayout(self) :
      self.SetTitle("Procedural Rock Generator")

self.AddButton(UI_Generate_Initial_Rock, c4d.BFH_LEFT | c4d.BFV_TOP | c4d.BFH_SCALEFIT, 600, 15, "Generate Initial Rock")

#Group 1 with 2 columns "Resolution"
      self.GroupBegin(Group1, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 2, 0, "Resolution")
      self.GroupBorderSpace(5, 5, 5, 5)
      self.GroupBorder(c4d.BORDER_GROUP_IN)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Initial Mesh Subdivisions:", 0)
      self.AddEditSlider(UI_Initial_Mesh_Subdivisions, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Hyper Nurbs Subdisvisions:", 0)
      self.AddEditSlider(UI_HyperNURBS_Subdivisions, c4d.BFH_SCALEFIT, 0, 0)
      self.GroupEnd()

#Group 2 with 2 columns "Basic Rock Shape"
      self.GroupBegin(Group2, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 2, 0, "Basic Rock Shape")
      self.GroupBorderSpace(5, 5, 5, 5)
      self.GroupBorder(c4d.BORDER_GROUP_IN)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Rock Size:", 0)
      self.AddEditSlider(UI_Rock_SIZE, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Displacement Height:", 0)
      self.AddEditSlider(UI_Displacement1_Height, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Type:", 0)
      self.AddComboBox(Combo_1, c4d.BFH_SCALEFIT, 0, 0)
      self.AddChild(Combo_1 ,Combo_1_ch_0,'Box Noise')
      self.AddChild(Combo_1,Combo_1_ch_1,'Blistered Turbulence')
      self.AddChild(Combo_1,Combo_1_ch_2,'Buya')
      self.AddChild(Combo_1,Combo_1_ch_3,'Cell Noise')
      self.AddChild(Combo_1,Combo_1_ch_4,'Cranal')
      self.AddChild(Combo_1,Combo_1_ch_5,'Dents')
      self.AddChild(Combo_1,Combo_1_ch_6,'Displaced Turbulence')
      self.AddChild(Combo_1,Combo_1_ch_7,'FBM')
      self.AddChild(Combo_1,Combo_1_ch_8,'Hama')
      self.AddChild(Combo_1,Combo_1_ch_9,'Luka')
      self.AddChild(Combo_1,Combo_1_ch_10,'Mod Noise')
      self.AddChild(Combo_1,Combo_1_ch_11,'Hama')
      self.AddChild(Combo_1,Combo_1_ch_12,'Noise')
      self.AddChild(Combo_1,Combo_1_ch_13,'Nutous')
      self.AddChild(Combo_1,Combo_1_ch_14,'Ober')
      self.AddChild(Combo_1,Combo_1_ch_15,'Pezo')
      self.AddChild(Combo_1,Combo_1_ch_16,'Poxo')
      self.AddChild(Combo_1,Combo_1_ch_17,'Sema')
      self.AddChild(Combo_1,Combo_1_ch_18,'Stupl')
      self.AddChild(Combo_1,Combo_1_ch_19,'Turbulence')
      self.AddChild(Combo_1,Combo_1_ch_20,'VL Noise')
      self.AddChild(Combo_1,Combo_1_ch_21,'Wavy Turbulence')
      self.AddChild(Combo_1,Combo_1_ch_22,'Cell Voronoi')
      self.AddChild(Combo_1,Combo_1_ch_23,'Displaced Voronoi')
      self.AddChild(Combo_1,Combo_1_ch_24,'Sparse Convolution')
      self.AddChild(Combo_1,Combo_1_ch_25,'Voronoi 1')
      self.AddChild(Combo_1,Combo_1_ch_26,'Voronoi 2')
      self.AddChild(Combo_1,Combo_1_ch_27,'Voronoi 3')
      self.AddChild(Combo_1,Combo_1_ch_28,'Zada')
      self.AddChild(Combo_1,Combo_1_ch_29,'Fire')
      self.AddChild(Combo_1,Combo_1_ch_30,'Electric')
      self.AddChild(Combo_1,Combo_1_ch_31,'Gaseous')
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Size:", 0)
      self.AddEditSlider(UI_Noise1_Size, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Random Seed:", 0)
      self.AddEditSlider(UI_Random_Seed1, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Scale X:", 0)
      self.AddEditSlider(UI_Formula_x, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Scale Y:", 0)
      self.AddEditSlider(UI_Formula_y, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Scale Z:", 0)
      self.AddEditSlider(UI_Formula_z, c4d.BFH_SCALEFIT, 0, 0)
      self.GroupEnd()

#Group 3 with 2 columns "Rock Details"
      self.GroupBegin(Group3, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 2, 0, "Rock Details")
      self.GroupBorderSpace(5, 5, 5, 5)
      self.GroupBorder(c4d.BORDER_GROUP_IN)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Displacement Height:", 0)
      self.AddEditSlider(UI_Displacement2_Height, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Type:", 0)
      self.AddComboBox(Combo_2, c4d.BFH_SCALEFIT, 0, 0)
      self.AddChild(Combo_2,Combo_2_ch_0,'Box Noise')
      self.AddChild(Combo_2,Combo_2_ch_1,'Blistered Turbulence')
      self.AddChild(Combo_2,Combo_2_ch_2,'Buya')
      self.AddChild(Combo_2,Combo_2_ch_3,'Cell Noise')
      self.AddChild(Combo_2,Combo_2_ch_4,'Cranal')
      self.AddChild(Combo_2,Combo_2_ch_5,'Dents')
      self.AddChild(Combo_2,Combo_2_ch_6,'Displaced Turbulence')
      self.AddChild(Combo_2,Combo_2_ch_7,'FBM')
      self.AddChild(Combo_2,Combo_2_ch_8,'Hama')
      self.AddChild(Combo_2,Combo_2_ch_9,'Luka')
      self.AddChild(Combo_2,Combo_2_ch_10,'Mod Noise')
      self.AddChild(Combo_2,Combo_2_ch_11,'Hama')
      self.AddChild(Combo_2,Combo_2_ch_12,'Noise')
      self.AddChild(Combo_2,Combo_2_ch_13,'Nutous')
      self.AddChild(Combo_2,Combo_2_ch_14,'Ober')
      self.AddChild(Combo_2,Combo_2_ch_15,'Pezo')
      self.AddChild(Combo_2,Combo_2_ch_16,'Poxo')
      self.AddChild(Combo_2,Combo_2_ch_17,'Sema')
      self.AddChild(Combo_2,Combo_2_ch_18,'Stupl')
      self.AddChild(Combo_2,Combo_2_ch_19,'Turbulence')
      self.AddChild(Combo_2,Combo_2_ch_20,'VL Noise')
      self.AddChild(Combo_2,Combo_2_ch_21,'Wavy Turbulence')
      self.AddChild(Combo_2,Combo_2_ch_22,'Cell Voronoi')
      self.AddChild(Combo_2,Combo_2_ch_23,'Displaced Voronoi')
      self.AddChild(Combo_2,Combo_2_ch_24,'Sparse Convolution')
      self.AddChild(Combo_2,Combo_2_ch_25,'Voronoi 1')
      self.AddChild(Combo_2,Combo_2_ch_26,'Voronoi 2')
      self.AddChild(Combo_2,Combo_2_ch_27,'Voronoi 3')
      self.AddChild(Combo_2,Combo_2_ch_28,'Zada')
      self.AddChild(Combo_2,Combo_2_ch_29,'Fire')
      self.AddChild(Combo_2,Combo_2_ch_30,'Electric')
      self.AddChild(Combo_2,Combo_2_ch_31,'Gaseous')
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Size:", 0)
      self.AddEditSlider(UI_Noise2_Size, c4d.BFH_SCALEFIT, 0, 0)
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Random Seed:", 0)
      self.AddEditSlider(UI_Random_Seed2, c4d.BFH_SCALEFIT, 0, 0)
      self.GroupEnd()

self.AddButton(UI_Generate_Mesh, c4d.BFH_LEFT | c4d.BFV_TOP | c4d.BFH_SCALEFIT, 600, 15, "Generate Rock Mesh")
     
      return True

def InitValues(self) :
      self.SetReal(UI_Initial_Mesh_Subdivisions, 50, min=0, max=400, step=1, format=c4d.FORMAT_REAL)
      self.SetReal(UI_HyperNURBS_Subdivisions, 1, min=1, max=6, step=1, format=c4d.FORMAT_REAL)
      self.SetReal(UI_Rock_SIZE, 195, min=1, max=1000, step=1, format=c4d.FORMAT_REAL)
      self.SetReal(UI_Displacement1_Height, 227, min=0, max=500, step=1, format=c4d.FORMAT_REAL)
      self.SetLong(Combo_1,Combo_1_ch_23)
      self.SetReal(UI_Noise1_Size, 18, min=0, max=40, step=1, format=c4d.FORMAT_PERCENT)
      self.SetReal(UI_Random_Seed1, 658, min=1, max=1000, step=1, format=c4d.FORMAT_REAL)
      self.SetReal(UI_Formula_x, 1, min=1, max=5, step=0.1, format=c4d.FORMAT_REAL)
      self.SetReal(UI_Formula_y, 1, min=1, max=5, step=0.1, format=c4d.FORMAT_REAL)
      self.SetReal(UI_Formula_z, 1, min=1, max=5, step=0.1, format=c4d.FORMAT_REAL)
      self.SetReal(UI_Displacement2_Height, 5, min=0, max=500, step=1, format=c4d.FORMAT_REAL)
      self.SetLong(Combo_2,Combo_2_ch_9)
      self.SetReal(UI_Noise2_Size, 2.57, min=0, max=40, step=1, format=c4d.FORMAT_PERCENT)
      self.SetReal(UI_Random_Seed2, 660, min=1, max=1000, step=1, format=c4d.FORMAT_REAL)

return True

def Command(self,id,msg) :
     
      if (id == UI_Generate_Initial_Rock) :
          doc = c4d.documents.GetActiveDocument()

c4d.CallCommand(12202) # Set standart Camera in Editor Window
          c4d.CallCommand(12091) # Set Gouraud-Shading in Editor Window
          c4d.CallCommand(13620) # Set Editor Window to Single View

# Create the HyperNURBS
          h = c4d.BaseObject(c4d.Osds) # Create new HyperNURBS
          h[c4d.SDSOBJECT_SUBEDITOR_CM] = 2 # Set Editor subdivision to 2
          h[c4d.SDSOBJECT_SUBRAY_CM] = 3 # Set Render subdivision to 3
          h.SetName('Hypernurbs')
          doc.InsertObject(h)
          # Create the sphere
          s = c4d.BaseObject(c4d.Osphere) # Create new sphere
          s[c4d.PRIM_SPHERE_TYPE] = 2 # Set sphere type to Hexaeder
          s[c4d.PRIM_SPHERE_SUB] = 50 # Set sphere segments to 50
          s[c4d.PRIM_SPHERE_RAD] = 200 # Set sphere radius to 200
          s.SetName('Sphere')
          doc.InsertObject(s)
          # Create the Displacer deformer 1
          c4d.CallCommand(1018685) # Create new displacer deformer
          d1 = doc.SearchObject('Displacer')
          d1[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = 227 # Set displacement height to 227cm
          d1[c4d.MGDISPLACER_DISPLACEMENTMODE]=0 # Set Displacementmode to Intensity
          d1[c4d.MGDISPLACER_POLYNORMALMODE]=1 # Set Polynormalmode to Sphere
          d1.SetName('Displacer1')

# Assingn the noise shadet to the displace deformer 1
          mat1 = d1
          shd1 = c4d.BaseList2D(c4d.Xnoise)
          shd1[c4d.SLA_NOISE_SEED] = 658
          shd1[c4d.SLA_NOISE_NOISE] = 2025
          shd1[c4d.SLA_NOISE_OCTAVES] = 1
          shd1[c4d.SLA_NOISE_GLOBAL_SCALE] = 18

mat1[c4d.ID_MG_SHADER_SHADER] = shd1
          mat1.InsertShader(shd1)
          mat1.Message(c4d.MSG_UPDATE)

# Create the Formula deformer
          c4d.CallCommand(5146) # Create new Formula deformer
          f = doc.SearchObject('Formel')
          f[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]=1 # Set Formula deformer to invisible
          f[c4d.FORMULAOBJECT_EFFECT]=0 # Set Effect to Manual
          fxWert_x = 'x*' + str((self.GetReal(UI_Formula_x)))
          fxWert_y = 'y*' + str((self.GetReal(UI_Formula_y)))
          fxWert_z = 'z*' + str((self.GetReal(UI_Formula_z)))
          f[c4d.FORMULAOBJECT_FX]=fxWert_x
          f[c4d.FORMULAOBJECT_FY]=fxWert_y
          f[c4d.FORMULAOBJECT_FZ]=fxWert_z
          f.SetName('Formula')

# Create the Displacer deformer 2
          c4d.CallCommand(1018685) # Create new displacer deformer
          d2 = doc.SearchObject('Displacer')
          d2[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = 5 # Set displacement height to 5cm
          d2.SetName('Displacer2')

# Assingn the noise shader to the displace deformer 2
          mat2 = d2
          shd2 = c4d.BaseList2D(c4d.Xnoise)
          shd2[c4d.SLA_NOISE_SEED] = 660
          shd2[c4d.SLA_NOISE_NOISE] = 2010
          shd2[c4d.SLA_NOISE_OCTAVES] = 20
          shd2[c4d.SLA_NOISE_GLOBAL_SCALE] = 2.57

mat2[c4d.ID_MG_SHADER_SHADER] = shd2
          mat2.InsertShader(shd2)
          mat2.Message(c4d.MSG_UPDATE)

# Insertions
          s.InsertUnder(h)
          d2.InsertUnder(s)
          f.InsertUnder(s)
          d1.InsertUnder(s)

# Layer
          c4d.CallCommand(100004738) # Create a new layer
          c4d.CallCommand(100004748) # Alles aufklappen in der Objektliste
          c4d.CallCommand(100004766) # Select all Objects
          c4d.CallCommand(100004736) # Assign all Objects to the layer
          c4d.CallCommand(12148) # Zoom on Geometry in Editor Window
          c4d.CallCommand(100004767) # Deselect all

######################### Hide the layer in menu ##########################

#doc = c4d.documents.GetActiveDocument()
          #root = doc.GetLayerObjectRoot()#Gets the layer manager
          #LayersList = root.GetChildren()
          #toggled = 0
          #for layers in LayersList:

#    if layers.GetBit(c4d.BIT_ACTIVE) :# if the layer is selected
          #        layer_data = layers.GetLayerData(doc)
          #        layer_data['manager'] = not layer_data['manager']
          #        layers.SetLayerData(doc,layer_data)
          #        toggled=1
          #    c4d.EventAdd()

##########################################################################
      return True

if id == UI_Generate_Mesh:
          doc = c4d.documents.GetActiveDocument()
          rock = doc.SearchObject('Hypernurbs')
          rock.SetName('Rock')
          c4d.CallCommand(12236) # Grundobjekt kovertieren
          c4d.CallCommand(100004739) # Delete all Layers
          c4d.EventAdd()
      return True

if id == Combo_1:
          if (self.GetLong(Combo_1) == Combo_1_ch_0) :
              shd1[c4d.SLA_NOISE_NOISE] = 2001

elif (self.GetLong(Combo_1) == Combo_1_ch_1) :
              shd1[c4d.SLA_NOISE_NOISE] = 2002
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_2) :
              shd1[c4d.SLA_NOISE_NOISE] = 2003
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_3) :
              shd1[c4d.SLA_NOISE_NOISE] = 2004
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_4) :
              shd1[c4d.SLA_NOISE_NOISE] = 2005
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_5) :
              shd1[c4d.SLA_NOISE_NOISE] = 2006
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_6) :
              shd1[c4d.SLA_NOISE_NOISE] = 2007
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_7) :
              shd1[c4d.SLA_NOISE_NOISE] = 2008
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_8) :
              shd[c4d.SLA_NOISE_NOISE] = 2009
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_9) :
              shd1[c4d.SLA_NOISE_NOISE] = 2010
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_10) :
              shd1[c4d.SLA_NOISE_NOISE] = 2011
         
          elif (self.GetLong(Combo_1) == Combo_1_ch_11) :
              shd1[c4d.SLA_NOISE_NOISE] = 2012

elif (self.GetLong(Combo_1) == Combo_1_ch_12) :
              shd1[c4d.SLA_NOISE_NOISE] = 2013

elif (self.GetLong(Combo_1) == Combo_1_ch_13) :
              shd1[c4d.SLA_NOISE_NOISE] = 2014

elif (self.GetLong(Combo_1) == Combo_1_ch_14) :
              shd1[c4d.SLA_NOISE_NOISE] = 2015

elif (self.GetLong(Combo_1) == Combo_1_ch_15) :
              shd1[c4d.SLA_NOISE_NOISE] = 2016

elif (self.GetLong(Combo_1) == Combo_1_ch_16) :
              shd1[c4d.SLA_NOISE_NOISE] = 2017

elif (self.GetLong(Combo_1) == Combo_1_ch_17) :
              shd1[c4d.SLA_NOISE_NOISE] = 2019

elif (self.GetLong(Combo_1) == Combo_1_ch_18) :
              shd1[c4d.SLA_NOISE_NOISE] = 2020

elif (self.GetLong(Combo_1) == Combo_1_ch_19) :
              shd1[c4d.SLA_NOISE_NOISE] = 2021

elif (self.GetLong(Combo_1) == Combo_1_ch_20) :
              shd1[c4d.SLA_NOISE_NOISE] = 2022

elif (self.GetLong(Combo_1) == Combo_1_ch_21) :
              shd1[c4d.SLA_NOISE_NOISE] = 2023

elif (self.GetLong(Combo_1) == Combo_1_ch_22) :
              shd1[c4d.SLA_NOISE_NOISE] = 2024

elif (self.GetLong(Combo_1) == Combo_1_ch_23) :
              shd1[c4d.SLA_NOISE_NOISE] = 2025

elif (self.GetLong(Combo_1) == Combo_1_ch_24) :
              shd1[c4d.SLA_NOISE_NOISE] = 2026

elif (self.GetLong(Combo_1) == Combo_1_ch_25) :
              shd1[c4d.SLA_NOISE_NOISE] = 2027

elif (self.GetLong(Combo_1) == Combo_1_ch_26) :
              shd1[c4d.SLA_NOISE_NOISE] = 2028

elif (self.GetLong(Combo_1) == Combo_1_ch_27) :
              shd1[c4d.SLA_NOISE_NOISE] = 2029

elif (self.GetLong(Combo_1) == Combo_1_ch_28) :
              shd1[c4d.SLA_NOISE_NOISE] = 2030

elif (self.GetLong(Combo_1) == Combo_1_ch_29) :
              shd1[c4d.SLA_NOISE_NOISE] = 2031

elif (self.GetLong(Combo_1) == Combo_1_ch_30) :
              shd1[c4d.SLA_NOISE_NOISE] = 2032

elif (self.GetLong(Combo_1) == Combo_1_ch_31) :
              shd1[c4d.SLA_NOISE_NOISE] = 2033
      return True

if id == Combo_2:
          if (self.GetLong(Combo_2) == Combo_2_ch_0) :
              shd2[c4d.SLA_NOISE_NOISE] = 2001

elif (self.GetLong(Combo_2) == Combo_2_ch_1) :
              shd2[c4d.SLA_NOISE_NOISE] = 2002

elif (self.GetLong(Combo_2) == Combo_2_ch_2) :
              shd2[c4d.SLA_NOISE_NOISE] = 2003

elif (self.GetLong(Combo_2) == Combo_2_ch_3) :
              shd2[c4d.SLA_NOISE_NOISE] = 2004

elif (self.GetLong(Combo_2) == Combo_2_ch_4) :
              shd2[c4d.SLA_NOISE_NOISE] = 2005

elif (self.GetLong(Combo_2) == Combo_2_ch_5) :
              shd2[c4d.SLA_NOISE_NOISE] = 2006

elif (self.GetLong(Combo_2) == Combo_2_ch_6) :
              shd2[c4d.SLA_NOISE_NOISE] = 2007

elif (self.GetLong(Combo_2) == Combo_2_ch_7) :
              shd2[c4d.SLA_NOISE_NOISE] = 2008

elif (self.GetLong(Combo_2) == Combo_2_ch_8) :
              shd2[c4d.SLA_NOISE_NOISE] = 2009

elif (self.GetLong(Combo_2) == Combo_2_ch_9) :
              shd2[c4d.SLA_NOISE_NOISE] = 2010

elif (self.GetLong(Combo_2) == Combo_2_ch_10) :
              shd2[c4d.SLA_NOISE_NOISE] = 2011

elif (self.GetLong(Combo_2) == Combo_2_ch_11) :
              shd2[c4d.SLA_NOISE_NOISE] = 2012

elif (self.GetLong(Combo_2) == Combo_2_ch_12) :
              shd2[c4d.SLA_NOISE_NOISE] = 2013

elif (self.GetLong(Combo_2) == Combo_2_ch_13) :
              shd2[c4d.SLA_NOISE_NOISE] = 2014

elif (self.GetLong(Combo_2) == Combo_2_ch_14) :
              shd2[c4d.SLA_NOISE_NOISE] = 2015

elif (self.GetLong(Combo_2) == Combo_2_ch_15) :
              shd2[c4d.SLA_NOISE_NOISE] = 2016

elif (self.GetLong(Combo_2) == Combo_2_ch_16) :
              shd2[c4d.SLA_NOISE_NOISE] = 2017

elif (self.GetLong(Combo_2) == Combo_2_ch_17) :
              shd2[c4d.SLA_NOISE_NOISE] = 2019

elif (self.GetLong(Combo_2) == Combo_2_ch_18) :
              shd2[c4d.SLA_NOISE_NOISE] = 2020

elif (self.GetLong(Combo_2) == Combo_2_ch_19) :
              shd2[c4d.SLA_NOISE_NOISE] = 2021

elif (self.GetLong(Combo_2) == Combo_2_ch_20) :
              shd2[c4d.SLA_NOISE_NOISE] = 2022

elif (self.GetLong(Combo_2) == Combo_2_ch_21) :
              shd2[c4d.SLA_NOISE_NOISE] = 2023

elif (self.GetLong(Combo_2) == Combo_2_ch_22) :
              shd2[c4d.SLA_NOISE_NOISE] = 2024

elif (self.GetLong(Combo_2) == Combo_2_ch_23) :
              shd2[c4d.SLA_NOISE_NOISE] = 2025

elif (self.GetLong(Combo_2) == Combo_2_ch_24) :
              shd2[c4d.SLA_NOISE_NOISE] = 2026

elif (self.GetLong(Combo_1) == Combo_2_ch_25) :
              shd2[c4d.SLA_NOISE_NOISE] = 2027

elif (self.GetLong(Combo_2) == Combo_2_ch_26) :
              shd2[c4d.SLA_NOISE_NOISE] = 2028

elif (self.GetLong(Combo_2) == Combo_2_ch_27) :
              shd2[c4d.SLA_NOISE_NOISE] = 2029

elif (self.GetLong(Combo_2) == Combo_2_ch_28) :
              shd2[c4d.SLA_NOISE_NOISE] = 2030

elif (self.GetLong(Combo_2) == Combo_2_ch_29) :
              shd2[c4d.SLA_NOISE_NOISE] = 2031

elif (self.GetLong(Combo_2) == Combo_2_ch_30) :
              shd2[c4d.SLA_NOISE_NOISE] = 2032

elif (self.GetLong(Combo_2) == Combo_2_ch_31) :
              shd2[c4d.SLA_NOISE_NOISE] = 2033
      return True

h[c4d.SDSOBJECT_SUBRAY_CM] = self.GetReal(UI_HyperNURBS_Subdivisions)

s[c4d.PRIM_SPHERE_SUB] = self.GetReal(UI_Initial_Mesh_Subdivisions)
     
      s[c4d.PRIM_SPHERE_RAD] = self.GetReal(UI_Rock_SIZE)

d1[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = self.GetReal(UI_Displacement1_Height)
      d2[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = self.GetReal(UI_Displacement2_Height)
     
      shd1[c4d.SLA_NOISE_GLOBAL_SCALE] = self.GetReal(UI_Noise1_Size)
      shd1[c4d.SLA_NOISE_SEED] = self.GetReal(UI_Random_Seed1)
      shd2[c4d.SLA_NOISE_GLOBAL_SCALE] = self.GetReal(UI_Noise2_Size)
      shd2[c4d.SLA_NOISE_SEED] = self.GetReal(UI_Random_Seed2)

#fxWert_x = (self.GetReal(UI_Formula_x))
      #fxWert_y = (self.GetReal(UI_Formula_y))
      #fxWert_z = (self.GetReal(UI_Formula_z))

#f[c4d.FORMULAOBJECT_FX] = 'x*'fxWert_x
      #f[c4d.FORMULAOBJECT_FY] = 'y*'fxWert_x
      #f[c4d.FORMULAOBJECT_FZ] = 'z*'fxWert_x

return True

class ProceduralRockGenerator(c4d.plugins.CommandData) :

dialog = None

def Init(self, op) :
      return True

def Message(self, type, data) :
      return True

def Execute(self, doc) :
      if self.dialog is None:
          self.dialog = ProceduralRockGeneratorDialog()
      return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=400, defaulth=160)

if __name__ == '__main__':
  bmp = c4d.bitmaps.BaseBitmap()
  dir, file = os.path.split(__file__)
  fn = os.path.join(dir, "res", "Icon.tif")
  bmp.InitWith(fn)
  print "Procedural Rock Generator loaded."
  result = plugins.RegisterCommandPlugin(PLUGIN_ID, "ProceduralRockGenerator", 0, bmp, "ProceduralRockGenerator", ProceduralRockGenerator())

On 07/02/2013 at 13:13, xxxxxxxx wrote:

You need to use a getter to use the dialog's values.

Example:
Wrong

  
h[c4d.SDSOBJECT_SUBEDITOR_CM] = 2  

Correct

  
h[c4d.SDSOBJECT_SUBEDITOR_CM] = self.GetLong(UI_HyperNURBS_Subdivisions)  

-ScottA

On 07/02/2013 at 13:21, xxxxxxxx wrote:

Scott, I don't see what exactly is wrong with theese two examples. They have different intentions,

he even added a comment "Set Editor subdivision to 2".

16fingers, I currently don't have the time to look at your code in detail, but what I noticed
immediately, is that you don't use the NOISE_ constants but the integer IDs instead. There are
constants like NOISE_BOX_NOISE, see the c4d.utils.noise.C4DNoise class for a list of these.

You might also want to look at the c4d.utils.noise.C4DNoise.CreateMenuContainer() method.

On 07/02/2013 at 13:38, xxxxxxxx wrote:

The answer I posted is correct.
He's using hard coded values in the command() method where he should be using getters.

Don't make me take away your phone young man. 😂

-ScottA

On 07/02/2013 at 13:49, xxxxxxxx wrote:

> >> He's using hard coded values in the command() method where he should be using getters.

Yes, he does. But don't you think he is aware of this fact? He even added a comment that states
exactly what the line does.  It was probably not his intention to use the value from the UI.
~~

            h[c4d.SDSOBJECT_SUBEDITOR_CM] = 2 # Set Editor subdivision to 2

~~
~~
~~
I understand what you mean, but in my eyes, you've chosen the wrong line.

Uhh, I'm a dumbass. 😂 These comments are almost everywhere and he's using fixed values
everywhere. Sorry for complaining.

            s = c4d.BaseObject(c4d.Osphere) # Create new sphere
            s[c4d.PRIM_SPHERE_TYPE] = 2 # Set sphere type to Hexaeder
            s[c4d.PRIM_SPHERE_SUB] = 50 # Set sphere segments to 50
            s[c4d.PRIM_SPHERE_RAD] = 200 # Set sphere radius to 200
            s.SetName('Sphere')
            doc.InsertObject(s)

16fingers, as Scott said, you need to obtain the values from the dialog. You're assigning fixed
values to the sphere in this excerpt.

See the related GetReal(), GetLong(), GetBool(), etc. methods from the GeDialog class.

-Niklas

On 07/02/2013 at 14:17, xxxxxxxx wrote:

Lol,
You had me very worried there Nik.
You are pretty much always correct. And you had me questioning myself.

Put that phone down and focus darn it!...

-ScottA

On 08/02/2013 at 03:21, xxxxxxxx wrote:

Thank you guys for the tips.

I replaced the fixed values and i´m using the getters now.
The objects are created correctly and they also get the initial values but they still don´t change if i´m moving the sliders.

Do i need some kind of update code for aplying the slider values?

  
import os  
import sys  
import c4d  
from c4d import plugins, utils, gui,documents  
from c4d.modules import mograph  
  
PLUGIN_ID = 1029753  
  
global doc  
doc = c4d.documents.GetActiveDocument()  
  
  
# UI Daten  
  
UI_Initial_Mesh_Subdivisions = 10000  
UI_HyperNURBS_Subdivisions = 10001  
UI_Rock_SIZE = 10002  
UI_Displacement1_Height = 10003  
UI_Noise1_Type = 10004  
UI_Noise1_Size = 10005  
UI_Random_Seed1 = 10006  
UI_Formula_x = 10007  
UI_Formula_y = 10008  
UI_Formula_z = 10009  
UI_Displacement2_Height = 10010  
UI_Noise2_Type = 10011  
UI_Noise2_Size = 10012  
UI_Random_Seed2 = 10013  
UI_Generate_Mesh = 10014  
UI_Generate_Initial_Rock = 10015  
  
# Groups  
  
Group1 = 20001  
Group2 = 20002  
Group3 = 20003  
Group4 = 20004  
  
  
# Combo Box Daten  
  
Combo_1 = 20005  
Combo_1_ch_0 = 31000  
Combo_1_ch_1 = 31001  
Combo_1_ch_2 = 31002  
Combo_1_ch_3 = 31003  
Combo_1_ch_4 = 31004  
Combo_1_ch_5 = 31005  
Combo_1_ch_6 = 31006  
Combo_1_ch_7 = 31007  
Combo_1_ch_8 = 31008  
Combo_1_ch_9 = 31009  
Combo_1_ch_10 = 31010  
Combo_1_ch_11 = 31011  
Combo_1_ch_12 = 31012  
Combo_1_ch_13 = 31013  
Combo_1_ch_14 = 31014  
Combo_1_ch_15 = 31015  
Combo_1_ch_16 = 31016  
Combo_1_ch_17 = 31017  
Combo_1_ch_18 = 31018  
Combo_1_ch_19 = 31019  
Combo_1_ch_20 = 31020  
Combo_1_ch_21 = 31021  
Combo_1_ch_22 = 31022  
Combo_1_ch_23 = 31023  
Combo_1_ch_24 = 31024  
Combo_1_ch_25 = 31025  
Combo_1_ch_26 = 31026  
Combo_1_ch_27 = 31027  
Combo_1_ch_28 = 31028  
Combo_1_ch_29 = 31029  
Combo_1_ch_30 = 31030  
Combo_1_ch_31 = 31031  
  
Combo_2 = 20006  
Combo_2_ch_0 = 32000  
Combo_2_ch_1 = 32001  
Combo_2_ch_2 = 32002  
Combo_2_ch_3 = 32003  
Combo_2_ch_4 = 32004  
Combo_2_ch_5 = 32005  
Combo_2_ch_6 = 32006  
Combo_2_ch_7 = 32007  
Combo_2_ch_8 = 32008  
Combo_2_ch_9 = 32009  
Combo_2_ch_10 = 32010  
Combo_2_ch_11 = 32011  
Combo_2_ch_12 = 32012  
Combo_2_ch_13 = 32013  
Combo_2_ch_14 = 32014  
Combo_2_ch_15 = 32015  
Combo_2_ch_16 = 32016  
Combo_2_ch_17 = 32017  
Combo_2_ch_18 = 32018  
Combo_2_ch_19 = 32019  
Combo_2_ch_20 = 32020  
Combo_2_ch_21 = 32021  
Combo_2_ch_22 = 32022  
Combo_2_ch_23 = 32023  
Combo_2_ch_24 = 32024  
Combo_2_ch_25 = 32025  
Combo_2_ch_26 = 32026  
Combo_2_ch_27 = 32027  
Combo_2_ch_28 = 32028  
Combo_2_ch_29 = 32029  
Combo_2_ch_30 = 32030  
Combo_2_ch_31 = 32031  
  
  
#  
class ProceduralRockGeneratorDialog(c4d.gui.GeDialog) :  
  
  def CreateLayout(self) :  
      self.SetTitle("Procedural Rock Generator")  
  
      self.AddButton(UI_Generate_Initial_Rock, c4d.BFH_LEFT | c4d.BFV_TOP | c4d.BFH_SCALEFIT, 600, 15, "Generate Initial Rock")  
  
      #Group 1 with 2 columns "Resolution"  
      self.GroupBegin(Group1, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 2, 0, "Resolution")  
      self.GroupBorderSpace(5, 5, 5, 5)  
      self.GroupBorder(c4d.BORDER_GROUP_IN)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Initial Mesh Subdivisions:", 0)  
      self.AddEditSlider(UI_Initial_Mesh_Subdivisions, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Hyper Nurbs Subdisvisions:", 0)  
      self.AddEditSlider(UI_HyperNURBS_Subdivisions, c4d.BFH_SCALEFIT, 0, 0)  
      self.GroupEnd()  
  
      #Group 2 with 2 columns "Basic Rock Shape"  
      self.GroupBegin(Group2, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 2, 0, "Basic Rock Shape")  
      self.GroupBorderSpace(5, 5, 5, 5)  
      self.GroupBorder(c4d.BORDER_GROUP_IN)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Rock Size:", 0)  
      self.AddEditSlider(UI_Rock_SIZE, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Displacement Height:", 0)  
      self.AddEditSlider(UI_Displacement1_Height, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Type:", 0)  
      self.AddComboBox(Combo_1, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddChild(Combo_1 ,Combo_1_ch_0,'Box Noise')  
      self.AddChild(Combo_1,Combo_1_ch_1,'Blistered Turbulence')  
      self.AddChild(Combo_1,Combo_1_ch_2,'Buya')  
      self.AddChild(Combo_1,Combo_1_ch_3,'Cell Noise')  
      self.AddChild(Combo_1,Combo_1_ch_4,'Cranal')  
      self.AddChild(Combo_1,Combo_1_ch_5,'Dents')  
      self.AddChild(Combo_1,Combo_1_ch_6,'Displaced Turbulence')  
      self.AddChild(Combo_1,Combo_1_ch_7,'FBM')  
      self.AddChild(Combo_1,Combo_1_ch_8,'Hama')  
      self.AddChild(Combo_1,Combo_1_ch_9,'Luka')  
      self.AddChild(Combo_1,Combo_1_ch_10,'Mod Noise')  
      self.AddChild(Combo_1,Combo_1_ch_11,'Hama')  
      self.AddChild(Combo_1,Combo_1_ch_12,'Noise')  
      self.AddChild(Combo_1,Combo_1_ch_13,'Nutous')  
      self.AddChild(Combo_1,Combo_1_ch_14,'Ober')  
      self.AddChild(Combo_1,Combo_1_ch_15,'Pezo')  
      self.AddChild(Combo_1,Combo_1_ch_16,'Poxo')  
      self.AddChild(Combo_1,Combo_1_ch_17,'Sema')  
      self.AddChild(Combo_1,Combo_1_ch_18,'Stupl')  
      self.AddChild(Combo_1,Combo_1_ch_19,'Turbulence')  
      self.AddChild(Combo_1,Combo_1_ch_20,'VL Noise')  
      self.AddChild(Combo_1,Combo_1_ch_21,'Wavy Turbulence')  
      self.AddChild(Combo_1,Combo_1_ch_22,'Cell Voronoi')  
      self.AddChild(Combo_1,Combo_1_ch_23,'Displaced Voronoi')  
      self.AddChild(Combo_1,Combo_1_ch_24,'Sparse Convolution')  
      self.AddChild(Combo_1,Combo_1_ch_25,'Voronoi 1')  
      self.AddChild(Combo_1,Combo_1_ch_26,'Voronoi 2')  
      self.AddChild(Combo_1,Combo_1_ch_27,'Voronoi 3')  
      self.AddChild(Combo_1,Combo_1_ch_28,'Zada')  
      self.AddChild(Combo_1,Combo_1_ch_29,'Fire')  
      self.AddChild(Combo_1,Combo_1_ch_30,'Electric')  
      self.AddChild(Combo_1,Combo_1_ch_31,'Gaseous')  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Size:", 0)  
      self.AddEditSlider(UI_Noise1_Size, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Random Seed:", 0)  
      self.AddEditSlider(UI_Random_Seed1, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Scale X:", 0)  
      self.AddEditSlider(UI_Formula_x, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Scale Y:", 0)  
      self.AddEditSlider(UI_Formula_y, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Scale Z:", 0)  
      self.AddEditSlider(UI_Formula_z, c4d.BFH_SCALEFIT, 0, 0)  
      self.GroupEnd()  
  
      #Group 3 with 2 columns "Rock Details"  
      self.GroupBegin(Group3, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 2, 0, "Rock Details")  
      self.GroupBorderSpace(5, 5, 5, 5)  
      self.GroupBorder(c4d.BORDER_GROUP_IN)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Displacement Height:", 0)  
      self.AddEditSlider(UI_Displacement2_Height, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Type:", 0)  
      self.AddComboBox(Combo_2, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddChild(Combo_2,Combo_2_ch_0,'Box Noise')  
      self.AddChild(Combo_2,Combo_2_ch_1,'Blistered Turbulence')  
      self.AddChild(Combo_2,Combo_2_ch_2,'Buya')  
      self.AddChild(Combo_2,Combo_2_ch_3,'Cell Noise')  
      self.AddChild(Combo_2,Combo_2_ch_4,'Cranal')  
      self.AddChild(Combo_2,Combo_2_ch_5,'Dents')  
      self.AddChild(Combo_2,Combo_2_ch_6,'Displaced Turbulence')  
      self.AddChild(Combo_2,Combo_2_ch_7,'FBM')  
      self.AddChild(Combo_2,Combo_2_ch_8,'Hama')  
      self.AddChild(Combo_2,Combo_2_ch_9,'Luka')  
      self.AddChild(Combo_2,Combo_2_ch_10,'Mod Noise')  
      self.AddChild(Combo_2,Combo_2_ch_11,'Hama')  
      self.AddChild(Combo_2,Combo_2_ch_12,'Noise')  
      self.AddChild(Combo_2,Combo_2_ch_13,'Nutous')  
      self.AddChild(Combo_2,Combo_2_ch_14,'Ober')  
      self.AddChild(Combo_2,Combo_2_ch_15,'Pezo')  
      self.AddChild(Combo_2,Combo_2_ch_16,'Poxo')  
      self.AddChild(Combo_2,Combo_2_ch_17,'Sema')  
      self.AddChild(Combo_2,Combo_2_ch_18,'Stupl')  
      self.AddChild(Combo_2,Combo_2_ch_19,'Turbulence')  
      self.AddChild(Combo_2,Combo_2_ch_20,'VL Noise')  
      self.AddChild(Combo_2,Combo_2_ch_21,'Wavy Turbulence')  
      self.AddChild(Combo_2,Combo_2_ch_22,'Cell Voronoi')  
      self.AddChild(Combo_2,Combo_2_ch_23,'Displaced Voronoi')  
      self.AddChild(Combo_2,Combo_2_ch_24,'Sparse Convolution')  
      self.AddChild(Combo_2,Combo_2_ch_25,'Voronoi 1')  
      self.AddChild(Combo_2,Combo_2_ch_26,'Voronoi 2')  
      self.AddChild(Combo_2,Combo_2_ch_27,'Voronoi 3')  
      self.AddChild(Combo_2,Combo_2_ch_28,'Zada')  
      self.AddChild(Combo_2,Combo_2_ch_29,'Fire')  
      self.AddChild(Combo_2,Combo_2_ch_30,'Electric')  
      self.AddChild(Combo_2,Combo_2_ch_31,'Gaseous')  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Noise Size:", 0)  
      self.AddEditSlider(UI_Noise2_Size, c4d.BFH_SCALEFIT, 0, 0)  
      self.AddStaticText(0, c4d.BFH_LEFT, 0, 0, "Random Seed:", 0)  
      self.AddEditSlider(UI_Random_Seed2, c4d.BFH_SCALEFIT, 0, 0)  
      self.GroupEnd()  
  
      self.AddButton(UI_Generate_Mesh, c4d.BFH_LEFT | c4d.BFV_TOP | c4d.BFH_SCALEFIT, 600, 15, "Generate Rock Mesh")  
        
      return True  
  
  
  def InitValues(self) :  
      self.SetLong(UI_Initial_Mesh_Subdivisions, 50, min=0, max=400, step=True)  
      self.SetLong(UI_HyperNURBS_Subdivisions, 1, min=1, max=6, step=True)  
      self.SetLong(UI_Rock_SIZE, 195, min=1, max=1000, step=True)  
      self.SetReal(UI_Displacement1_Height, 227, min=0, max=500, step=1, format=c4d.FORMAT_REAL)  
      self.SetLong(Combo_1,Combo_1_ch_23)  
      self.SetLong(UI_Noise1_Size, 18, min=0, max=40, step=True)  
      self.SetLong(UI_Random_Seed1, 658, min=1, max=1000, step=True)  
      self.SetReal(UI_Formula_x, 1, min=1, max=5, step=0.1, format=c4d.FORMAT_REAL)  
      self.SetReal(UI_Formula_y, 1, min=1, max=5, step=0.1, format=c4d.FORMAT_REAL)  
      self.SetReal(UI_Formula_z, 1, min=1, max=5, step=0.1, format=c4d.FORMAT_REAL)  
      self.SetLong(UI_Displacement2_Height, 5, min=0, max=500, step=True)  
      self.SetLong(Combo_2,Combo_2_ch_9)  
      self.SetLong(UI_Noise2_Size, 2, min=0, max=40, step=True)  
      self.SetLong(UI_Random_Seed2, 660, min=1, max=1000, step=True)  
  
      return True  
  
  def Command(self,id,msg) :  
        
      if (id == UI_Generate_Initial_Rock) :  
          doc = c4d.documents.GetActiveDocument()  
  
          c4d.CallCommand(12202) # Set standart Camera in Editor Window  
          c4d.CallCommand(12091) # Set Gouraud-Shading in Editor Window  
          c4d.CallCommand(13620) # Set Editor Window to Single View  
  
          # Create the HyperNURBS  
          h = c4d.BaseObject(c4d.Osds) # Create new HyperNURBS  
          h[c4d.SDSOBJECT_SUBEDITOR_CM] = 2 # Set Editor subdivision to 2  
          h[c4d.SDSOBJECT_SUBRAY_CM] = self.GetLong(UI_HyperNURBS_Subdivisions) # Set Render subdivisions  
          h.SetName('Hypernurbs')  
          doc.InsertObject(h)  
          # Create the sphere  
          s = c4d.BaseObject(c4d.Osphere) # Create new sphere  
          s[c4d.PRIM_SPHERE_TYPE] = 2 # Set sphere type to Hexaeder  
          s[c4d.PRIM_SPHERE_SUB] = self.GetLong(UI_Initial_Mesh_Subdivisions) # Set sphere segments  
          s[c4d.PRIM_SPHERE_RAD] = self.GetLong(UI_Rock_SIZE) # Set sphere radius  
          s.SetName('Sphere')  
          doc.InsertObject(s)  
          # Create the Displacer deformer 1  
          c4d.CallCommand(1018685) # Create new displacer deformer  
          d1 = doc.SearchObject('Displacer')   
          d1[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = self.GetReal(UI_Displacement1_Height) # Set displacement height  
          d1[c4d.MGDISPLACER_DISPLACEMENTMODE]=0 # Set Displacementmode to Intensity  
          d1[c4d.MGDISPLACER_POLYNORMALMODE]=1 # Set Polynormalmode to Sphere  
          d1.SetName('Displacer1')  
  
          # Assingn the noise shadet to the displace deformer 1  
          mat1 = d1  
          shd1 = c4d.BaseList2D(c4d.Xnoise)  
          shd1[c4d.SLA_NOISE_SEED] = self.GetLong(UI_Random_Seed1)  
          shd1[c4d.SLA_NOISE_NOISE] = 2025  
          shd1[c4d.SLA_NOISE_OCTAVES] = 1  
          shd1[c4d.SLA_NOISE_GLOBAL_SCALE] = self.GetLong(UI_Noise1_Size)  
  
          mat1[c4d.ID_MG_SHADER_SHADER] = shd1  
          mat1.InsertShader(shd1)  
          mat1.Message(c4d.MSG_UPDATE)  
  
          # Create the Formula deformer  
          c4d.CallCommand(5146) # Create new Formula deformer  
          f = doc.SearchObject('Formel')  
          f[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]=1 # Set Formula deformer to invisible  
          f[c4d.FORMULAOBJECT_EFFECT]=0 # Set Effect to Manual  
          fxWert_x = 'x*' + str((self.GetReal(UI_Formula_x)))  
          fxWert_y = 'y*' + str((self.GetReal(UI_Formula_y)))  
          fxWert_z = 'z*' + str((self.GetReal(UI_Formula_z)))  
          f[c4d.FORMULAOBJECT_FX]=fxWert_x  
          f[c4d.FORMULAOBJECT_FY]=fxWert_y  
          f[c4d.FORMULAOBJECT_FZ]=fxWert_z  
          f.SetName('Formula')  
  
          # Create the Displacer deformer 2  
          c4d.CallCommand(1018685) # Create new displacer deformer  
          d2 = doc.SearchObject('Displacer')   
          d2[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = self.GetLong(UI_Displacement2_Height) # Set displacement height  
          d2.SetName('Displacer2')  
  
          # Assingn the noise shader to the displace deformer 2  
          mat2 = d2  
          shd2 = c4d.BaseList2D(c4d.Xnoise)  
          shd2[c4d.SLA_NOISE_SEED] = self.GetLong(UI_Random_Seed2)  
          shd2[c4d.SLA_NOISE_NOISE] = 2010  
          shd2[c4d.SLA_NOISE_OCTAVES] = 20  
          shd2[c4d.SLA_NOISE_GLOBAL_SCALE] = self.GetLong(UI_Noise2_Size)  
  
          mat2[c4d.ID_MG_SHADER_SHADER] = shd2  
          mat2.InsertShader(shd2)  
          mat2.Message(c4d.MSG_UPDATE)  
  
          # Insertions  
          s.InsertUnder(h)  
          d2.InsertUnder(s)  
          f.InsertUnder(s)  
          d1.InsertUnder(s)  
  
          # Layer  
          c4d.CallCommand(100004738) # Create a new layer  
          c4d.CallCommand(100004748) # Alles aufklappen in der Objektliste  
          c4d.CallCommand(100004766) # Select all Objects  
          c4d.CallCommand(100004736) # Assign all Objects to the layer  
          c4d.CallCommand(12148) # Zoom on Geometry in Editor Window  
          c4d.CallCommand(100004767) # Deselect all  
  
          ######################### Hide the layer in menu ##########################  
  
          #doc = c4d.documents.GetActiveDocument()  
          #root = doc.GetLayerObjectRoot()#Gets the layer manager  
          #LayersList = root.GetChildren()  
          #toggled = 0  
          #for layers in LayersList:  
  
          #    if layers.GetBit(c4d.BIT_ACTIVE) :# if the layer is selected  
          #        layer_data = layers.GetLayerData(doc)  
          #        layer_data['manager'] = not layer_data['manager']  
          #        layers.SetLayerData(doc,layer_data)  
          #        toggled=1  
          #    c4d.EventAdd()  
  
          ##########################################################################  
      return True  
  
  
      if id == UI_Generate_Mesh:  
          doc = c4d.documents.GetActiveDocument()  
          rock = doc.SearchObject('Hypernurbs')  
          rock.SetName('Rock')  
          c4d.CallCommand(12236) # Grundobjekt kovertieren  
          c4d.CallCommand(100004739) # Delete all Layers  
          c4d.EventAdd()  
      return True  
  
  
      if id == Combo_1:  
          if (self.GetLong(Combo_1) == Combo_1_ch_0) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2001  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_1) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2002  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_2) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2003  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_3) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2004  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_4) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2005  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_5) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2006  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_6) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2007  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_7) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2008  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_8) :  
              shd[c4d.SLA_NOISE_NOISE] = 2009  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_9) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2010  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_10) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2011  
            
          elif (self.GetLong(Combo_1) == Combo_1_ch_11) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2012  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_12) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2013  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_13) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2014  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_14) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2015  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_15) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2016  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_16) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2017  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_17) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2019  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_18) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2020  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_19) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2021  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_20) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2022  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_21) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2023  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_22) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2024  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_23) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2025  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_24) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2026  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_25) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2027  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_26) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2028  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_27) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2029  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_28) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2030  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_29) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2031  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_30) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2032  
  
          elif (self.GetLong(Combo_1) == Combo_1_ch_31) :  
              shd1[c4d.SLA_NOISE_NOISE] = 2033  
      return True  
  
      if id == Combo_2:  
          if (self.GetLong(Combo_2) == Combo_2_ch_0) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2001  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_1) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2002  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_2) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2003  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_3) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2004  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_4) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2005  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_5) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2006  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_6) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2007  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_7) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2008  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_8) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2009  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_9) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2010  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_10) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2011  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_11) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2012  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_12) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2013  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_13) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2014  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_14) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2015  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_15) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2016  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_16) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2017  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_17) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2019  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_18) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2020  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_19) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2021  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_20) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2022  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_21) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2023  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_22) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2024  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_23) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2025  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_24) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2026  
  
          elif (self.GetLong(Combo_1) == Combo_2_ch_25) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2027  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_26) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2028  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_27) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2029  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_28) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2030  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_29) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2031  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_30) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2032  
  
          elif (self.GetLong(Combo_2) == Combo_2_ch_31) :  
              shd2[c4d.SLA_NOISE_NOISE] = 2033  
      return True  
  
      #h[c4d.SDSOBJECT_SUBRAY_CM] = self.GetReal(UI_HyperNURBS_Subdivisions)  
  
      #s[c4d.PRIM_SPHERE_SUB] = self.GetReal(UI_Initial_Mesh_Subdivisions)  
        
      #s[c4d.PRIM_SPHERE_RAD] = self.GetReal(UI_Rock_SIZE)  
  
      #d1[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = self.GetReal(UI_Displacement1_Height)  
      #d2[c4d.MGDISPLACER_DISPLACEMENT_HEIGHT] = self.GetReal(UI_Displacement2_Height)  
        
      #shd1[c4d.SLA_NOISE_GLOBAL_SCALE] = self.GetReal(UI_Noise1_Size)  
      #shd1[c4d.SLA_NOISE_SEED] = self.GetReal(UI_Random_Seed1)  
      #shd2[c4d.SLA_NOISE_GLOBAL_SCALE] = self.GetReal(UI_Noise2_Size)  
      #shd2[c4d.SLA_NOISE_SEED] = self.GetReal(UI_Random_Seed2)  
  
      #fxWert_x = (self.GetReal(UI_Formula_x))  
      #fxWert_y = (self.GetReal(UI_Formula_y))  
      #fxWert_z = (self.GetReal(UI_Formula_z))  
  
      #f[c4d.FORMULAOBJECT_FX] = 'x*'fxWert_x  
      #f[c4d.FORMULAOBJECT_FY] = 'y*'fxWert_x  
      #f[c4d.FORMULAOBJECT_FZ] = 'z*'fxWert_x  
  
      return True  
  
class ProceduralRockGenerator(c4d.plugins.CommandData) :  
  
  dialog = None  
  
  def Init(self, op) :  
      return True  
  
  def Message(self, type, data) :  
      return True  
  
  def Execute(self, doc) :  
      if self.dialog is None:  
          self.dialog = ProceduralRockGeneratorDialog()  
      return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaultw=400, defaulth=160)  
  
if __name__ == '__main__':  
  bmp = c4d.bitmaps.BaseBitmap()  
  dir, file = os.path.split(__file__)  
  fn = os.path.join(dir, "res", "Icon.tif")  
  bmp.InitWith(fn)  
  print "Procedural Rock Generator loaded."  
  result = plugins.RegisterCommandPlugin(PLUGIN_ID, "ProceduralRockGenerator", 0, bmp, "ProceduralRockGenerator", ProceduralRockGenerator())  

On 08/02/2013 at 03:29, xxxxxxxx wrote:

Hi 16fingers,

think about it twice. When you want the objects to change when a slider has been modified, this
needs to be reflected in your code. It does not magically happen, you have to develop it, write code
so that it does what you want.

You're probably better off writing an ObjectData plugin when you want the changes to be reflected
while dragging (which is implicit since you will automatically generate new objects whenever a
property changes in the AM).

-Niklas

On 08/02/2013 at 08:50, xxxxxxxx wrote:

The code in your command() method is being used to grab the slider values and use them to create your object. Not to change it after it's been created.

Think of it like a duck laying an egg.Smile

-ScottA