You can edit ../Plugins/SketchyPhysics3/ClassExtensions.rb with a plain-text editor [Notepad[++].exe or similar]... around line #59
- Code: Select all
class Sketchup::Group
def definition # make it so you can use group.definition
return(entities[0].parent)
end
end
change it to read
- Code: Select all
class Sketchup::Group
if not Sketchup::Group.method_defined?(:definition)
def definition() # make it so you can use group.definition
return(self.entities.parent)
end
end#if
end
This code is used to set the
group.definition method not available directly in the API...
In its current form it is looking for a parent of the first entity [0] in the group's entities - if there is no first [0] entity in the entities it fails because 'nil' has no parent.
The suggested change explicitly refers to the group's entities AND even if the entities is empty it returns the parent and thereby the definition...
NOTE: an even safer 'method' is this
- Code: Select all
class Sketchup::Group
# Some times the 'group.entities.parent' refer to the wrong definition.
# This method checks for this error and locates the correct parent definition.
if not Sketchup::Group.method_defined?(:definition)
def definition()
if self.entities.parent.instances.include?(self)
return self.entities.parent
else
Sketchup.active_model.definitions.each { |definition|
next if not definition.group?
return definition if definition.instances.include?(self)
}
end
return nil # Should never happen.
end
end#if
end
Note how the suggested code changes test to see if the
group.definition method is already set [by another tool or perhaps even SketchUp in a yet to come API upgrade] and it doesn't change it if it is...
IF you have other scripts that are also defining
group.definition [do a 'grep' search through Plugins for "
class Sketchup::Group"] it might also be best for you to substitute the same class/method definition and tests for all of them
