Trouble using the existing offset method from offset.rb


#1

Hi, I downloaded the offset.rb from Author:: Rick Wilson /Organization:: Smustard/ Name:: offset.rb/Version:: 2.201
SU Version:: 4.0/ Date:: 2010-10-15.

I required the offset.rb in my ruby console in sketchup.
But when I call the method offset. It always shows up Error: #<NoMethodError: undefined method `offset’ for nil:NilClass>

Here is a sample of what is in the offset.rb
class Sketchup::Curve
def offset(dist)
return nil if self.count_edges<2…

Is there something wrong with the way I require it?

Thank you!


#2

This script modifies SketchUp API classes and should NOT be used, until Rick fixes it so it does not do this.

We cannot tell what the error text is because the forum is swallowing the message.

Please wrap error text in

```text

and

lines.


----------


Please wrap Ruby code in:

```text
```ruby

and

lines.

#3

Thank you for your reply!

The error message is undefined method `offset’ for nil.

Thank you!


#4

You will have to supply more code, so we can understand why this is happening.

The message indicates that the receiver object you are calling the offset method upon, is pointing at nil.


#5

Thank you for your reply!

ruby lines from offset.rb :

class Sketchup::Curve
def offset(dist)
return nil if self.count_edges<2
pi=Math::PI
if (not ((dist.class==Fixnum || dist.class==Float || dist.class==Length) && dist!=0))
return nil
end
verts=self.vertices
pts=[]
0.upto(verts.length-1) do |a|
if a==0 #special case for start vertex
model=self.model
model.start_operation "offset"
gp=model.active_entities.add_group
gpents=gp.entities
face=gpents.add_face(verts[0].position,verts[1].position,verts[2].position)
zaxis=face.normal
v=self.edges[0].line[1]
f=dist/dist.abs
t=Geom::Transformation.rotation(verts[0].position,zaxis,(pi/2)*f)
vec3=v.transform(t)
vec3.length=dist.abs
pts.push(verts[0].position.transform(vec3))
gp.erase!
model.commit_operation
elsif a==(verts.length-1) #special case for end vertex
model=self.model
model.start_operation "offset"
gp=model.active_entities.add_group
gpents=gp.entities
face=gpents.add_face(verts[a].position,verts[a-1].position,verts[a-2].position)
zaxis=face.normal
v=self.edges[a-1].line[1]
f=dist/dist.abs
t=Geom::Transformation.rotation(verts[a].position,zaxis,(pi/2)*f)
vec3=v.transform(t)
vec3.length=dist.abs
pts.push(verts[a].position.transform(vec3))
gp.erase!
model.commit_operation
else
vec1=(verts[a].position-verts[a-(verts.length-1)].position).normalize
vec2=(verts[a].position-verts[a-1].position).normalize
vec3=(vec1+vec2).normalize
if vec3.valid?
ang=vec1.angle_between(vec2)/2
ang=pi/2 if vec1.parallel?(vec2)
vec3.length=dist/Math::sin(ang)
t=Geom::Transformation.new(vec3)
if pts.length > 0
if not (vec2.parallel?(pts.last.vector_to(verts[a].position.transform(t))))
t=Geom::Transformation.new(vec3.reverse)
end
end
pts.push(verts[a].position.transform(t))
end
end
end
#Sketchup.active_model.active_entities.add_curve(pts)
c=parent.entities.add_curve(pts)
c.first.curve
end
end


lines


#6

Please re-read: http://forums.sketchup.com/t/trouble-using-the-existing-offset-method-from-offset-rb/16566/2

… and if that code is copyrighted, please remove it.