Skip to content

Instantly share code, notes, and snippets.

View jimfoltz's full-sized avatar

Jim Foltz jimfoltz

View GitHub Profile
@jimfoltz
jimfoltz / 3ds2obj.rb
Created October 17, 2013 08:23
Command line quickie to convert binary .3ds files and output ascii .obj file. Materials are ignored.
v_tot = 1
vqty = 0
file = ARGV.shift
f = File.new(file, "rb")
while ! f.eof?
cid = f.read(2).unpack('s')[0]
len = f.read(4).unpack('i')[0]
@jimfoltz
jimfoltz / extract_png.rb
Created November 8, 2013 23:14
Ruby snippet to extract the thumbnail .png enbeded in a .skp (SketchUp) file.
# with a lot of help from Adam on comp.lang.ruby
def extract_chunk(input, output)
lenword = input.read(4)
length = lenword.unpack('N')[0]
type = input.read(4)
data = length>0 ? input.read(length) : ""
crc = input.read(4)
return nil if length<0 || !(('A'..'z')===type[0,1])
#return nil if validate_crc(type+data, crc)
@jimfoltz
jimfoltz / cannon.rb
Last active August 29, 2015 13:57
Projectile Motion Animation SketchUp
class Cannon
def initialize(bearing, elev, velocity)
@item = Sketchup.active_model.entities[0]
@t = 0
@v = velocity.to_f
@angle = elev.to_f
@bearing = bearing.to_f
@vy = @v * Math::cos(@angle.degrees)
@vz = @v * Math::sin(@angle.degrees)
# jf_attach_camera_to_sun.rb (C) jim.foltz@gmail.com
#
# Name: Sun Tool
#
module JF
module AttachCameraToSun
VERSION = '1.0.0'.freeze
require 'socket'
require 'nokogiri'
require 'nori'
require 'pp'
SETTINGS = "C:/ProgramData/SketchUp/RubyDebugger.settings"
def main
@parser = Nori.new
if not defined?(JF::ZoomCrosshairs)
UI.menu("Camera").add_item("Zoom Crosshairs") {
Sketchup.active_model.select_tool(JF::ZoomCrosshairs.new)
}
end
module JF
class ZoomCrosshairs
=begin
This is how you to delete a Layer prior to SketchUp 2015.
SketchUp >= 2015 has a Layer.delete method.
(c) TIG 2009
layer-delete.rb adds a new Method the Sketchup's Layer Class-
"layer.delete()" - it deletes that layer from the model and
entities that used it get the default layer instead...
@jimfoltz
jimfoltz / att_reporter.rb
Last active August 29, 2015 14:10
Overview Attching DC Attributes to Component in SketchUp
# http://sketchucation.com/forums/viewtopic.php?p=124392#p124392
#----------------------------------------------------------------------------#
## Copyright 2005-2008, Google, Inc.
# This software is provided as an example of using the Ruby interface
# to SketchUp.
# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted, provided that the above
@jimfoltz
jimfoltz / amf-ex.rb
Last active November 15, 2015 10:58
amf-ex.rb
#UI.menu.add_item("Export AMF") {
#JF::AMF.export
#}
require 'rexml/document'
module JF
module AMF
module Exporter
# http://stackoverflow.com/a/17982272/816093
module TransformationHelper
def flipped_x?
dot_x, dot_y, dot_z = axes_dot_products()
dot_x < 0 && flipped?(dot_x, dot_y, dot_z)
end
def flipped_y?