# Scripting Errors?

I'm trying to make a Perforce Addon, I saw a few people asking for it. It will be free to the public of course. I am having issues figuring python out. I have spent about two days researching and looking for different methods. From what I can tell I am doing it all the recommended way. Can someone look at my code and tell me where I messed up?

I was going to just expose it here but it looks funny so I am making a pastebin.

Perforce Plugin Code

# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

bl_info = {
"name": "Perforce Tools",
"author": "PlacidStorm",
"version": (1, 0, 0),
"blender": (2, 7, 8),
"location": "View3D > Tools > Perforce Tools",
"description": "Adds some tools for improve the Blender to Perforce workflow",
"warning": "",
"wiki_url": "",
"category": "Perforce Tools"}

#Import Information.
import bpy
import os

class PerforceServerProperties(bpy.types.PropertyGroup):
Server_IP = bpy.props.StringProperty(
name="Server_IP",
description="Server IP",
default='192.168.0.1')
Server_Port = bpy.props.StringProperty(
name="Server_Port",
description="Server Port",
default='1666')
default='')
Server_Pass = bpy.props.StringProperty(
default='')

# Class for the Tool Panel.
class PerforceToolPanel(bpy.types.Panel):
bl_label = "Perforce Tools"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = 'Perforce Tools'

def draw(self, context):
layout = self.layout

filename = bpy.path.basename(bpy.context.blend_data.filepath)

layout.label(text="Perforce Server Info", icon='WORLD_DATA')
layout.label(text="File Info", icon='FILE_BLEND')
layout.label(text="Current File: " + filename)

# Class Registration
classes = [
PerforceServerProperties,
PerforceToolPanel

]

def register():
for c in classes:
bpy.utils.register_class(c)

def unregister():
for c in classes:
bpy.utils.unregister_class(c)

bpy.types.Scene.serv_prop_grp = bpy.props.PointerProperty(type=PerforceServerProperties)
# Needed to run script in text editor
if __name__ == "__main__":
register()

• Add 4 spaces to the start of each line and paste to get a code block. Most source code editors will add the spaces if you select the text and press tab. – sambler Nov 23 '17 at 1:42

To add a custom property to the scene, you need to place the property creation line inside the register() function, and then delete it in unregister()

def register():
for c in classes:
bpy.utils.register_class(c)
bpy.types.Scene.serv_prop_grp = bpy.props.PointerProperty(type=PerforceServerProperties)

def unregister():
for c in classes:
bpy.utils.unregister_class(c)
del bpy.types.Scene.serv_prop_grp


Other than variable declarations, without any functions used to initialize them, you can't have any code outside of function or class definitions in a blender addon.

• Thanks, I was so close to figuring this out. I am not use to using Python. I usually use C#. I did a edit and other than the unregister part. All I was missing was the tab/4space assigning the serv_prop_grp. – Austin Cain Nov 27 '17 at 15:33